Class: Line::Bot::Client
- Inherits:
-
Object
- Object
- Line::Bot::Client
- Defined in:
- lib/line/bot/client.rb
Overview
API Client of LINE Bot SDK Ruby
@client ||= Line::Bot::Client.new do |config|
config.channel_id = ENV["LINE_CHANNEL_ID"]
config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
end
Instance Attribute Summary collapse
-
#blob_endpoint ⇒ Object
@return [String].
-
#channel_id ⇒ Object
@return [String].
-
#channel_secret ⇒ Object
@return [String].
-
#channel_token ⇒ Object
@return [String].
-
#endpoint ⇒ Object
@return [String].
- #http_options ⇒ Hash
- #httpclient ⇒ Object
Instance Method Summary collapse
-
#broadcast(messages, headers: {}) ⇒ Net::HTTPResponse
Send messages to all friends.
-
#bulk_link_rich_menus(user_ids, rich_menu_id) ⇒ Net::HTTPResponse
To link a rich menu to multiple users at a time.
-
#bulk_unlink_rich_menus(user_ids) ⇒ Net::HTTPResponse
To unlink a rich menu from multiple users at a time.
-
#create_link_token(user_id) ⇒ Net::HTTPResponse
Issue a link token to a user.
-
#create_rich_menu(rich_menu) ⇒ Net::HTTPResponse
Create a rich menu.
-
#create_rich_menu_image(rich_menu_id, file) ⇒ Net::HTTPResponse
Upload and attaches an image to a rich menu.
- #credentials ⇒ Hash
-
#delete(endpoint_base, endpoint_path, headers = {}) ⇒ Net::HTTPResponse
Delete content of specified URL.
-
#delete_rich_menu(rich_menu_id) ⇒ Net::HTTPResponse
Delete a rich menu.
-
#get(endpoint_base, endpoint_path, headers = {}) ⇒ Net::HTTPResponse
Fetch data, get content of specified URL.
-
#get_default_rich_menu ⇒ Net::HTTPResponse
Get default rich menu.
-
#get_friend_demographics ⇒ Net::HTTPResponse
Get the demographic attributes for a bot’s friends.
-
#get_group_member_ids(group_id, continuation_token = nil) ⇒ Net::HTTPResponse
Get user IDs of a group.
-
#get_group_member_profile(group_id, user_id) ⇒ Net::HTTPResponse
Get an user’s profile of a group.
-
#get_group_members_count(group_id) ⇒ Net::HTTPResponse
Gets the user IDs of the members of a group that the bot is in.
-
#get_group_summary(group_id) ⇒ Net::HTTPResponse
Gets the group ID, group name, and group icon URL of a group where the LINE Official Account is a member.
-
#get_message_content(identifier) ⇒ Net::HTTPResponse
Get message content.
-
#get_message_delivery_broadcast(date) ⇒ Net::HTTPResponse
Gets the number of messages sent with the /bot/message/multicast endpoint.
-
#get_message_delivery_multicast(date) ⇒ Net::HTTPResponse
Gets the number of messages sent with the /bot/message/multicast endpoint.
-
#get_message_delivery_push(date) ⇒ Net::HTTPResponse
Gets the number of messages sent with the /bot/message/push endpoint.
-
#get_message_delivery_reply(date) ⇒ Net::HTTPResponse
Gets the number of messages sent with the /bot/message/reply endpoint.
-
#get_number_of_followers(date) ⇒ Net::HTTPResponse
Returns the number of followers.
-
#get_number_of_message_deliveries(date) ⇒ Net::HTTPResponse
Returns the number of messages sent on a specified day.
-
#get_profile(user_id) ⇒ Net::HTTPResponse
Get an user’s profile.
-
#get_quota ⇒ Net::HTTPResponse
Get the target limit for additional messages.
-
#get_quota_consumption ⇒ Net::HTTPResponse
Get number of messages sent this month.
-
#get_rich_menu(rich_menu_id) ⇒ Net::HTTPResponse
Get a rich menu via a rich menu ID.
-
#get_rich_menu_image(rich_menu_id) ⇒ Net::HTTPResponse
Download an image associated with a rich menu.
-
#get_rich_menus ⇒ Net::HTTPResponse
Get a list of all uploaded rich menus.
-
#get_room_member_ids(room_id, continuation_token = nil) ⇒ Net::HTTPResponse
Get user IDs of a room.
-
#get_room_member_profile(room_id, user_id) ⇒ Net::HTTPResponse
Get an user’s profile of a room.
-
#get_room_members_count(room_id) ⇒ Net::HTTPResponse
Gets the count of members in a room.
-
#get_user_interaction_statistics(request_id) ⇒ Net::HTTPResponse
Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account.
-
#get_user_rich_menu(user_id) ⇒ Net::HTTPResponse
Get the ID of the rich menu linked to a user.
-
#initialize(options = {}) {|_self| ... } ⇒ Line::Bot::Client
constructor
Initialize a new client.
-
#issue_channel_token(grant_type = 'client_credentials') ⇒ Net::HTTPResponse
Issue channel access token.
- #leave_group(group_id) ⇒ Object
- #leave_room(room_id) ⇒ Object
-
#link_user_rich_menu(user_id, rich_menu_id) ⇒ Net::HTTPResponse
Link a rich menu to a user.
-
#multicast(to, messages, headers: {}) ⇒ Net::HTTPResponse
Send messages to multiple users using userIds.
-
#narrowcast(messages, recipient: nil, filter: nil, limit: nil, headers: {}) ⇒ Net::HTTPResponse
Narrowcast messages to users.
-
#parse_events_from(request_body) ⇒ Array<Line::Bot::Event::Class>
Parse events from request.body.
-
#post(endpoint_base, endpoint_path, payload = nil, headers = {}) ⇒ Net::HTTPResponse
Post data, get content of specified URL.
-
#push_message(user_id, messages, headers: {}) ⇒ Net::HTTPResponse
Push messages to a user using user_id.
-
#reply_message(token, messages) ⇒ Net::HTTPResponse
Reply messages to a user using replyToken.
-
#revoke_channel_token(access_token) ⇒ Net::HTTPResponse
Revoke channel access token.
-
#set_default_rich_menu(rich_menu_id) ⇒ Net::HTTPResponse
Set default rich menu (Link a rich menu to all user).
-
#unlink_user_rich_menu(user_id) ⇒ Net::HTTPResponse
Unlink a rich menu from a user.
-
#unset_default_rich_menu ⇒ Net::HTTPResponse
Unset default rich menu (Unlink a rich menu from all user).
-
#validate_signature(content, channel_signature) ⇒ Boolean
Validate signature of a webhook event.
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Line::Bot::Client
Initialize a new client.
43 44 45 46 47 48 |
# File 'lib/line/bot/client.rb', line 43 def initialize( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end |
Instance Attribute Details
#blob_endpoint ⇒ Object
@return [String]
31 32 33 |
# File 'lib/line/bot/client.rb', line 31 def blob_endpoint @blob_endpoint end |
#channel_id ⇒ Object
@return [String]
31 32 33 |
# File 'lib/line/bot/client.rb', line 31 def channel_id @channel_id end |
#channel_secret ⇒ Object
@return [String]
31 32 33 |
# File 'lib/line/bot/client.rb', line 31 def channel_secret @channel_secret end |
#channel_token ⇒ Object
@return [String]
31 32 33 |
# File 'lib/line/bot/client.rb', line 31 def channel_token @channel_token end |
#endpoint ⇒ Object
@return [String]
31 32 33 |
# File 'lib/line/bot/client.rb', line 31 def endpoint @endpoint end |
#http_options ⇒ Hash
37 38 39 |
# File 'lib/line/bot/client.rb', line 37 def end |
#httpclient ⇒ Object
34 35 36 |
# File 'lib/line/bot/client.rb', line 34 def httpclient @httpclient end |
Instance Method Details
#broadcast(messages, headers: {}) ⇒ Net::HTTPResponse
Send messages to all friends.
174 175 176 177 178 179 180 181 182 |
# File 'lib/line/bot/client.rb', line 174 def broadcast(, headers: {}) channel_token_required = [] if .is_a?(Hash) endpoint_path = '/bot/message/broadcast' payload = { messages: }.to_json post(endpoint, endpoint_path, payload, credentials.merge(headers)) end |
#bulk_link_rich_menus(user_ids, rich_menu_id) ⇒ Net::HTTPResponse
To link a rich menu to multiple users at a time
511 512 513 514 515 516 |
# File 'lib/line/bot/client.rb', line 511 def (user_ids, ) channel_token_required endpoint_path = "/bot/richmenu/bulk/link" post(endpoint, endpoint_path, { richMenuId: , userIds: user_ids }.to_json, credentials) end |
#bulk_unlink_rich_menus(user_ids) ⇒ Net::HTTPResponse
To unlink a rich menu from multiple users at a time
523 524 525 526 527 528 |
# File 'lib/line/bot/client.rb', line 523 def (user_ids) channel_token_required endpoint_path = "/bot/richmenu/bulk/unlink" post(endpoint, endpoint_path, { userIds: user_ids }.to_json, credentials) end |
#create_link_token(user_id) ⇒ Net::HTTPResponse
Issue a link token to a user
561 562 563 564 565 566 |
# File 'lib/line/bot/client.rb', line 561 def create_link_token(user_id) channel_token_required endpoint_path = "/bot/user/#{user_id}/linkToken" post(endpoint, endpoint_path, nil, credentials) end |
#create_rich_menu(rich_menu) ⇒ Net::HTTPResponse
Create a rich menu
414 415 416 417 418 419 |
# File 'lib/line/bot/client.rb', line 414 def () channel_token_required endpoint_path = '/bot/richmenu' post(endpoint, endpoint_path, .to_json, credentials) end |
#create_rich_menu_image(rich_menu_id, file) ⇒ Net::HTTPResponse
Upload and attaches an image to a rich menu
548 549 550 551 552 553 554 |
# File 'lib/line/bot/client.rb', line 548 def (, file) channel_token_required endpoint_path = "/bot/richmenu/#{rich_menu_id}/content" headers = credentials.merge('Content-Type' => content_type(file)) post(blob_endpoint, endpoint_path, file.rewind && file.read, headers) end |
#credentials ⇒ Hash
70 71 72 73 74 |
# File 'lib/line/bot/client.rb', line 70 def credentials { "Authorization" => "Bearer #{channel_token}", } end |
#delete(endpoint_base, endpoint_path, headers = {}) ⇒ Net::HTTPResponse
Delete content of specified URL.
666 667 668 669 |
# File 'lib/line/bot/client.rb', line 666 def delete(endpoint_base, endpoint_path, headers = {}) headers = API::DEFAULT_HEADERS.merge(headers) httpclient.delete(endpoint_base + endpoint_path, headers) end |
#delete_rich_menu(rich_menu_id) ⇒ Net::HTTPResponse
Delete a rich menu
426 427 428 429 430 431 |
# File 'lib/line/bot/client.rb', line 426 def () channel_token_required endpoint_path = "/bot/richmenu/#{rich_menu_id}" delete(endpoint, endpoint_path, credentials) end |
#get(endpoint_base, endpoint_path, headers = {}) ⇒ Net::HTTPResponse
Fetch data, get content of specified URL.
641 642 643 644 |
# File 'lib/line/bot/client.rb', line 641 def get(endpoint_base, endpoint_path, headers = {}) headers = API::DEFAULT_HEADERS.merge(headers) httpclient.get(endpoint_base + endpoint_path, headers) end |
#get_default_rich_menu ⇒ Net::HTTPResponse
Get default rich menu
448 449 450 451 452 453 |
# File 'lib/line/bot/client.rb', line 448 def channel_token_required endpoint_path = '/bot/user/all/richmenu' get(endpoint, endpoint_path, credentials) end |
#get_friend_demographics ⇒ Net::HTTPResponse
Get the demographic attributes for a bot’s friends.
627 628 629 630 631 632 |
# File 'lib/line/bot/client.rb', line 627 def get_friend_demographics channel_token_required endpoint_path = '/bot/insight/demographic' get(endpoint, endpoint_path, credentials) end |
#get_group_member_ids(group_id, continuation_token = nil) ⇒ Net::HTTPResponse
Get user IDs of a group
280 281 282 283 284 285 286 |
# File 'lib/line/bot/client.rb', line 280 def get_group_member_ids(group_id, continuation_token = nil) channel_token_required endpoint_path = "/bot/group/#{group_id}/members/ids" endpoint_path += "?start=#{continuation_token}" if continuation_token get(endpoint, endpoint_path, credentials) end |
#get_group_member_profile(group_id, user_id) ⇒ Net::HTTPResponse
Get an user’s profile of a group.
253 254 255 256 257 258 |
# File 'lib/line/bot/client.rb', line 253 def get_group_member_profile(group_id, user_id) channel_token_required endpoint_path = "/bot/group/#{group_id}/member/#{user_id}" get(endpoint, endpoint_path, credentials) end |
#get_group_members_count(group_id) ⇒ Net::HTTPResponse
Gets the user IDs of the members of a group that the bot is in.
320 321 322 323 324 325 |
# File 'lib/line/bot/client.rb', line 320 def get_group_members_count(group_id) channel_token_required endpoint_path = "/bot/group/#{group_id}/members/count" get(endpoint, endpoint_path, credentials) end |
#get_group_summary(group_id) ⇒ Net::HTTPResponse
Gets the group ID, group name, and group icon URL of a group where the LINE Official Account is a member.
308 309 310 311 312 313 |
# File 'lib/line/bot/client.rb', line 308 def get_group_summary(group_id) channel_token_required endpoint_path = "/bot/group/#{group_id}/summary" get(endpoint, endpoint_path, credentials) end |
#get_message_content(identifier) ⇒ Net::HTTPResponse
Get message content.
229 230 231 232 233 234 |
# File 'lib/line/bot/client.rb', line 229 def (identifier) channel_token_required endpoint_path = "/bot/message/#{identifier}/content" get(blob_endpoint, endpoint_path, credentials) end |
#get_message_delivery_broadcast(date) ⇒ Net::HTTPResponse
Gets the number of messages sent with the /bot/message/multicast endpoint.
402 403 404 405 406 407 |
# File 'lib/line/bot/client.rb', line 402 def (date) channel_token_required endpoint_path = "/bot/message/delivery/broadcast?date=#{date}" get(endpoint, endpoint_path, credentials) end |
#get_message_delivery_multicast(date) ⇒ Net::HTTPResponse
Gets the number of messages sent with the /bot/message/multicast endpoint.
390 391 392 393 394 395 |
# File 'lib/line/bot/client.rb', line 390 def (date) channel_token_required endpoint_path = "/bot/message/delivery/multicast?date=#{date}" get(endpoint, endpoint_path, credentials) end |
#get_message_delivery_push(date) ⇒ Net::HTTPResponse
Gets the number of messages sent with the /bot/message/push endpoint.
378 379 380 381 382 383 |
# File 'lib/line/bot/client.rb', line 378 def (date) channel_token_required endpoint_path = "/bot/message/delivery/push?date=#{date}" get(endpoint, endpoint_path, credentials) end |
#get_message_delivery_reply(date) ⇒ Net::HTTPResponse
Gets the number of messages sent with the /bot/message/reply endpoint.
366 367 368 369 370 371 |
# File 'lib/line/bot/client.rb', line 366 def (date) channel_token_required endpoint_path = "/bot/message/delivery/reply?date=#{date}" get(endpoint, endpoint_path, credentials) end |
#get_number_of_followers(date) ⇒ Net::HTTPResponse
Returns the number of followers
617 618 619 620 621 622 |
# File 'lib/line/bot/client.rb', line 617 def get_number_of_followers(date) channel_token_required endpoint_path = "/bot/insight/followers?date=#{date}" get(endpoint, endpoint_path, credentials) end |
#get_number_of_message_deliveries(date) ⇒ Net::HTTPResponse
Returns the number of messages sent on a specified day
593 594 595 596 597 598 |
# File 'lib/line/bot/client.rb', line 593 def (date) channel_token_required endpoint_path = "/bot/insight/message/delivery?date=#{date}" get(endpoint, endpoint_path, credentials) end |
#get_profile(user_id) ⇒ Net::HTTPResponse
Get an user’s profile.
240 241 242 243 244 245 |
# File 'lib/line/bot/client.rb', line 240 def get_profile(user_id) channel_token_required endpoint_path = "/bot/profile/#{user_id}" get(endpoint, endpoint_path, credentials) end |
#get_quota ⇒ Net::HTTPResponse
Get the target limit for additional messages
571 572 573 574 575 576 |
# File 'lib/line/bot/client.rb', line 571 def get_quota channel_token_required endpoint_path = "/bot/message/quota" get(endpoint, endpoint_path, credentials) end |
#get_quota_consumption ⇒ Net::HTTPResponse
Get number of messages sent this month
581 582 583 584 585 586 |
# File 'lib/line/bot/client.rb', line 581 def get_quota_consumption channel_token_required endpoint_path = "/bot/message/quota/consumption" get(endpoint, endpoint_path, credentials) end |
#get_rich_menu(rich_menu_id) ⇒ Net::HTTPResponse
Get a rich menu via a rich menu ID
354 355 356 357 358 359 |
# File 'lib/line/bot/client.rb', line 354 def () channel_token_required endpoint_path = "/bot/richmenu/#{rich_menu_id}" get(endpoint, endpoint_path, credentials) end |
#get_rich_menu_image(rich_menu_id) ⇒ Net::HTTPResponse
Download an image associated with a rich menu
535 536 537 538 539 540 |
# File 'lib/line/bot/client.rb', line 535 def () channel_token_required endpoint_path = "/bot/richmenu/#{rich_menu_id}/content" get(blob_endpoint, endpoint_path, credentials) end |
#get_rich_menus ⇒ Net::HTTPResponse
Get a list of all uploaded rich menus
342 343 344 345 346 347 |
# File 'lib/line/bot/client.rb', line 342 def channel_token_required endpoint_path = '/bot/richmenu/list' get(endpoint, endpoint_path, credentials) end |
#get_room_member_ids(room_id, continuation_token = nil) ⇒ Net::HTTPResponse
Get user IDs of a room
295 296 297 298 299 300 301 |
# File 'lib/line/bot/client.rb', line 295 def get_room_member_ids(room_id, continuation_token = nil) channel_token_required endpoint_path = "/bot/room/#{room_id}/members/ids" endpoint_path += "?start=#{continuation_token}" if continuation_token get(endpoint, endpoint_path, credentials) end |
#get_room_member_profile(room_id, user_id) ⇒ Net::HTTPResponse
Get an user’s profile of a room.
266 267 268 269 270 271 |
# File 'lib/line/bot/client.rb', line 266 def get_room_member_profile(room_id, user_id) channel_token_required endpoint_path = "/bot/room/#{room_id}/member/#{user_id}" get(endpoint, endpoint_path, credentials) end |
#get_room_members_count(room_id) ⇒ Net::HTTPResponse
Gets the count of members in a room.
332 333 334 335 336 337 |
# File 'lib/line/bot/client.rb', line 332 def get_room_members_count(room_id) channel_token_required endpoint_path = "/bot/room/#{room_id}/members/count" get(endpoint, endpoint_path, credentials) end |
#get_user_interaction_statistics(request_id) ⇒ Net::HTTPResponse
Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account.
605 606 607 608 609 610 |
# File 'lib/line/bot/client.rb', line 605 def get_user_interaction_statistics(request_id) channel_token_required endpoint_path = "/bot/insight/message/event?requestId=#{request_id}" get(endpoint, endpoint_path, credentials) end |
#get_user_rich_menu(user_id) ⇒ Net::HTTPResponse
Get the ID of the rich menu linked to a user
438 439 440 441 442 443 |
# File 'lib/line/bot/client.rb', line 438 def (user_id) channel_token_required endpoint_path = "/bot/user/#{user_id}/richmenu" get(endpoint, endpoint_path, credentials) end |
#issue_channel_token(grant_type = 'client_credentials') ⇒ Net::HTTPResponse
Issue channel access token
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/line/bot/client.rb', line 81 def issue_channel_token(grant_type = 'client_credentials') channel_id_required channel_secret_required endpoint_path = '/oauth/accessToken' payload = URI.encode_www_form( grant_type: grant_type, client_id: channel_id, client_secret: channel_secret ) headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } post(endpoint, endpoint_path, payload, headers) end |
#leave_group(group_id) ⇒ Object
211 212 213 214 215 216 |
# File 'lib/line/bot/client.rb', line 211 def leave_group(group_id) channel_token_required endpoint_path = "/bot/group/#{group_id}/leave" post(endpoint, endpoint_path, nil, credentials) end |
#leave_room(room_id) ⇒ Object
218 219 220 221 222 223 |
# File 'lib/line/bot/client.rb', line 218 def leave_room(room_id) channel_token_required endpoint_path = "/bot/room/#{room_id}/leave" post(endpoint, endpoint_path, nil, credentials) end |
#link_user_rich_menu(user_id, rich_menu_id) ⇒ Net::HTTPResponse
Link a rich menu to a user
If you want to link a rich menu to multiple users, please consider to use bulk_link_rich_menus.
486 487 488 489 490 491 |
# File 'lib/line/bot/client.rb', line 486 def (user_id, ) channel_token_required endpoint_path = "/bot/user/#{user_id}/richmenu/#{rich_menu_id}" post(endpoint, endpoint_path, nil, credentials) end |
#multicast(to, messages, headers: {}) ⇒ Net::HTTPResponse
Send messages to multiple users using userIds.
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/line/bot/client.rb', line 157 def multicast(to, , headers: {}) channel_token_required to = [to] if to.is_a?(String) = [] if .is_a?(Hash) endpoint_path = '/bot/message/multicast' payload = { to: to, messages: }.to_json post(endpoint, endpoint_path, payload, credentials.merge(headers)) end |
#narrowcast(messages, recipient: nil, filter: nil, limit: nil, headers: {}) ⇒ Net::HTTPResponse
Narrowcast messages to users
API Documentation is here. developers.line.biz/en/reference/messaging-api/#send-narrowcast-message
196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/line/bot/client.rb', line 196 def narrowcast(, recipient: nil, filter: nil, limit: nil, headers: {}) channel_token_required = [] if .is_a?(Hash) endpoint_path = '/bot/message/narrowcast' payload = { messages: , recipient: recipient, filter: filter, limit: limit }.to_json post(endpoint, endpoint_path, payload, credentials.merge(headers)) end |
#parse_events_from(request_body) ⇒ Array<Line::Bot::Event::Class>
Parse events from request.body
676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/line/bot/client.rb', line 676 def parse_events_from(request_body) json = JSON.parse(request_body) json['events'].map do |item| begin klass = Event.const_get(Util.camelize(item['type'])) klass.new(item) rescue NameError Event::Base.new(item) end end end |
#post(endpoint_base, endpoint_path, payload = nil, headers = {}) ⇒ Net::HTTPResponse
Post data, get content of specified URL.
654 655 656 657 |
# File 'lib/line/bot/client.rb', line 654 def post(endpoint_base, endpoint_path, payload = nil, headers = {}) headers = API::DEFAULT_HEADERS.merge(headers) httpclient.post(endpoint_base + endpoint_path, payload, headers) end |
#push_message(user_id, messages, headers: {}) ⇒ Net::HTTPResponse
Push messages to a user using user_id.
111 112 113 114 115 116 117 118 119 |
# File 'lib/line/bot/client.rb', line 111 def (user_id, , headers: {}) channel_token_required = [] if .is_a?(Hash) endpoint_path = '/bot/message/push' payload = { to: user_id, messages: }.to_json post(endpoint, endpoint_path, payload, credentials.merge(headers)) end |
#reply_message(token, messages) ⇒ Net::HTTPResponse
Reply messages to a user using replyToken.
141 142 143 144 145 146 147 148 149 |
# File 'lib/line/bot/client.rb', line 141 def (token, ) channel_token_required = [] if .is_a?(Hash) endpoint_path = '/bot/message/reply' payload = { replyToken: token, messages: }.to_json post(endpoint, endpoint_path, payload, credentials) end |
#revoke_channel_token(access_token) ⇒ Net::HTTPResponse
Revoke channel access token
98 99 100 101 102 103 |
# File 'lib/line/bot/client.rb', line 98 def revoke_channel_token(access_token) endpoint_path = '/oauth/revoke' payload = URI.encode_www_form(access_token: access_token) headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } post(endpoint, endpoint_path, payload, headers) end |
#set_default_rich_menu(rich_menu_id) ⇒ Net::HTTPResponse
Set default rich menu (Link a rich menu to all user)
460 461 462 463 464 465 |
# File 'lib/line/bot/client.rb', line 460 def () channel_token_required endpoint_path = "/bot/user/all/richmenu/#{rich_menu_id}" post(endpoint, endpoint_path, nil, credentials) end |
#unlink_user_rich_menu(user_id) ⇒ Net::HTTPResponse
Unlink a rich menu from a user
498 499 500 501 502 503 |
# File 'lib/line/bot/client.rb', line 498 def (user_id) channel_token_required endpoint_path = "/bot/user/#{user_id}/richmenu" delete(endpoint, endpoint_path, credentials) end |
#unset_default_rich_menu ⇒ Net::HTTPResponse
Unset default rich menu (Unlink a rich menu from all user)
470 471 472 473 474 475 |
# File 'lib/line/bot/client.rb', line 470 def channel_token_required endpoint_path = "/bot/user/all/richmenu" delete(endpoint, endpoint_path, credentials) end |
#validate_signature(content, channel_signature) ⇒ Boolean
Validate signature of a webhook event.
developers.line.biz/en/reference/messaging-api/#signature-validation
697 698 699 700 701 702 703 704 |
# File 'lib/line/bot/client.rb', line 697 def validate_signature(content, channel_signature) return false if !channel_signature || !channel_secret hash = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, channel_secret, content) signature = Base64.strict_encode64(hash) variable_secure_compare(channel_signature, signature) end |