talent/api_line.go

52 lines
856 B
Go
Raw Normal View History

2021-12-30 09:16:20 +00:00
package main
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/line/line-bot-sdk-go/v7/linebot"
"github.com/rs/zerolog/log"
)
func webhook(c *gin.Context) {
events, err := bot.ParseRequest(c.Request)
if err != nil {
panic(err)
}
if flagDev {
data, _ := json.MarshalIndent(events, "", " ")
fmt.Println(string(data))
}
for _, event := range events {
if event.Type == linebot.EventTypeFollow {
Follow(event)
}
2022-01-02 16:47:25 +00:00
if event.Type == linebot.EventTypeMessage {
controller(event)
}
2021-12-30 09:16:20 +00:00
}
OK(c, "ok")
}
2022-01-02 16:47:25 +00:00
func controller(event *linebot.Event) {
2022-01-03 05:06:26 +00:00
msg, ok := event.Message.(*linebot.TextMessage)
if !ok {
log.Error().Msg("controller not impemented")
return
}
Hit(msg.Text, event.Source.UserID)
switch msg.Text {
2022-01-02 16:47:25 +00:00
case "":
2021-12-30 13:39:00 +00:00
2022-01-02 16:47:25 +00:00
default:
// route to watson
log.Error().Caller().Msg("NOT IMPLEMENTED")
2021-12-30 09:16:20 +00:00
}
}