51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package bot
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"git/ecom/jira-bot/pkg/bot/middlewares"
|
||
"git/ecom/jira-bot/pkg/bot/scenes"
|
||
"git/ecom/jira-bot/pkg/config"
|
||
"git/ecom/jira-bot/pkg/templates"
|
||
"git/ecom/jira-bot/pkg/utils"
|
||
|
||
"log"
|
||
|
||
telegram "gopkg.in/tucnak/telebot.v2"
|
||
)
|
||
|
||
// Чатбот
|
||
func JiraBot() {
|
||
|
||
cfg, _ := config.GetConfig()
|
||
redis := utils.Redis(cfg.Redis)
|
||
ctx := context.Background()
|
||
jiraClient, _ := utils.GetClient(&cfg.Jira)
|
||
b, err := telegram.NewBot(telegram.Settings{
|
||
URL: cfg.Telegram.Url,
|
||
Token: cfg.Telegram.Token,
|
||
Poller: middlewares.RedisSession(redis, ctx),
|
||
})
|
||
|
||
if err != nil {
|
||
log.Fatal(err)
|
||
return
|
||
}
|
||
|
||
b.Handle(telegram.OnText, func(m *telegram.Message) {
|
||
// spew.Dump(m)
|
||
b.Send(m.Sender, m.Text)
|
||
})
|
||
|
||
// Cтартовая сцена
|
||
b.Handle("/start", scenes.Start(b, cfg))
|
||
|
||
b.Handle("/exit", scenes.Exit(b, redis, ctx))
|
||
b.Handle("/hello", func(m *telegram.Message) {
|
||
b.Send(m.Sender, "Hello World!")
|
||
})
|
||
|
||
fmt.Println(templates.Title(b.Me, cfg.BotVersion,jiraClient.GetBaseURL().Host))
|
||
b.Start()
|
||
}
|