update
parent
5ca8f38e40
commit
2f35f8c4b0
6
api.go
6
api.go
|
@ -29,7 +29,11 @@ func ApiUpdateEmail(c *gin.Context) {
|
|||
OK(c, "ok")
|
||||
msg := linebot.NewTextMessage("更新成功!")
|
||||
sticker := linebot.NewStickerMessage("1070", "17840")
|
||||
SendMessage("", data.ID, msg, sticker, DefaultMsg())
|
||||
SendMessage("", data.ID, msg, sticker)
|
||||
go func() {
|
||||
time.Sleep(time.Second * 2)
|
||||
SendMessage("", data.ID, DefaultMsg())
|
||||
}()
|
||||
}
|
||||
|
||||
func ApiPostReceipt(c *gin.Context) {
|
||||
|
|
|
@ -52,6 +52,8 @@ func postback(event *linebot.Event) {
|
|||
ApiListProductOfCat(event)
|
||||
case strings.HasPrefix(data, "purchase="):
|
||||
ApiPurchase(event)
|
||||
case strings.HasPrefix(data, "sales="):
|
||||
ApiSelectSales(event)
|
||||
case data == "list-tags":
|
||||
ApiListCategories(event)
|
||||
}
|
||||
|
@ -87,6 +89,7 @@ func controller(event *linebot.Event) {
|
|||
case msg.Text == "我要理賠":
|
||||
case msg.Text == "修改完成":
|
||||
case msg.Text == "我要投保":
|
||||
case msg.Text == "讓我幫你":
|
||||
|
||||
default:
|
||||
// route to watson
|
||||
|
|
|
@ -61,7 +61,7 @@ func ApiPurchase(event *linebot.Event) {
|
|||
data := event.Postback.Data
|
||||
data = strings.TrimPrefix(data, "purchase=")
|
||||
prod := &Product{}
|
||||
if err := DB.Preload("Categories").First(prod, "name = ?", data); err != nil {
|
||||
if err := DB.Preload("Categories").First(prod, "name = ?", data).Error; err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
@ -69,8 +69,21 @@ func ApiPurchase(event *linebot.Event) {
|
|||
msg := linebot.NewTextMessage(`好的,
|
||||
保費試算為: XXX元
|
||||
|
||||
稍後將由專人為您服務。`)
|
||||
SendMessage(event.ReplyToken, event.Source.UserID, msg)
|
||||
請選擇您附近的專業業務員。`)
|
||||
|
||||
var salses []Sales
|
||||
DB.Find(&salses)
|
||||
columns := make([]*linebot.CarouselColumn, len(salses))
|
||||
for i, salse := range salses {
|
||||
columns[i] = linebot.NewCarouselColumn(
|
||||
salse.Img, salse.Name, salse.Brief,
|
||||
linebot.NewPostbackAction("讓我幫你", "sales="+salse.Name, "讓我幫你", ""),
|
||||
)
|
||||
}
|
||||
template := linebot.NewCarouselTemplate(columns...)
|
||||
|
||||
selectSales := linebot.NewTemplateMessage("選擇專業業務員", template)
|
||||
SendMessage(event.ReplyToken, event.Source.UserID, msg, selectSales)
|
||||
}
|
||||
|
||||
func ApiListRecommanded(event *linebot.Event) {
|
||||
|
@ -81,12 +94,16 @@ func ApiListRecommanded(event *linebot.Event) {
|
|||
|
||||
// send slide
|
||||
|
||||
text := "您的推薦"
|
||||
leftBtn := linebot.NewMessageAction("修改資料", "修改資料")
|
||||
rightBtn := linebot.NewMessageAction("我的保單", "我的保單")
|
||||
template := linebot.NewConfirmTemplate(text, leftBtn, rightBtn)
|
||||
msg := linebot.NewTemplateMessage(text, template)
|
||||
if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg); err != nil {
|
||||
panic(err)
|
||||
columns := make([]*linebot.CarouselColumn, len(prods))
|
||||
for i, prod := range prods {
|
||||
columns[i] = linebot.NewCarouselColumn(
|
||||
prod.Img, prod.Name, prod.Brief,
|
||||
linebot.NewURIAction("保單詳細", flagBase+"/product/"+strconv.Itoa(int(prod.ID))),
|
||||
linebot.NewPostbackAction("我要投保", "purchase="+prod.Name, "我要投保", ""),
|
||||
)
|
||||
}
|
||||
template := linebot.NewCarouselTemplate(columns...)
|
||||
|
||||
msg := linebot.NewTemplateMessage("我要投保", template)
|
||||
SendMessage(event.ReplyToken, event.Source.UserID, msg)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/line/line-bot-sdk-go/v7/linebot"
|
||||
)
|
||||
|
||||
func ApiSelectSales(event *linebot.Event) {
|
||||
data := event.Postback.Data
|
||||
data = strings.TrimPrefix(data, "sales=")
|
||||
|
||||
sales := &Sales{}
|
||||
DB.First(sales, "name = ?", data)
|
||||
|
||||
tmp, _ := linebot.UnmarshalFlexMessageJSON([]byte(
|
||||
fmt.Sprintf(greet, sales.Img, sales.Name, "很高興為您服務!"),
|
||||
))
|
||||
msg := linebot.NewFlexMessage("很高興為您服務!", tmp)
|
||||
sticker := linebot.NewStickerMessage("1070", "17852")
|
||||
SendMessage(event.ReplyToken, event.Source.UserID, msg, sticker)
|
||||
}
|
||||
|
||||
var greet string = `
|
||||
{
|
||||
"type": "bubble",
|
||||
"hero": {
|
||||
"type": "image",
|
||||
"url": "%v",
|
||||
"size": "full"
|
||||
},
|
||||
"body": {
|
||||
"type": "box",
|
||||
"layout": "vertical",
|
||||
"contents": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "你好! 我是%v",
|
||||
"weight": "bold",
|
||||
"size": "xl"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"text": "%v"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`
|
2
db.go
2
db.go
|
@ -44,7 +44,7 @@ func migrateDB() {
|
|||
if err := DB.SetupJoinTable(&User{}, "Products", &Order{}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := DB.AutoMigrate(&Node{}, &User{}, &Profile{}, &Product{}, &Order{}, &Price{}); err != nil {
|
||||
if err := DB.AutoMigrate(&Node{}, &User{}, &Profile{}, &Product{}, &Order{}, &Price{}, &Sales{}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue