Merged two bots into one
This commit is contained in:
parent
68f1750beb
commit
480503d770
7 changed files with 177 additions and 181 deletions
33
internal/telegram/handler.go
Normal file
33
internal/telegram/handler.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"gitlab.com/flygrounder/go-mtg-vk/internal/scenario"
|
||||
)
|
||||
|
||||
const welcomeMessage = "Здравствуйте, вас приветствует бот для поиска цен на карты MTG, введите название карты, которая вас интересует."
|
||||
|
||||
type Handler struct {
|
||||
Scenario *scenario.Scenario
|
||||
}
|
||||
|
||||
func (h *Handler) HandleMessage(c *gin.Context) {
|
||||
var upd tgbotapi.Update
|
||||
err := c.Bind(&upd)
|
||||
if err != nil || upd.Message == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if upd.Message.Text == "/start" {
|
||||
h.Scenario.Sender.Send(upd.Message.Chat.ID, welcomeMessage)
|
||||
return
|
||||
}
|
||||
|
||||
h.Scenario.HandleSearch(context.Background(), &scenario.UserMessage{
|
||||
Body: upd.Message.Text,
|
||||
UserId: upd.Message.Chat.ID,
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue