talent/api_line.go

52 lines
856 B
Go

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)
}
if event.Type == linebot.EventTypeMessage {
controller(event)
}
}
OK(c, "ok")
}
func controller(event *linebot.Event) {
msg, ok := event.Message.(*linebot.TextMessage)
if !ok {
log.Error().Msg("controller not impemented")
return
}
Hit(msg.Text, event.Source.UserID)
switch msg.Text {
case "":
default:
// route to watson
log.Error().Caller().Msg("NOT IMPLEMENTED")
}
}