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"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
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) {
|
|
|
|
switch event.Source.Ty {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|