Skip to content

Instantly share code, notes, and snippets.

@buildingwatsize
Last active July 20, 2020 09:18
Show Gist options
  • Save buildingwatsize/85f63f5e9d9f8c45ae00320cefaa2bac to your computer and use it in GitHub Desktop.
Save buildingwatsize/85f63f5e9d9f8c45ae00320cefaa2bac to your computer and use it in GitHub Desktop.
service.go - Goldnoti [Phase 2]
// HandleLINEEventMessage : Handle LINE Event Message for LINE Bot Client
func HandleLINEEventMessage(event *linebot.Event) {
switch message := event.Message.(type) {
case *linebot.TextMessage:
textIncoming := message.Text
log.Println("[INFO]: Text Incoming |", textIncoming)
uid := event.Source.UserID
log.Println("[INFO]: User ID |", uid)
profile := repository.Bot.GetProfile(uid)
log.Println("[INFO]: User Profile |", profile)
todayPrice, err := repository.Harvester()
if err != nil {
log.Println("[ERROR]: Get Today Price Error |", err)
return
}
colorCode := "#666666"
if todayPrice.StatusChange == "ทองขึ้น" {
colorCode = "#64a338"
} else if todayPrice.StatusChange == "ทองลง" {
colorCode = " #e03b24"
}
flexContainer, err := linebot.UnmarshalFlexMessageJSON([]byte(fmt.Sprintf(`
...
{FLEX_MESSAGE_JSON}
...
`,
humanize.FormatFloat("", todayPrice.BarBuy),
humanize.FormatFloat("", todayPrice.BarSell),
humanize.FormatFloat("", todayPrice.OrnamentBuy),
humanize.FormatFloat("", todayPrice.OrnamentSell),
humanize.FormatFloat("", todayPrice.TodayChange),
todayPrice.StatusChange,
colorCode,
todayPrice.UpdatedDate,
todayPrice.UpdatedTime,
)))
if err != nil {
log.Println("[ERROR]: Flex Message Builder |", err)
return
}
flexMessage := linebot.NewFlexMessage("ราคาทองคำวันนี้", flexContainer)
replyToken := event.ReplyToken
if _, err := repository.Bot.ReplyMessage(replyToken, flexMessage).Do(); err != nil {
log.Println("[ERROR]: Reply Message |", err)
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment