Skip to content

Commit 363b44e

Browse files
authored
Add v2 example - bot mention, text v2 emoji (line#561)
related to line#533
1 parent 4fa714d commit 363b44e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

examples/v2/kitchensink/app.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,55 @@ def handle_message_event(event)
260260
)
261261
client.reply_message(reply_message_request: request)
262262

263+
when 'emoji v2'
264+
request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
265+
reply_token: event.reply_token,
266+
messages: [
267+
Line::Bot::V2::MessagingApi::TextMessageV2.new(
268+
text: "Look at this: {sample} It's a LINE emoji! (v2)",
269+
substitution: {
270+
"sample" => Line::Bot::V2::MessagingApi::EmojiSubstitutionObject.new(
271+
product_id: '5ac1bfd5040ab15980c9b435',
272+
emoji_id: '002'
273+
)
274+
}
275+
)
276+
]
277+
)
278+
client.reply_message(reply_message_request: request)
279+
280+
when 'mention me'
281+
if event.source.type == 'group' || event.source.type == 'room'
282+
request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
283+
reply_token: event.reply_token,
284+
messages: [
285+
Line::Bot::V2::MessagingApi::TextMessageV2.new(
286+
text: "Hi {yourName}! cc: {all}\n How are you?",
287+
substitution: {
288+
"yourName" => Line::Bot::V2::MessagingApi::MentionSubstitutionObject.new(
289+
mentionee: Line::Bot::V2::MessagingApi::UserMentionTarget.new(
290+
user_id: event.source.user_id
291+
)
292+
),
293+
"all" => Line::Bot::V2::MessagingApi::MentionSubstitutionObject.new(
294+
mentionee: Line::Bot::V2::MessagingApi::AllMentionTarget.new()
295+
)
296+
}
297+
)
298+
]
299+
)
300+
response, _,_ = client.reply_message_with_http_info(reply_message_request: request)
301+
if response.is_a?(Line::Bot::V2::MessagingApi::ErrorResponse)
302+
logger.error "[ERROR MENTION]\n" \
303+
"Message: #{response.message}\n" \
304+
"Details: #{response.details.inspect}"
305+
else
306+
logger.info "[MENTION]\n #{response}"
307+
end
308+
else
309+
reply_text(event, "Bot can't use mention API without group ID")
310+
end
311+
263312
when 'buttons'
264313
request = Line::Bot::V2::MessagingApi::ReplyMessageRequest.new(
265314
reply_token: event.reply_token,

0 commit comments

Comments
 (0)