Early telegram integrations

This commit is contained in:
2022-09-14 22:54:51 +08:00
parent 534bc70f0f
commit 9b48f2ee50
8 changed files with 65 additions and 29 deletions

35
main.go
View File

@@ -2,11 +2,38 @@ package main
import (
"log"
"net/http"
"github.com/tgckpg/golifehk/handlers"
"os"
mtrbus "github.com/tgckpg/golifehk/datasources/mtr/bus"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
func main() {
http.HandleFunc( "/", handlers.Index )
log.Fatal(http.ListenAndServe(":8000", nil))
bot, err := tgbotapi.NewBotAPI( os.Getenv( "TELEGRAM_API_TOKEN" ) )
if err != nil {
log.Panic( err )
}
bot.Debug = true
log.Printf("Authorized on account %s", bot.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates := bot.GetUpdatesChan(u)
for update := range updates {
if update.Message == nil {
continue
}
log.Printf( "[%s] %s", update.Message.From.UserName, update.Message.Text )
result := mtrbus.Query( "zh", update.Message.Text )
msg := tgbotapi.NewMessage( update.Message.Chat.ID, result.Message() )
msg.ReplyToMessageID = update.Message.MessageID
bot.Send( msg )
}
}