hdkv
/
i2_bot
Archived
1
Fork 0

Moving from long polling to webhook-based updates

master
Vladimir Hodakov 2018-01-31 00:10:10 +04:00
parent 5b13b6479a
commit 88e640d322
4 changed files with 16 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import (
"git.wtfteam.pro/fat0troll/i2_bot/lib/users" "git.wtfteam.pro/fat0troll/i2_bot/lib/users"
"git.wtfteam.pro/fat0troll/i2_bot/lib/welcomer" "git.wtfteam.pro/fat0troll/i2_bot/lib/welcomer"
"github.com/go-telegram-bot-api/telegram-bot-api" "github.com/go-telegram-bot-api/telegram-bot-api"
"net/http"
"time" "time"
) )
@ -56,10 +57,16 @@ func main() {
c.Cron.Start() c.Cron.Start()
c.Log.Info("> Cron started.") c.Log.Info("> Cron started.")
u := tgbotapi.NewUpdate(0) _, err := c.Bot.SetWebhook(tgbotapi.NewWebhook(c.Cfg.Telegram.WebHookDomain))
u.Timeout = 60 if err != nil {
c.Log.Fatal(err.Error())
}
updates, _ := c.Bot.GetUpdatesChan(u) updates := c.Bot.ListenForWebhook("/" + c.Bot.Token)
go http.ListenAndServe(c.Cfg.Telegram.ListenAddress, nil)
c.Log.Info("Listening on " + c.Cfg.Telegram.ListenAddress)
c.Log.Info("Webhook URL: " + c.Cfg.Telegram.WebHookDomain)
for update := range updates { for update := range updates {
if update.Message != nil { if update.Message != nil {

View File

@ -1,5 +1,7 @@
telegram_connection: telegram_connection:
api_token: "your-awesome-token" api_token: "your-awesome-token"
webhook_domain: "https://i2bot.wtfteam.pro"
listen_address: "0.0.0.0:5000"
database_connection: database_connection:
host: "localhost" host: "localhost"
port: "3306" port: "3306"

View File

@ -32,7 +32,7 @@ func (b *Broadcaster) AdminBroadcastMessageSend(update *tgbotapi.Update, playerR
return "fail" return "fail"
} }
prettyName := profileRaw.Nickname + "(@" + profileRaw.TelegramNickname + ")" prettyName := profileRaw.Nickname + " (@" + profileRaw.TelegramNickname + ")"
privateChats := []dbmapping.Chat{} privateChats := []dbmapping.Chat{}
switch messageRaw.BroadcastType { switch messageRaw.BroadcastType {

View File

@ -24,7 +24,9 @@ type DatabaseConnection struct {
// TelegramConnection handles settings for Telegram connection in config.yaml // TelegramConnection handles settings for Telegram connection in config.yaml
type TelegramConnection struct { type TelegramConnection struct {
APIToken string `yaml:"api_token"` APIToken string `yaml:"api_token"`
WebHookDomain string `yaml:"webhook_domain"`
ListenAddress string `yaml:"listen_address"`
} }
// SpecialChats handles settings for special chats // SpecialChats handles settings for special chats