talent/setup_line.go

54 lines
851 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"
)
var bot *linebot.Client
func setupLine() {
var err error
bot, err = linebot.New(LINE_SECRET, LINE_TOKEN)
if err != nil {
panic(err)
}
}
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) {
switch event.Source.Ty {
case "":
default:
// route to watson
log.Error().Caller().Msg("NOT IMPLEMENTED")
}
}