Class: Line::Bot::Client
- Inherits:
-
Object
- Object
- Line::Bot::Client
- Defined in:
- lib/line/bot/client.rb
Overview
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_click_audience(params) ⇒ Net::HTTPResponse
Create an audience group of users that clicked a URL in a message sent in the past.
-
#create_impression_audience(params) ⇒ Net::HTTPResponse
Create an audience group of users that opened a message sent in the past.
- #create_liff_app(app) ⇒ Object
-
#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.
-
#create_user_id_audience(params) ⇒ Net::HTTPResponse
Create an audience group by uploading user_ids.
- #credentials ⇒ Hash
-
#delete(endpoint_base, endpoint_path, headers = {}) ⇒ Net::HTTPResponse
Delete content of specified URL.
-
#delete_audience(audience_group_id) ⇒ Net::HTTPResponse
Delete an existing audience group.
- #delete_liff_app(liff_id) ⇒ Object
-
#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_aggregation_info ⇒ Net::HTTPResponse
Get the number of aggregation units used this month.
-
#get_aggregation_list(limit: nil, start: nil) ⇒ Net::HTTPResponse
Get the name list of units used this month for statistics aggregation.
-
#get_audience(audience_group_id) ⇒ Net::HTTPResponse
Get audience group data.
-
#get_audience_authority_level ⇒ Net::HTTPResponse
Get the authority level of the audience.
-
#get_audiences(params) ⇒ Net::HTTPResponse
Get data for more than one audience group.
-
#get_bot_info ⇒ Net::HTTPResponse
Gets a bot’s basic information.
-
#get_channel_access_token_key_ids_jwt(jwt) ⇒ Net::HTTPResponse
Get all valid channel access token key IDs v2.1.
-
#get_default_rich_menu ⇒ Net::HTTPResponse
Get default rich menu.
-
#get_follower_ids(deprecated_continuation_token = nil, start: nil, limit: nil) ⇒ Net::HTTPResponse
Get user IDs of who added your LINE Official Account as a friend.
-
#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_liff_apps ⇒ Object
-
#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_rich_menus_alias(rich_menu_alias_id) ⇒ Net::HTTPResponse
Get a rich menu alias via a rich menu alias ID.
-
#get_rich_menus_alias_list ⇒ Net::HTTPResponse
Get a list of all uploaded rich menus alias.
-
#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_statistics_per_unit(unit:, from:, to:) ⇒ Net::HTTPResponse
Get the per-unit statistics of how users interact with push messages and multicast messages.
-
#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.
-
#get_webhook_endpoint ⇒ Net::HTTPResponse
Gets information on a webhook endpoint.
-
#initialize(options = {}) {|_self| ... } ⇒ Line::Bot::Client
constructor
Initialize a new client.
-
#issue_channel_access_token_jwt(jwt) ⇒ Net::HTTPResponse
Issue channel access token v2.1.
-
#issue_channel_token(grant_type = 'client_credentials') ⇒ Net::HTTPResponse
Issue channel access token.
- #leave_group(group_id) ⇒ Object
- #leave_room(room_id) ⇒ Object
- #liff_endpoint ⇒ Object
-
#link_user_rich_menu(user_id, rich_menu_id) ⇒ Net::HTTPResponse
Link a rich menu to a user.
-
#multicast(to, messages, headers: {}, payload: {}) ⇒ Net::HTTPResponse
Send messages to multiple users using userIds.
-
#narrowcast(messages, recipient: nil, filter: nil, limit: nil, headers: {}) ⇒ Net::HTTPResponse
Narrowcast messages to users.
- #oauth_endpoint ⇒ Object
-
#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: {}, payload: {}) ⇒ Net::HTTPResponse
Push messages to a user using user_id.
-
#put(endpoint_base, endpoint_path, payload = nil, headers = {}) ⇒ Net::HTTPResponse
Put data, get content of specified URL.
-
#rename_audience(audience_group_id, description) ⇒ Net::HTTPResponse
Rename an existing audience group.
-
#reply_message(token, messages) ⇒ Net::HTTPResponse
Reply messages to a user using replyToken.
-
#revoke_channel_access_token_jwt(access_token) ⇒ Net::HTTPResponse
Revoke channel access token v2.1.
-
#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).
-
#set_rich_menus_alias(rich_menu_id, rich_menu_alias_id) ⇒ Net::HTTPResponse
Set rich menu alias.
-
#set_webhook_endpoint(webhook_endpoint) ⇒ Net::HTTPResponse
Sets the webhook endpoint URL.
-
#test_webhook_endpoint(webhook_endpoint = nil) ⇒ Net::HTTPResponse
Checks if the configured webhook endpoint can receive a test webhook event.
-
#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).
-
#unset_rich_menus_alias(rich_menu_alias_id) ⇒ Net::HTTPResponse
Unset rich menu alias.
-
#update_audience_authority_level(authority_level) ⇒ Net::HTTPResponse
Change the authority level of the audience.
- #update_liff_app(liff_id, app) ⇒ Object
-
#update_rich_menus_alias(rich_menu_id, rich_menu_alias_id) ⇒ Net::HTTPResponse
Update rich menu alias.
-
#update_user_id_audience(params) ⇒ Net::HTTPResponse
Update an audience group.
-
#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 @http_options 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.
235 236 237 238 239 240 241 242 243 |
# File 'lib/line/bot/client.rb', line 235 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
653 654 655 656 657 658 |
# File 'lib/line/bot/client.rb', line 653 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
665 666 667 668 669 670 |
# File 'lib/line/bot/client.rb', line 665 def (user_ids) channel_token_required endpoint_path = "/bot/richmenu/bulk/unlink" post(endpoint, endpoint_path, { userIds: user_ids }.to_json, credentials) end |
#create_click_audience(params) ⇒ Net::HTTPResponse
Create an audience group of users that clicked a URL in a message sent in the past
Parameters are described here. developers.line.biz/en/reference/messaging-api/#create-click-audience-group
892 893 894 895 896 897 |
# File 'lib/line/bot/client.rb', line 892 def create_click_audience(params) channel_token_required endpoint_path = '/bot/audienceGroup/click' post(endpoint, endpoint_path, params.to_json, credentials) end |
#create_impression_audience(params) ⇒ Net::HTTPResponse
Create an audience group of users that opened a message sent in the past
Parameters are described here. developers.line.biz/en/reference/messaging-api/#create-imp-audience-group
907 908 909 910 911 912 |
# File 'lib/line/bot/client.rb', line 907 def create_impression_audience(params) channel_token_required endpoint_path = '/bot/audienceGroup/imp' post(endpoint, endpoint_path, params.to_json, credentials) end |
#create_liff_app(app) ⇒ Object
833 834 835 836 837 838 |
# File 'lib/line/bot/client.rb', line 833 def create_liff_app(app) channel_token_required endpoint_path = '/apps' post(liff_endpoint, endpoint_path, app.to_json, credentials) end |
#create_link_token(user_id) ⇒ Net::HTTPResponse
Issue a link token to a user
703 704 705 706 707 708 |
# File 'lib/line/bot/client.rb', line 703 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
496 497 498 499 500 501 |
# File 'lib/line/bot/client.rb', line 496 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
690 691 692 693 694 695 696 |
# File 'lib/line/bot/client.rb', line 690 def (, file) channel_token_required endpoint_path = "/bot/richmenu/#{}/content" headers = credentials.merge('Content-Type' => content_type(file)) post(blob_endpoint, endpoint_path, file.rewind && file.read, headers) end |
#create_user_id_audience(params) ⇒ Net::HTTPResponse
Create an audience group by uploading user_ids
Parameters are described here. developers.line.biz/en/reference/messaging-api/#create-upload-audience-group
862 863 864 865 866 867 |
# File 'lib/line/bot/client.rb', line 862 def create_user_id_audience(params) channel_token_required endpoint_path = '/bot/audienceGroup/upload' post(endpoint, endpoint_path, params.to_json, credentials) end |
#credentials ⇒ Hash
78 79 80 81 82 |
# File 'lib/line/bot/client.rb', line 78 def credentials { "Authorization" => "Bearer #{channel_token}", } end |
#delete(endpoint_base, endpoint_path, headers = {}) ⇒ Net::HTTPResponse
Delete content of specified URL.
1086 1087 1088 1089 |
# File 'lib/line/bot/client.rb', line 1086 def delete(endpoint_base, endpoint_path, headers = {}) headers = API::DEFAULT_HEADERS.merge(headers) httpclient.delete(endpoint_base + endpoint_path, headers) end |
#delete_audience(audience_group_id) ⇒ Net::HTTPResponse
Delete an existing audience group
Parameters are described here. developers.line.biz/en/reference/messaging-api/#delete-audience-group
936 937 938 939 940 941 |
# File 'lib/line/bot/client.rb', line 936 def delete_audience(audience_group_id) channel_token_required endpoint_path = "/bot/audienceGroup/#{audience_group_id}" delete(endpoint, endpoint_path, credentials) end |
#delete_liff_app(liff_id) ⇒ Object
847 848 849 850 851 852 |
# File 'lib/line/bot/client.rb', line 847 def delete_liff_app(liff_id) channel_token_required endpoint_path = "/apps/#{liff_id}" delete(liff_endpoint, endpoint_path, credentials) end |
#delete_rich_menu(rich_menu_id) ⇒ Net::HTTPResponse
Delete a rich menu
508 509 510 511 512 513 |
# File 'lib/line/bot/client.rb', line 508 def () channel_token_required endpoint_path = "/bot/richmenu/#{}" delete(endpoint, endpoint_path, credentials) end |
#get(endpoint_base, endpoint_path, headers = {}) ⇒ Net::HTTPResponse
Fetch data, get content of specified URL.
1048 1049 1050 1051 |
# File 'lib/line/bot/client.rb', line 1048 def get(endpoint_base, endpoint_path, headers = {}) headers = API::DEFAULT_HEADERS.merge(headers) httpclient.get(endpoint_base + endpoint_path, headers) end |
#get_aggregation_info ⇒ Net::HTTPResponse
Get the number of aggregation units used this month.
1020 1021 1022 1023 1024 1025 |
# File 'lib/line/bot/client.rb', line 1020 def get_aggregation_info channel_token_required endpoint_path = "/bot/message/aggregation/info" get(endpoint, endpoint_path, credentials) end |
#get_aggregation_list(limit: nil, start: nil) ⇒ Net::HTTPResponse
Get the name list of units used this month for statistics aggregation.
1033 1034 1035 1036 1037 1038 1039 |
# File 'lib/line/bot/client.rb', line 1033 def get_aggregation_list(limit: nil, start: nil) channel_token_required params = {limit: limit, start: start}.compact endpoint_path = "/bot/message/aggregation/list?" + URI.encode_www_form(params) get(endpoint, endpoint_path, credentials) end |
#get_audience(audience_group_id) ⇒ Net::HTTPResponse
Get audience group data
Parameters are described here. developers.line.biz/en/reference/messaging-api/#get-audience-group
951 952 953 954 955 956 |
# File 'lib/line/bot/client.rb', line 951 def get_audience(audience_group_id) channel_token_required endpoint_path = "/bot/audienceGroup/#{audience_group_id}" get(endpoint, endpoint_path, credentials) end |
#get_audience_authority_level ⇒ Net::HTTPResponse
Get the authority level of the audience
Parameters are described here. developers.line.biz/en/reference/messaging-api/#get-authority-level
979 980 981 982 983 984 |
# File 'lib/line/bot/client.rb', line 979 def channel_token_required endpoint_path = "/bot/audienceGroup/authorityLevel" get(endpoint, endpoint_path, credentials) end |
#get_audiences(params) ⇒ Net::HTTPResponse
Get data for more than one audience group
Parameters are described here. developers.line.biz/en/reference/messaging-api/#get-audience-groups
966 967 968 969 970 971 |
# File 'lib/line/bot/client.rb', line 966 def get_audiences(params) channel_token_required endpoint_path = "/bot/audienceGroup/list?" + URI.encode_www_form(params) get(endpoint, endpoint_path, credentials) end |
#get_bot_info ⇒ Net::HTTPResponse
Gets a bot’s basic information.
779 780 781 782 783 784 |
# File 'lib/line/bot/client.rb', line 779 def get_bot_info channel_token_required endpoint_path = '/bot/info' get(endpoint, endpoint_path, credentials) end |
#get_channel_access_token_key_ids_jwt(jwt) ⇒ Net::HTTPResponse
Get all valid channel access token key IDs v2.1
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/line/bot/client.rb', line 153 def get_channel_access_token_key_ids_jwt(jwt) payload = URI.encode_www_form( client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer', client_assertion: jwt ) endpoint_path = "/oauth2/v2.1/tokens/kid?#{payload}" headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } get(oauth_endpoint, endpoint_path, headers) end |
#get_default_rich_menu ⇒ Net::HTTPResponse
Get default rich menu
530 531 532 533 534 535 |
# File 'lib/line/bot/client.rb', line 530 def channel_token_required endpoint_path = '/bot/user/all/richmenu' get(endpoint, endpoint_path, credentials) end |
#get_follower_ids(deprecated_continuation_token = nil, start: nil, limit: nil) ⇒ Net::HTTPResponse
Get user IDs of who added your LINE Official Account as a friend
340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/line/bot/client.rb', line 340 def get_follower_ids(deprecated_continuation_token = nil, start: nil, limit: nil) channel_token_required if deprecated_continuation_token warn "continuation_token as the first argument is deprecated. Please use :start instead." start = deprecated_continuation_token end params = { start: start, limit: limit }.compact endpoint_path = "/bot/followers/ids" endpoint_path += "?" + URI.encode_www_form(params) unless params.empty? get(endpoint, endpoint_path, credentials) end |
#get_friend_demographics ⇒ Net::HTTPResponse
Get the demographic attributes for a bot’s friends.
769 770 771 772 773 774 |
# File 'lib/line/bot/client.rb', line 769 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
362 363 364 365 366 367 368 |
# File 'lib/line/bot/client.rb', line 362 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.
314 315 316 317 318 319 |
# File 'lib/line/bot/client.rb', line 314 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.
402 403 404 405 406 407 |
# File 'lib/line/bot/client.rb', line 402 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.
390 391 392 393 394 395 |
# File 'lib/line/bot/client.rb', line 390 def get_group_summary(group_id) channel_token_required endpoint_path = "/bot/group/#{group_id}/summary" get(endpoint, endpoint_path, credentials) end |
#get_liff_apps ⇒ Object
826 827 828 829 830 831 |
# File 'lib/line/bot/client.rb', line 826 def get_liff_apps channel_token_required endpoint_path = '/apps' get(liff_endpoint, endpoint_path, credentials) end |
#get_message_content(identifier) ⇒ Net::HTTPResponse
Get message content.
290 291 292 293 294 295 |
# File 'lib/line/bot/client.rb', line 290 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.
484 485 486 487 488 489 |
# File 'lib/line/bot/client.rb', line 484 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.
472 473 474 475 476 477 |
# File 'lib/line/bot/client.rb', line 472 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.
460 461 462 463 464 465 |
# File 'lib/line/bot/client.rb', line 460 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.
448 449 450 451 452 453 |
# File 'lib/line/bot/client.rb', line 448 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
759 760 761 762 763 764 |
# File 'lib/line/bot/client.rb', line 759 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
735 736 737 738 739 740 |
# File 'lib/line/bot/client.rb', line 735 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.
301 302 303 304 305 306 |
# File 'lib/line/bot/client.rb', line 301 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
713 714 715 716 717 718 |
# File 'lib/line/bot/client.rb', line 713 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
723 724 725 726 727 728 |
# File 'lib/line/bot/client.rb', line 723 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
436 437 438 439 440 441 |
# File 'lib/line/bot/client.rb', line 436 def () channel_token_required endpoint_path = "/bot/richmenu/#{}" get(endpoint, endpoint_path, credentials) end |
#get_rich_menu_image(rich_menu_id) ⇒ Net::HTTPResponse
Download an image associated with a rich menu
677 678 679 680 681 682 |
# File 'lib/line/bot/client.rb', line 677 def () channel_token_required endpoint_path = "/bot/richmenu/#{}/content" get(blob_endpoint, endpoint_path, credentials) end |
#get_rich_menus ⇒ Net::HTTPResponse
Get a list of all uploaded rich menus
424 425 426 427 428 429 |
# File 'lib/line/bot/client.rb', line 424 def channel_token_required endpoint_path = '/bot/richmenu/list' get(endpoint, endpoint_path, credentials) end |
#get_rich_menus_alias(rich_menu_alias_id) ⇒ Net::HTTPResponse
Get a rich menu alias via a rich menu alias ID
602 603 604 605 606 607 |
# File 'lib/line/bot/client.rb', line 602 def () channel_token_required endpoint_path = "/bot/richmenu/alias/#{}" get(endpoint, endpoint_path, credentials) end |
#get_rich_menus_alias_list ⇒ Net::HTTPResponse
Get a list of all uploaded rich menus alias
612 613 614 615 616 617 |
# File 'lib/line/bot/client.rb', line 612 def channel_token_required endpoint_path = "/bot/richmenu/alias/list" get(endpoint, endpoint_path, credentials) end |
#get_room_member_ids(room_id, continuation_token = nil) ⇒ Net::HTTPResponse
Get user IDs of a room
377 378 379 380 381 382 383 |
# File 'lib/line/bot/client.rb', line 377 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.
327 328 329 330 331 332 |
# File 'lib/line/bot/client.rb', line 327 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.
414 415 416 417 418 419 |
# File 'lib/line/bot/client.rb', line 414 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_statistics_per_unit(unit:, from:, to:) ⇒ Net::HTTPResponse
Get the per-unit statistics of how users interact with push messages and multicast messages.
1009 1010 1011 1012 1013 1014 1015 |
# File 'lib/line/bot/client.rb', line 1009 def get_statistics_per_unit(unit:, from:, to:) channel_token_required params = {customAggregationUnit: unit, from: from, to: to} endpoint_path = "/bot/insight/message/event/aggregation?" + URI.encode_www_form(params) 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.
747 748 749 750 751 752 |
# File 'lib/line/bot/client.rb', line 747 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
520 521 522 523 524 525 |
# File 'lib/line/bot/client.rb', line 520 def (user_id) channel_token_required endpoint_path = "/bot/user/#{user_id}/richmenu" get(endpoint, endpoint_path, credentials) end |
#get_webhook_endpoint ⇒ Net::HTTPResponse
Gets information on a webhook endpoint.
789 790 791 792 793 794 |
# File 'lib/line/bot/client.rb', line 789 def get_webhook_endpoint channel_token_required endpoint_path = '/bot/channel/webhook/endpoint' get(endpoint, endpoint_path, credentials) end |
#issue_channel_access_token_jwt(jwt) ⇒ Net::HTTPResponse
Issue channel access token v2.1
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/line/bot/client.rb', line 118 def issue_channel_access_token_jwt(jwt) endpoint_path = '/oauth2/v2.1/token' payload = URI.encode_www_form( grant_type: 'client_credentials', client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer', client_assertion: jwt ) headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } post(oauth_endpoint, endpoint_path, payload, headers) end |
#issue_channel_token(grant_type = 'client_credentials') ⇒ Net::HTTPResponse
Issue channel access token
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/line/bot/client.rb', line 89 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
272 273 274 275 276 277 |
# File 'lib/line/bot/client.rb', line 272 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
279 280 281 282 283 284 |
# File 'lib/line/bot/client.rb', line 279 def leave_room(room_id) channel_token_required endpoint_path = "/bot/room/#{room_id}/leave" post(endpoint, endpoint_path, nil, credentials) end |
#liff_endpoint ⇒ Object
73 74 75 |
# File 'lib/line/bot/client.rb', line 73 def liff_endpoint @liff_endpoint ||= API::DEFAULT_LIFF_ENDPOINT 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.
628 629 630 631 632 633 |
# File 'lib/line/bot/client.rb', line 628 def (user_id, ) channel_token_required endpoint_path = "/bot/user/#{user_id}/richmenu/#{}" post(endpoint, endpoint_path, nil, credentials) end |
#multicast(to, messages, headers: {}, payload: {}) ⇒ Net::HTTPResponse
Send messages to multiple users using userIds.
218 219 220 221 222 223 224 225 226 227 |
# File 'lib/line/bot/client.rb', line 218 def multicast(to, , headers: {}, payload: {}) channel_token_required to = [to] if to.is_a?(String) = [] if .is_a?(Hash) endpoint_path = '/bot/message/multicast' payload = payload.merge({ 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
257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/line/bot/client.rb', line 257 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 |
#oauth_endpoint ⇒ Object
58 59 60 |
# File 'lib/line/bot/client.rb', line 58 def oauth_endpoint @oauth_endpoint ||= API::DEFAULT_OAUTH_ENDPOINT end |
#parse_events_from(request_body) ⇒ Array<Line::Bot::Event::Class>
Parse events from request.body
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 |
# File 'lib/line/bot/client.rb', line 1096 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.
1061 1062 1063 1064 |
# File 'lib/line/bot/client.rb', line 1061 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: {}, payload: {}) ⇒ Net::HTTPResponse
Push messages to a user using user_id.
171 172 173 174 175 176 177 178 179 |
# File 'lib/line/bot/client.rb', line 171 def (user_id, , headers: {}, payload: {}) channel_token_required = [] if .is_a?(Hash) endpoint_path = '/bot/message/push' payload = payload.merge({ to: user_id, messages: }).to_json post(endpoint, endpoint_path, payload, credentials.merge(headers)) end |
#put(endpoint_base, endpoint_path, payload = nil, headers = {}) ⇒ Net::HTTPResponse
Put data, get content of specified URL.
1074 1075 1076 1077 |
# File 'lib/line/bot/client.rb', line 1074 def put(endpoint_base, endpoint_path, payload = nil, headers = {}) headers = API::DEFAULT_HEADERS.merge(headers) httpclient.put(endpoint_base + endpoint_path, payload, headers) end |
#rename_audience(audience_group_id, description) ⇒ Net::HTTPResponse
Rename an existing audience group
920 921 922 923 924 925 926 |
# File 'lib/line/bot/client.rb', line 920 def rename_audience(audience_group_id, description) channel_token_required endpoint_path = "/bot/audienceGroup/#{audience_group_id}/updateDescription" body = {description: description} put(endpoint, endpoint_path, body.to_json, credentials) end |
#reply_message(token, messages) ⇒ Net::HTTPResponse
Reply messages to a user using replyToken.
201 202 203 204 205 206 207 208 209 |
# File 'lib/line/bot/client.rb', line 201 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_access_token_jwt(access_token) ⇒ Net::HTTPResponse
Revoke channel access token v2.1
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/line/bot/client.rb', line 134 def revoke_channel_access_token_jwt(access_token) channel_id_required channel_secret_required endpoint_path = '/oauth2/v2.1/revoke' payload = URI.encode_www_form( client_id: channel_id, client_secret: channel_secret, access_token: access_token ) headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } post(oauth_endpoint, endpoint_path, payload, headers) end |
#revoke_channel_token(access_token) ⇒ Net::HTTPResponse
Revoke channel access token
106 107 108 109 110 111 |
# File 'lib/line/bot/client.rb', line 106 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)
542 543 544 545 546 547 |
# File 'lib/line/bot/client.rb', line 542 def () channel_token_required endpoint_path = "/bot/user/all/richmenu/#{}" post(endpoint, endpoint_path, nil, credentials) end |
#set_rich_menus_alias(rich_menu_id, rich_menu_alias_id) ⇒ Net::HTTPResponse
Set rich menu alias
565 566 567 568 569 570 |
# File 'lib/line/bot/client.rb', line 565 def (, ) channel_token_required endpoint_path = '/bot/richmenu/alias' post(endpoint, endpoint_path, { richMenuId: , richMenuAliasId: }.to_json, credentials) end |
#set_webhook_endpoint(webhook_endpoint) ⇒ Net::HTTPResponse
Sets the webhook endpoint URL.
801 802 803 804 805 806 807 |
# File 'lib/line/bot/client.rb', line 801 def set_webhook_endpoint(webhook_endpoint) channel_token_required endpoint_path = '/bot/channel/webhook/endpoint' body = {endpoint: webhook_endpoint} put(endpoint, endpoint_path, body.to_json, credentials) end |
#test_webhook_endpoint(webhook_endpoint = nil) ⇒ Net::HTTPResponse
Checks if the configured webhook endpoint can receive a test webhook event.
814 815 816 817 818 819 820 821 822 823 824 |
# File 'lib/line/bot/client.rb', line 814 def test_webhook_endpoint(webhook_endpoint = nil) channel_token_required endpoint_path = '/bot/channel/webhook/test' body = if webhook_endpoint.nil? {} else {endpoint: webhook_endpoint} end post(endpoint, endpoint_path, body.to_json, credentials) end |
#unlink_user_rich_menu(user_id) ⇒ Net::HTTPResponse
Unlink a rich menu from a user
640 641 642 643 644 645 |
# File 'lib/line/bot/client.rb', line 640 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)
552 553 554 555 556 557 |
# File 'lib/line/bot/client.rb', line 552 def channel_token_required endpoint_path = "/bot/user/all/richmenu" delete(endpoint, endpoint_path, credentials) end |
#unset_rich_menus_alias(rich_menu_alias_id) ⇒ Net::HTTPResponse
Unset rich menu alias
577 578 579 580 581 582 |
# File 'lib/line/bot/client.rb', line 577 def () channel_token_required endpoint_path = "/bot/richmenu/alias/#{}" delete(endpoint, endpoint_path, credentials) end |
#update_audience_authority_level(authority_level) ⇒ Net::HTTPResponse
Change the authority level of the audience
Parameters are described here. developers.line.biz/en/reference/messaging-api/#change-authority-level
994 995 996 997 998 999 1000 |
# File 'lib/line/bot/client.rb', line 994 def () channel_token_required endpoint_path = "/bot/audienceGroup/authorityLevel" body = {authorityLevel: } put(endpoint, endpoint_path, body.to_json, credentials) end |
#update_liff_app(liff_id, app) ⇒ Object
840 841 842 843 844 845 |
# File 'lib/line/bot/client.rb', line 840 def update_liff_app(liff_id, app) channel_token_required endpoint_path = "/apps/#{liff_id}" put(liff_endpoint, endpoint_path, app.to_json, credentials) end |
#update_rich_menus_alias(rich_menu_id, rich_menu_alias_id) ⇒ Net::HTTPResponse
Update rich menu alias
590 591 592 593 594 595 |
# File 'lib/line/bot/client.rb', line 590 def (, ) channel_token_required endpoint_path = "/bot/richmenu/alias/#{}" post(endpoint, endpoint_path, { richMenuId: }.to_json, credentials) end |
#update_user_id_audience(params) ⇒ Net::HTTPResponse
Update an audience group
Parameters are described here. developers.line.biz/en/reference/messaging-api/#update-upload-audience-group
877 878 879 880 881 882 |
# File 'lib/line/bot/client.rb', line 877 def update_user_id_audience(params) channel_token_required endpoint_path = '/bot/audienceGroup/upload' put(endpoint, endpoint_path, params.to_json, credentials) end |
#validate_signature(content, channel_signature) ⇒ Boolean
Validate signature of a webhook event.
developers.line.biz/en/reference/messaging-api/#signature-validation
1117 1118 1119 1120 1121 1122 1123 1124 |
# File 'lib/line/bot/client.rb', line 1117 def validate_signature(content, channel_signature) return false if !channel_signature || !channel_secret hash = OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA256'), channel_secret, content) signature = Base64.strict_encode64(hash) variable_secure_compare(channel_signature, signature) end |