Early telegram integrations
This commit is contained in:
35
main.go
35
main.go
@@ -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 )
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user