2021-06-03 01:59:32 +03:00
|
|
|
|
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"
|
|
|
|
|
)
|
|
|
|
|
|
2021-06-03 09:30:25 +03:00
|
|
|
|
|
|
|
|
|
|
2021-06-03 01:59:32 +03:00
|
|
|
|
// Чатбот
|
|
|
|
|
func JiraBot() {
|
|
|
|
|
|
2021-06-03 09:30:25 +03:00
|
|
|
|
|
2021-06-03 01:59:32 +03:00
|
|
|
|
cfg, _ := config.GetConfig()
|
|
|
|
|
redis := utils.Redis(cfg.Redis)
|
|
|
|
|
ctx := context.Background()
|
2021-06-03 09:30:25 +03:00
|
|
|
|
pnsq := utils.GetProducer()
|
2021-06-03 01:59:32 +03:00
|
|
|
|
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))
|
2021-06-03 09:30:25 +03:00
|
|
|
|
|
2021-06-03 01:59:32 +03:00
|
|
|
|
b.Handle("/hello", func(m *telegram.Message) {
|
|
|
|
|
b.Send(m.Sender, "Hello World!")
|
2021-06-03 09:30:25 +03:00
|
|
|
|
messageBody := []byte("hello")
|
|
|
|
|
topicName := "error"
|
|
|
|
|
|
|
|
|
|
// Synchronously publish a single message to the specified topic.
|
|
|
|
|
// Messages can also be sent asynchronously and/or in batches.
|
|
|
|
|
err = pnsq.Publish(topicName, messageBody)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
2021-06-03 01:59:32 +03:00
|
|
|
|
})
|
|
|
|
|
|
2021-06-03 09:30:25 +03:00
|
|
|
|
fmt.Println(templates.Title(b.Me, cfg.BotVersion, jiraClient.GetBaseURL().Host))
|
2021-06-03 01:59:32 +03:00
|
|
|
|
b.Start()
|
|
|
|
|
}
|