Browse Source

Add telegram send

main
parent
commit
ef219a94bb
  1. 1
      go.mod
  2. 2
      go.sum
  3. 23
      main.go

1
go.mod

@ -4,6 +4,7 @@ go 1.17 @@ -4,6 +4,7 @@ go 1.17
require (
github.com/boltdb/bolt v1.3.1 // indirect
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 // indirect
github.com/jessevdk/go-flags v1.5.0 // indirect
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect

2
go.sum

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc=

23
main.go

@ -3,11 +3,13 @@ package main @@ -3,11 +3,13 @@ package main
import (
"encoding/json"
"encoding/xml"
"html"
"html/template"
"log"
"os"
"github.com/boltdb/bolt"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/jessevdk/go-flags"
"gopkg.in/yaml.v2"
)
@ -15,8 +17,10 @@ import ( @@ -15,8 +17,10 @@ import (
type Config struct {
Dbpath string `yaml:"dbpath"`
Telegram struct {
Send bool `yaml:"send"`
Token string `yaml:"token"`
Send bool `yaml:"send"`
SendDebug bool `yaml:"senddebug"`
ChatId int64 `yaml:"chatid"`
Token string `yaml:"token"`
} `yaml:"telegram"`
VK struct {
Send bool `yaml:"send"`
@ -164,6 +168,21 @@ func InitDb(rss Rss2, dbpath string) { @@ -164,6 +168,21 @@ func InitDb(rss Rss2, dbpath string) {
func (config Config) RunSend() {
if config.Telegram.Send {
log.Println("Send to telegram")
bot, err := tgbotapi.NewBotAPI(config.Telegram.Token)
if err != nil {
log.Panic(err)
}
bot.Debug = config.Telegram.SendDebug
for _, v := range senditems.ItemList {
s := "<b>" + string(v.Title) + "</b>\n" + html.UnescapeString(string(v.Description)) +
"\n" + v.Link
msg := tgbotapi.NewMessage(config.Telegram.ChatId, s)
msg.ParseMode = "Html"
_, err := bot.Send(msg)
if err != nil {
log.Panic(err)
}
}
}
if config.VK.Send {
log.Println("Send to VK")

Loading…
Cancel
Save