Skip to content

Commit

Permalink
Merge pull request #30 from kkdai/support_bot_mentions
Browse files Browse the repository at this point in the history
chore: update go version to 1.23 and line-bot-sdk-go to v8.10.0; enha…
  • Loading branch information
kkdai authored Oct 31, 2024
2 parents c582448 + 1f94b6b commit 704d992
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kkdai/LineBotTemplate

// +heroku goVersion go1.21
go 1.21
go 1.23

require github.com/line/line-bot-sdk-go/v8 v8.2.0
require github.com/line/line-bot-sdk-go/v8 v8.10.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/line/line-bot-sdk-go/v8 v8.2.0 h1:IFqwd3pKbA+o3pwV3nzamtWHt7n+ijSH3t/D8Q/vVQ0=
github.com/line/line-bot-sdk-go/v8 v8.2.0/go.mod h1:n9Ly8OHM6xCeQktLzRpQHe/yBda95kFgmQUefUQeFCs=
github.com/line/line-bot-sdk-go/v8 v8.10.0 h1:rdlb+Qp2UGPgAnt0CWTHfPDxmTtQ0taGuiPsqj6LCfU=
github.com/line/line-bot-sdk-go/v8 v8.10.0/go.mod h1:9U4mY4kLAFSCSwPl1YxtqmG0Db19DnclpuYS5VOkOZY=
26 changes: 26 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ func callbackHandler(w http.ResponseWriter, r *http.Request) {
switch message := e.Message.(type) {
// Handle only on text message
case webhook.TextMessageContent:
// If it is in group message, check if mention me.
switch e.Source.(type) {
case webhook.GroupSource:
case webhook.RoomSource:
for _, mention := range message.Mention.Mentionees {
botID := ""
botResponse, err := bot.GetBotInfo().Do()
if err != nil {
botID = botResponse.BasicID
fmt.Println("Bot ID=", botID)
}
switch mention.GetType() {
case "user":
botMention := mention.(*webhook.UserMentionee)
fmt.Println("Mentioned user ID=", botMention.UserId, " isSelf=", botMention.IsSelf)

if botMention.IsSelf {
if _, err = bot.ReplyMessage(e.ReplyToken, linebot.NewTextMessage("你找我嗎?")).Do(); err != nil {
log.Print(err)
}
return
}
}
}
}

// GetMessageQuota: Get how many remain free tier push message quota you still have this month. (maximum 500)
quota, err := bot.GetMessageQuota().Do()
if err != nil {
Expand Down

0 comments on commit 704d992

Please sign in to comment.