talent/api_line_products.go

65 lines
1.9 KiB
Go
Raw Normal View History

2022-01-03 14:50:49 +00:00
package main
2022-01-04 07:09:46 +00:00
import (
"strings"
2022-01-03 14:50:49 +00:00
2022-01-04 07:09:46 +00:00
"github.com/line/line-bot-sdk-go/v7/linebot"
)
func ApiPreparePurchase(event *linebot.Event) {
text := "沒問題!您知道想投保甚麼險種嗎?我們很樂意為您介紹"
template := linebot.NewConfirmTemplate(text,
linebot.NewPostbackAction("我知道", "list-tags", "我知道", ""),
linebot.NewMessageAction("為我推薦", "為我推薦"))
msg := linebot.NewTemplateMessage(text, template)
if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg); err != nil {
panic(err)
}
}
func ApiListCategories(event *linebot.Event) {
var cats []Category
DB.Find(&cats)
buttons := make([]*linebot.QuickReplyButton, len(cats))
for i, cat := range cats {
buttons[i] = linebot.NewQuickReplyButton("",
linebot.NewPostbackAction(cat.Name, "cat="+cat.Name, "", "險種: "+cat.Name))
}
msg := linebot.NewTextMessage("請選擇險種。").WithQuickReplies(
linebot.NewQuickReplyItems(buttons...),
)
if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg); err != nil {
panic(err)
}
}
func ApiListProductOfCat(event *linebot.Event) {
data := event.Postback.Data
data = strings.TrimPrefix(data, "cat=")
msg := linebot.NewTextMessage(data + ":")
if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg); err != nil {
panic(err)
}
}
func ApiGetProduct(event *linebot.Event) {}
func ApiListRecommanded(event *linebot.Event) {
var prods []Product
DB.Limit(10).Find(&prods, "id not in (select product_id from orders where user_id = ?)", event.Source.UserID)
// sort for target user
// send slide
text := "您的推薦"
2022-01-03 14:50:49 +00:00
leftBtn := linebot.NewMessageAction("修改資料", "修改資料")
rightBtn := linebot.NewMessageAction("我的保單", "我的保單")
2022-01-04 07:09:46 +00:00
template := linebot.NewConfirmTemplate(text, leftBtn, rightBtn)
msg := linebot.NewTemplateMessage(text, template)
2022-01-03 14:50:49 +00:00
if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg); err != nil {
panic(err)
}
}