2 changed files with 48 additions and 52 deletions
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
package send |
||||
|
||||
import ( |
||||
"log" |
||||
"ssender/internal/models" |
||||
|
||||
"github.com/SevereCloud/vksdk/v2/api" |
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" |
||||
) |
||||
|
||||
func RunSend(senditems *models.SendItems, config models.Config) error { |
||||
for _, v := range senditems.ItemList { |
||||
if config.Telegram.Send { |
||||
log.Println("Send to telegram") |
||||
bot, err := tgbotapi.NewBotAPI(config.Telegram.Token) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
bot.Debug = config.Telegram.SendDebug |
||||
|
||||
// s := "<b>" + string(v.Title) + "</b>\n" + html.UnescapeString(string(v.Description)) +
|
||||
// "\nhttps://t.me/iv?url=" + v.Link + "&rhash=da76512d0ff2a2" +
|
||||
// "\n\nСсылка на пост: " + v.Link
|
||||
msg := tgbotapi.NewMessage(config.Telegram.ChatId, v.Link) |
||||
msg.ParseMode = "Html" |
||||
_, err = bot.Send(msg) |
||||
if err != nil { |
||||
return err |
||||
|
||||
} |
||||
log.Println("Sended to telegram") |
||||
} |
||||
if config.VK.Send { |
||||
log.Println("Send to VK") |
||||
vk := api.NewVK(config.VK.Token) |
||||
_, err := vk.WallPost(api.Params{ |
||||
"owner_id": config.VK.OwnerId, |
||||
"attachments": v.Link, |
||||
}) |
||||
if err != nil { |
||||
return err |
||||
} |
||||
log.Println("Sended to VK") |
||||
} |
||||
|
||||
} |
||||
return nil |
||||
} |
||||
Loading…
Reference in new issue