Quantcast
Channel: Blog E
Viewing all articles
Browse latest Browse all 541

[TIL][Golang][Line Bot] 關於 Line Bot API 發送歡迎訊息 (Implement Line Bot welcome message when add to friend)

$
0
0

前提

這是我上週所開發的流浪動物領養聊天機器人得到大家的一些建議.

裡面有個建議是希望能夠新增好友的時候能夠增加”歡迎訊息”. 於是開始實作.

相關問題與解決方式

如何在新增朋友的時候發送預設簡訊

目標:

想要再新增你的機器人的時候,能夠發送一些簡單的介紹.

遇到困難:

其實根據 Line API Spec (Receive Operations)應該要能直接收到透過 content.From來查詢誰發的好友需求才是.

不過不清楚的官方文件是這樣說沒錯啦,實際上去跑的時候.

  • content沒資料 (ID, From, To)
  • OpContent (透過 ontent.OperationContent()拿的)一樣都沒資料 (ID, From, To)

在不斷地來來回回,總算找到可能是放在 result.RawContent.令人驚訝的是竟然是放在 result.RawContent.Param[0]

以下是全部相關程式碼

程式碼:

funccallbackHandler(whttp.ResponseWriter,r*http.Request){received,err:=bot.ParseRequest(r)iferr!=nil{iferr==linebot.ErrInvalidSignature{w.WriteHeader(400)}else{w.WriteHeader(500)}return}for_,result:=rangereceived.Results{content:=result.Content()//Add with new friend.ifcontent!=nil&&content.IsOperation&&content.OpType==OpTypeAddedAsFriend{out:=fmt.Sprintf("(Welcom MSG)歡迎訊息..")//result.RawContent.Params[0] is who send your bot friend added operation, otherwise you cannot get in content or operation content._,err=bot.SendText([]string{result.RawContent.Params[0]},out)iferr!=nil{log.Println(err)}log.Println("New friend add event.")}}}

相關資料


Viewing all articles
Browse latest Browse all 541

Trending Articles


Girasoles para colorear


mayabang Quotes, Torpe Quotes, tanga Quotes


Tagalog Quotes About Crush – Tagalog Love Quotes


OFW quotes : Pinoy Tagalog Quotes


Long Distance Relationship Tagalog Love Quotes


Tagalog Quotes To Move on and More Love Love Love Quotes


5 Tagalog Relationship Rules


Best Crush Tagalog Quotes And Sayings 2017


Re:Mutton Pies (lleechef)


FORECLOSURE OF REAL ESTATE MORTGAGE


Sapos para colorear


tagalog love Quotes – Tiwala Quotes


Break up Quotes Tagalog Love Quote – Broken Hearted Quotes Tagalog


Patama Quotes : Tagalog Inspirational Quotes


Pamatay na Banat and Mga Patama Love Quotes


Tagalog Long Distance Relationship Love Quotes


BARKADA TAGALOG QUOTES


“BAHAY KUBO HUGOT”


Vimeo 10.7.0 by Vimeo.com, Inc.


Vimeo 10.7.1 by Vimeo.com, Inc.