package main import ( "fmt" "strings" "github.com/line/line-bot-sdk-go/v7/linebot" ) func ApiPrepareClaim(event *linebot.Event) { data := event.Postback.Data data = strings.TrimPrefix(data, "claim=") prod := &Product{} if err := DB.First(prod, "name = ?", data).Error; err != nil { panic(err) } order := &Order{} if err := DB.First(order, "product_id = ? and user_id = ?", prod.ID, event.Source.UserID); err != nil { panic(err) } DB.Model(order).Update("status", OrderClaiming) for _, cat := range prod.Categories { if cat.Name == "旅平" { url := flagBase + "/claim" button := linebot.NewButtonsTemplate("", "", "請上傳收據", linebot.NewURIAction("開啟上傳頁面", url)) msg := linebot.NewTemplateMessage(fmt.Sprintf("請前往 %v 上傳收據", url), button) if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg); err != nil { panic(err) } return } } msg := linebot.NewTextMessage("我們收到您的申請囉! 稍後將由專人致電為您服務!") sticker := linebot.NewStickerMessage("6632", "11825397") if _, err := SendMessage(event.ReplyToken, event.Source.UserID, msg, sticker); err != nil { panic(err) } }