2022-01-03 05:06:26 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/line/line-bot-sdk-go/v7/linebot"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
2022-01-03 14:50:49 +00:00
|
|
|
const NO_COMPAT = "電腦版不支援此訊息, 請至手機上讀取"
|
|
|
|
|
2022-01-03 05:06:26 +00:00
|
|
|
func Mkdir(args ...interface{}) error {
|
|
|
|
var path string
|
|
|
|
var mode os.FileMode
|
|
|
|
mode = 0755
|
|
|
|
for _, arg := range args {
|
|
|
|
switch arg := arg.(type) {
|
|
|
|
case string:
|
|
|
|
path = filepath.Join(path, arg)
|
|
|
|
case os.FileMode:
|
|
|
|
mode = arg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return os.MkdirAll(path, mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Hit(name, uid string) {
|
|
|
|
n := &Node{
|
|
|
|
Name: name,
|
|
|
|
UserID: uid,
|
|
|
|
}
|
|
|
|
go DB.Create(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SendMessage(replyToken string, to string, messages ...linebot.SendingMessage) (*linebot.BasicResponse, error) {
|
|
|
|
if replyToken != "" {
|
|
|
|
res, err := bot.ReplyMessage(replyToken, messages...).Do()
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Caller().Interface("response", res).Msg("reply error")
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
} else {
|
|
|
|
res, err := bot.PushMessage(to, messages...).Do()
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Err(err).Caller().Interface("response", res).Msg("push error")
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
}
|
2022-01-03 10:28:00 +00:00
|
|
|
|
2022-01-03 14:50:49 +00:00
|
|
|
func DefaultMsg() *linebot.TemplateMessage {
|
|
|
|
msg := linebot.NewButtonsTemplate(
|
|
|
|
"https://www.taishinlife.com.tw/event/LuckyForNew/assets/img/banner-1.jpg",
|
|
|
|
"有甚麼我能為你服務的嗎?", "您可以試著選擇:",
|
|
|
|
linebot.NewMessageAction("我想投保", "我想投保"),
|
|
|
|
linebot.NewMessageAction("我的資料", "我的資料"),
|
|
|
|
linebot.NewMessageAction("辦理理賠", "辦理理賠"),
|
|
|
|
)
|
2022-01-04 05:01:42 +00:00
|
|
|
return linebot.NewTemplateMessage("有甚麼我能為你服務的嗎?", msg)
|
2022-01-03 10:28:00 +00:00
|
|
|
}
|