Skip to content

Instantly share code, notes, and snippets.

@kkdai
Last active December 30, 2022 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkdai/f67d3ece464876bfb4c5fcf09a1ad1ca to your computer and use it in GitHub Desktop.
Save kkdai/f67d3ece464876bfb4c5fcf09a1ad1ca to your computer and use it in GitHub Desktop.
...
case *linebot.TextMessage:
// 預設訊息
reply := "msg ID:" + message.ID + ":" + "Get:" + message.Text + " , \n OK!"
// 如果聊天機器人在群組中,開始儲存訊息。
if event.Source.GroupID != "" {
// 先取得使用者 Display Name (也就是顯示的名稱)
userName := event.Source.UserID
userProfile, err := bot.GetProfile(event.Source.UserID).Do()
if err == nil {
userName = userProfile.DisplayName
}
// event.Source.GroupID 就是聊天群組的 ID,並且透過聊天群組的 ID 來放入 Map 之中。
q := summaryQueue[event.Source.GroupID]
m := MsgDetail{
MsgText: message.Text,
UserName: userName,
Time: time.Now(),
}
log.Println("Save msg:", m)
summaryQueue[event.Source.GroupID] = append(q, m)
log.Println("All msg:", q)
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment