Social sender
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

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
}