talent/util.go

62 lines
1.5 KiB
Go

package main
import (
"os"
"path/filepath"
"github.com/line/line-bot-sdk-go/v7/linebot"
"github.com/rs/zerolog/log"
)
const NO_COMPAT = "電腦版不支援此訊息, 請至手機上讀取"
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
}
}
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("辦理理賠", "辦理理賠"),
)
return linebot.NewTemplateMessage("有甚麼我能為你服務的嗎?", msg)
}