Class: Line::Bot::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Line::Bot::Client

Initialize a new client.

Parameters:

  • options (Hash) (defaults to: {})

Yields:

  • (_self)

Yield Parameters:



43
44
45
46
47
48
# File 'lib/line/bot/client.rb', line 43

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
  yield(self) if block_given?
end

Instance Attribute Details

#blob_endpointObject

@return [String]



31
32
33
# File 'lib/line/bot/client.rb', line 31

def blob_endpoint
  @blob_endpoint
end

#channel_idObject

@return [String]



31
32
33
# File 'lib/line/bot/client.rb', line 31

def channel_id
  @channel_id
end

#channel_secretObject

@return [String]



31
32
33
# File 'lib/line/bot/client.rb', line 31

def channel_secret
  @channel_secret
end

#channel_tokenObject

@return [String]



31
32
33
# File 'lib/line/bot/client.rb', line 31

def channel_token
  @channel_token
end

#endpointObject

@return [String]



31
32
33
# File 'lib/line/bot/client.rb', line 31

def endpoint
  @endpoint
end

#http_optionsHash

Returns:

  • (Hash)


37
38
39
# File 'lib/line/bot/client.rb', line 37

def http_options
  @http_options
end

#httpclientObject

Returns:

  • (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.

Parameters:

  • messages (Hash, Array)

    Message Objects

  • headers (Hash) (defaults to: {})

    HTTP Headers

Returns:

  • (Net::HTTPResponse)


282
283
284
285
286
287
288
289
290
# File 'lib/line/bot/client.rb', line 282

def broadcast(messages, headers: {})
  channel_token_required

  messages = [messages] if messages.is_a?(Hash)

  endpoint_path = '/bot/message/broadcast'
  payload = { messages: messages }.to_json
  post(endpoint, endpoint_path, payload, credentials.merge(headers))
end

To link a rich menu to multiple users at a time

Parameters:

  • user_ids (Array)

    ID of the user

  • rich_menu_id (String)

    ID of the uploaded rich menu

Returns:

  • (Net::HTTPResponse)


777
778
779
780
781
782
# File 'lib/line/bot/client.rb', line 777

def bulk_link_rich_menus(user_ids, rich_menu_id)
  channel_token_required

  endpoint_path = "/bot/richmenu/bulk/link"
  post(endpoint, endpoint_path, { richMenuId: rich_menu_id, userIds: user_ids }.to_json, credentials)
end

To unlink a rich menu from multiple users at a time

Parameters:

  • user_ids (Array)

    ID of the user

Returns:

  • (Net::HTTPResponse)


789
790
791
792
793
794
# File 'lib/line/bot/client.rb', line 789

def bulk_unlink_rich_menus(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

Parameters:

  • params (Hash)

    options

Returns:

  • (Net::HTTPResponse)

    This response includes an audience_group_id.



1016
1017
1018
1019
1020
1021
# File 'lib/line/bot/client.rb', line 1016

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

Parameters:

  • params (Hash)

    options

Returns:

  • (Net::HTTPResponse)

    This response includes an audience_group_id.



1031
1032
1033
1034
1035
1036
# File 'lib/line/bot/client.rb', line 1031

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



957
958
959
960
961
962
# File 'lib/line/bot/client.rb', line 957

def create_liff_app(app)
  channel_token_required

  endpoint_path = '/apps'
  post(liff_endpoint, endpoint_path, app.to_json, credentials)
end

Issue a link token to a user

Parameters:

  • user_id (String)

    ID of the user

Returns:

  • (Net::HTTPResponse)


827
828
829
830
831
832
# File 'lib/line/bot/client.rb', line 827

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

Parameters:

  • rich_menu (Hash)

    The rich menu represented as a rich menu object

Returns:

  • (Net::HTTPResponse)


608
609
610
611
612
613
# File 'lib/line/bot/client.rb', line 608

def create_rich_menu(rich_menu)
  channel_token_required

  endpoint_path = '/bot/richmenu'
  post(endpoint, endpoint_path, rich_menu.to_json, credentials)
end

#create_rich_menu_image(rich_menu_id, file) ⇒ Net::HTTPResponse

Upload and attaches an image to a rich menu

Parameters:

  • rich_menu_id (String)

    The ID of the rich menu to attach the image to

  • file (File)

    Image file to attach rich menu

Returns:

  • (Net::HTTPResponse)


814
815
816
817
818
819
820
# File 'lib/line/bot/client.rb', line 814

def create_rich_menu_image(rich_menu_id, 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

#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

Parameters:

  • params (Hash)

    options

Returns:

  • (Net::HTTPResponse)

    This response includes an audience_group_id.



986
987
988
989
990
991
# File 'lib/line/bot/client.rb', line 986

def create_user_id_audience(params)
  channel_token_required

  endpoint_path = '/bot/audienceGroup/upload'
  post(endpoint, endpoint_path, params.to_json, credentials)
end

#credentialsHash

Returns:

  • (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.

Parameters:

  • endpoint_base (String)
  • endpoint_path (String)
  • headers (Hash) (defaults to: {})

Returns:

  • (Net::HTTPResponse)


1255
1256
1257
1258
# File 'lib/line/bot/client.rb', line 1255

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

Parameters:

  • audience_group_id (Integer)

Returns:

  • (Net::HTTPResponse)


1060
1061
1062
1063
1064
1065
# File 'lib/line/bot/client.rb', line 1060

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



971
972
973
974
975
976
# File 'lib/line/bot/client.rb', line 971

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

Parameters:

  • rich_menu_id (String)

    ID of an uploaded rich menu

Returns:

  • (Net::HTTPResponse)


632
633
634
635
636
637
# File 'lib/line/bot/client.rb', line 632

def delete_rich_menu(rich_menu_id)
  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.

Parameters:

  • endpoint_base (String)
  • endpoint_path (String)
  • headers (Hash) (defaults to: {})

Returns:

  • (Net::HTTPResponse)


1217
1218
1219
1220
# File 'lib/line/bot/client.rb', line 1217

def get(endpoint_base, endpoint_path, headers = {})
  headers = API::DEFAULT_HEADERS.merge(headers)
  httpclient.get(endpoint_base + endpoint_path, headers)
end

#get_aggregation_infoNet::HTTPResponse

Get the number of aggregation units used this month.

Returns:

  • (Net::HTTPResponse)


1144
1145
1146
1147
1148
1149
# File 'lib/line/bot/client.rb', line 1144

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.

Parameters:

  • limit (Integer) (defaults to: nil)

    Maximum number of aggregation units per request. Maximum: 100, Default: 100.

  • start (String) (defaults to: nil)

    Value of the continuation token found in the ‘next` property of the JSON object returned in the response.

Returns:

  • (Net::HTTPResponse)


1157
1158
1159
1160
1161
1162
1163
# File 'lib/line/bot/client.rb', line 1157

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

Parameters:

  • audience_group_id (Integer)

Returns:

  • (Net::HTTPResponse)


1075
1076
1077
1078
1079
1080
# File 'lib/line/bot/client.rb', line 1075

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_levelNet::HTTPResponse

Get the authority level of the audience

Parameters are described here. developers.line.biz/en/reference/messaging-api/#get-authority-level

Returns:

  • (Net::HTTPResponse)


1103
1104
1105
1106
1107
1108
# File 'lib/line/bot/client.rb', line 1103

def get_audience_authority_level
  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

Parameters:

  • params (Hash)

    key name ‘page` is required

Returns:

  • (Net::HTTPResponse)


1090
1091
1092
1093
1094
1095
# File 'lib/line/bot/client.rb', line 1090

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_infoNet::HTTPResponse

Gets a bot’s basic information.

Returns:

  • (Net::HTTPResponse)


903
904
905
906
907
908
# File 'lib/line/bot/client.rb', line 903

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

Parameters:

  • jwt (String)

Returns:

  • (Net::HTTPResponse)


187
188
189
190
191
192
193
194
195
196
# File 'lib/line/bot/client.rb', line 187

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_menuNet::HTTPResponse

Get default rich menu

Returns:

  • (Net::HTTPResponse)


654
655
656
657
658
659
# File 'lib/line/bot/client.rb', line 654

def get_default_rich_menu
  channel_token_required

  endpoint_path = '/bot/user/all/richmenu'
  get(endpoint, endpoint_path, credentials)
end

#get_delivery_result_sent_by_phone_numbers(date) ⇒ Net::HTTPResponse

Get the delivery result of the message delivered in Send message using phone number. (‘#multicast_by_phone_numbers`)

Parameters:

  • date (String)

    Date the message was sent in UTC+9 with ‘yyyyMMdd` format.

Returns:

  • (Net::HTTPResponse)


1203
1204
1205
1206
1207
1208
# File 'lib/line/bot/client.rb', line 1203

def get_delivery_result_sent_by_phone_numbers(date)
  channel_token_required

  endpoint_path = "/bot/message/delivery/ad_phone?date=#{date}"
  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

Parameters:

  • start (String) (defaults to: nil)

    Identifier to return next page (next property to be included in the response)

  • limit (Integer) (defaults to: nil)

    The maximum number of user IDs to retrieve in a single request

Returns:

  • (Net::HTTPResponse)


387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/line/bot/client.rb', line 387

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_demographicsNet::HTTPResponse

Get the demographic attributes for a bot’s friends.

Returns:

  • (Net::HTTPResponse)


893
894
895
896
897
898
# File 'lib/line/bot/client.rb', line 893

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

Parameters:

  • group_id (String)

    Group’s identifier

  • continuation_token (String) (defaults to: nil)

    Identifier to return next page (next property to be included in the response)

Returns:

  • (Net::HTTPResponse)


409
410
411
412
413
414
415
# File 'lib/line/bot/client.rb', line 409

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.

Parameters:

  • group_id (String)

    Group’s identifier

  • user_id (String)

    User Id user_id

Returns:

  • (Net::HTTPResponse)


361
362
363
364
365
366
# File 'lib/line/bot/client.rb', line 361

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.

Parameters:

  • group_id (String)

    Group’s identifier

Returns:

  • (Net::HTTPResponse)


449
450
451
452
453
454
# File 'lib/line/bot/client.rb', line 449

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.

Parameters:

  • group_id (String)

    Group’s identifier

Returns:

  • (Net::HTTPResponse)


437
438
439
440
441
442
# File 'lib/line/bot/client.rb', line 437

def get_group_summary(group_id)
  channel_token_required

  endpoint_path = "/bot/group/#{group_id}/summary"
  get(endpoint, endpoint_path, credentials)
end

#get_liff_appsObject



950
951
952
953
954
955
# File 'lib/line/bot/client.rb', line 950

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.

Parameters:

  • identifier (String)

    Message’s identifier

Returns:

  • (Net::HTTPResponse)


337
338
339
340
341
342
# File 'lib/line/bot/client.rb', line 337

def get_message_content(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.

Parameters:

  • date (String)

    Date the messages were sent (format: yyyyMMdd)

Returns:

  • (Net::HTTPResponse)


531
532
533
534
535
536
# File 'lib/line/bot/client.rb', line 531

def get_message_delivery_broadcast(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.

Parameters:

  • date (String)

    Date the messages were sent (format: yyyyMMdd)

Returns:

  • (Net::HTTPResponse)


519
520
521
522
523
524
# File 'lib/line/bot/client.rb', line 519

def get_message_delivery_multicast(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.

Parameters:

  • date (String)

    Date the messages were sent (format: yyyyMMdd)

Returns:

  • (Net::HTTPResponse)


507
508
509
510
511
512
# File 'lib/line/bot/client.rb', line 507

def get_message_delivery_push(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.

Parameters:

  • date (String)

    Date the messages were sent (format: yyyyMMdd)

Returns:

  • (Net::HTTPResponse)


495
496
497
498
499
500
# File 'lib/line/bot/client.rb', line 495

def get_message_delivery_reply(date)
  channel_token_required

  endpoint_path = "/bot/message/delivery/reply?date=#{date}"
  get(endpoint, endpoint_path, credentials)
end

#get_narrowcast_message_status(request_id) ⇒ Net::HTTPResponse

Gets the status of a narrowcast message.

Parameters:

  • request_id (String)

    The narrowcast message’s request ID. Each Messaging API request has a request ID. Find it in the response headers.

Returns:

  • (Net::HTTPResponse)


1170
1171
1172
1173
1174
1175
# File 'lib/line/bot/client.rb', line 1170

def get_narrowcast_message_status(request_id)
  channel_token_required

  endpoint_path = "/bot/message/progress/narrowcast?requestId=#{request_id}"
  get(endpoint, endpoint_path, credentials)
end

#get_number_of_followers(date) ⇒ Net::HTTPResponse

Returns the number of followers

Parameters:

  • date (String)

    (Format:yyyyMMdd, Example:20191231)

Returns:

  • (Net::HTTPResponse)


883
884
885
886
887
888
# File 'lib/line/bot/client.rb', line 883

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

Parameters:

  • date (String)

    (Format:yyyyMMdd, Example:20191231)

Returns:

  • (Net::HTTPResponse)


859
860
861
862
863
864
# File 'lib/line/bot/client.rb', line 859

def get_number_of_message_deliveries(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.

Parameters:

  • user_id (String)

    User Id user_id

Returns:

  • (Net::HTTPResponse)


348
349
350
351
352
353
# File 'lib/line/bot/client.rb', line 348

def get_profile(user_id)
  channel_token_required

  endpoint_path = "/bot/profile/#{user_id}"
  get(endpoint, endpoint_path, credentials)
end

#get_profile_by_access_token(access_token) ⇒ Net::HTTPResponse

Get user profile by access token

Parameters:

  • access_token (String)

    access token

Returns:

  • (Net::HTTPResponse)


203
204
205
206
207
208
209
# File 'lib/line/bot/client.rb', line 203

def get_profile_by_access_token(access_token)
  headers = {
    "Authorization" => "Bearer #{access_token}",
  }
  endpoint_path = "/v2/profile"
  get(oauth_endpoint, endpoint_path, headers)
end

#get_quotaNet::HTTPResponse

Get the target limit for additional messages

Returns:

  • (Net::HTTPResponse)


837
838
839
840
841
842
# File 'lib/line/bot/client.rb', line 837

def get_quota
  channel_token_required

  endpoint_path = "/bot/message/quota"
  get(endpoint, endpoint_path, credentials)
end

#get_quota_consumptionNet::HTTPResponse

Get number of messages sent this month

Returns:

  • (Net::HTTPResponse)


847
848
849
850
851
852
# File 'lib/line/bot/client.rb', line 847

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

Parameters:

  • rich_menu_id (String)

    ID of an uploaded rich menu

Returns:

  • (Net::HTTPResponse)


483
484
485
486
487
488
# File 'lib/line/bot/client.rb', line 483

def get_rich_menu(rich_menu_id)
  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

Parameters:

  • rich_menu_id (String)

    ID of an uploaded rich menu

Returns:

  • (Net::HTTPResponse)


801
802
803
804
805
806
# File 'lib/line/bot/client.rb', line 801

def get_rich_menu_image(rich_menu_id)
  channel_token_required

  endpoint_path = "/bot/richmenu/#{rich_menu_id}/content"
  get(blob_endpoint, endpoint_path, credentials)
end

#get_rich_menusNet::HTTPResponse

Get a list of all uploaded rich menus

Returns:

  • (Net::HTTPResponse)


471
472
473
474
475
476
# File 'lib/line/bot/client.rb', line 471

def get_rich_menus
  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

Parameters:

  • rich_menu_alias_id (String)

    string of alias words rich menu

Returns:

  • (Net::HTTPResponse)


726
727
728
729
730
731
# File 'lib/line/bot/client.rb', line 726

def get_rich_menus_alias(rich_menu_alias_id)
  channel_token_required

  endpoint_path = "/bot/richmenu/alias/#{rich_menu_alias_id}"
  get(endpoint, endpoint_path, credentials)
end

#get_rich_menus_alias_listNet::HTTPResponse

Get a list of all uploaded rich menus alias

Returns:

  • (Net::HTTPResponse)


736
737
738
739
740
741
# File 'lib/line/bot/client.rb', line 736

def get_rich_menus_alias_list
  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

Parameters:

  • room_id (String)

    Room’s identifier

  • continuation_token (String) (defaults to: nil)

    Identifier to return next page (next property to be included in the response)

Returns:

  • (Net::HTTPResponse)


424
425
426
427
428
429
430
# File 'lib/line/bot/client.rb', line 424

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.

Parameters:

  • room_id (String)

    Room’s identifier

  • user_id (String)

    User Id user_id

Returns:

  • (Net::HTTPResponse)


374
375
376
377
378
379
# File 'lib/line/bot/client.rb', line 374

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.

Parameters:

  • room_id (String)

    Room’s identifier

Returns:

  • (Net::HTTPResponse)


461
462
463
464
465
466
# File 'lib/line/bot/client.rb', line 461

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.

Parameters:

  • unit (String)

    Case-sensitive name of aggregation unit specified when sending the message.

  • from (String)

    Start date of aggregation period in UTC+9 with ‘yyyyMMdd` format

  • to (String)

    End date of aggregation period in UTC+9 with ‘yyyyMMdd` format.

Returns:

  • (Net::HTTPResponse)


1133
1134
1135
1136
1137
1138
1139
# File 'lib/line/bot/client.rb', line 1133

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.

Parameters:

  • request_id (String)

Returns:

  • (Net::HTTPResponse)


871
872
873
874
875
876
# File 'lib/line/bot/client.rb', line 871

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

Parameters:

  • user_id (String)

    ID of the user

Returns:

  • (Net::HTTPResponse)


644
645
646
647
648
649
# File 'lib/line/bot/client.rb', line 644

def get_user_rich_menu(user_id)
  channel_token_required

  endpoint_path = "/bot/user/#{user_id}/richmenu"
  get(endpoint, endpoint_path, credentials)
end

#get_webhook_endpointNet::HTTPResponse

Gets information on a webhook endpoint.

Returns:

  • (Net::HTTPResponse)


913
914
915
916
917
918
# File 'lib/line/bot/client.rb', line 913

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

Parameters:

  • jwt (String)

Returns:

  • (Net::HTTPResponse)


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

Parameters:

  • grant_type (String) (defaults to: 'client_credentials')

    Grant type

Returns:

  • (Net::HTTPResponse)


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



319
320
321
322
323
324
# File 'lib/line/bot/client.rb', line 319

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



326
327
328
329
330
331
# File 'lib/line/bot/client.rb', line 326

def leave_room(room_id)
  channel_token_required

  endpoint_path = "/bot/room/#{room_id}/leave"
  post(endpoint, endpoint_path, nil, credentials)
end

#liff_endpointObject



73
74
75
# File 'lib/line/bot/client.rb', line 73

def liff_endpoint
  @liff_endpoint ||= API::DEFAULT_LIFF_ENDPOINT
end

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.

Parameters:

  • user_id (String)

    ID of the user

  • rich_menu_id (String)

    ID of an uploaded rich menu

Returns:

  • (Net::HTTPResponse)


752
753
754
755
756
757
# File 'lib/line/bot/client.rb', line 752

def link_user_rich_menu(user_id, rich_menu_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: {}, payload: {}) ⇒ Net::HTTPResponse

Send messages to multiple users using userIds.

Parameters:

  • to (Array, String)

    Array of userIds

  • messages (Hash, Array)

    Message Objects

  • headers (Hash) (defaults to: {})

    HTTP Headers

  • payload (Hash) (defaults to: {})

    Additional request body

Returns:

  • (Net::HTTPResponse)


265
266
267
268
269
270
271
272
273
274
# File 'lib/line/bot/client.rb', line 265

def multicast(to, messages, headers: {}, payload: {})
  channel_token_required

  to = [to] if to.is_a?(String)
  messages = [messages] if messages.is_a?(Hash)

  endpoint_path = '/bot/message/multicast'
  payload = payload.merge({ to: to, messages: messages }).to_json
  post(endpoint, endpoint_path, payload, credentials.merge(headers))
end

#multicast_by_phone_numbers(to, messages, headers: {}, payload: {}) ⇒ Net::HTTPResponse

Send messages to multiple users using phone numbers.

Parameters:

  • to (Array, String)

    Array of hashed phone numbers.

  • messages (Hash, Array)

    Message Objects.

  • headers (Hash) (defaults to: {})

    HTTP Headers.

  • payload (Hash) (defaults to: {})

    Additional request body.

Returns:

  • (Net::HTTPResponse)


1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
# File 'lib/line/bot/client.rb', line 1186

def multicast_by_phone_numbers(to, messages, headers: {}, payload: {})
  channel_token_required

  to = [to] if to.is_a?(String)
  messages = [messages] if messages.is_a?(Hash)

  endpoint_path = 'bot/ad/multicast/phone'
  payload = payload.merge({ to: to, messages: messages }).to_json
  post(oauth_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

Parameters:

  • messages (Hash, Array)
  • recipient (Hash) (defaults to: nil)
  • filter (Hash) (defaults to: nil)
  • limit (Hash) (defaults to: nil)
  • headers (Hash) (defaults to: {})

    HTTP Headers

Returns:

  • (Net::HTTPResponse)


304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/line/bot/client.rb', line 304

def narrowcast(messages, recipient: nil, filter: nil, limit: nil, headers: {})
  channel_token_required

  messages = [messages] if messages.is_a?(Hash)

  endpoint_path = '/bot/message/narrowcast'
  payload = {
    messages: messages,
    recipient: recipient,
    filter: filter,
    limit: limit
  }.to_json
  post(endpoint, endpoint_path, payload, credentials.merge(headers))
end

#oauth_endpointObject



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

Parameters:

  • request_body (String)

Returns:

  • (Array<Line::Bot::Event::Class>)


1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
# File 'lib/line/bot/client.rb', line 1265

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.

Parameters:

  • endpoint_base (String)
  • endpoint_path (String)
  • payload (String, NilClass) (defaults to: nil)
  • headers (Hash) (defaults to: {})

Returns:

  • (Net::HTTPResponse)


1230
1231
1232
1233
# File 'lib/line/bot/client.rb', line 1230

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.

Parameters:

  • user_id (String)

    User Id

  • messages (Hash, Array)

    Message Objects

  • headers (Hash) (defaults to: {})

    HTTP Headers

  • payload (Hash) (defaults to: {})

    Additional request body

Returns:

  • (Net::HTTPResponse)


218
219
220
221
222
223
224
225
226
# File 'lib/line/bot/client.rb', line 218

def push_message(user_id, messages, headers: {}, payload: {})
  channel_token_required

  messages = [messages] if messages.is_a?(Hash)

  endpoint_path = '/bot/message/push'
  payload = payload.merge({ to: user_id, messages: 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.

Parameters:

  • endpoint_base (String)
  • endpoint_path (String)
  • payload (String, NilClass) (defaults to: nil)
  • headers (Hash) (defaults to: {})

Returns:

  • (Net::HTTPResponse)


1243
1244
1245
1246
# File 'lib/line/bot/client.rb', line 1243

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

Parameters:

  • audience_group_id (Integer)
  • description (String)

Returns:

  • (Net::HTTPResponse)


1044
1045
1046
1047
1048
1049
1050
# File 'lib/line/bot/client.rb', line 1044

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.

Examples:

Send a balloon to a user.

message = {
  type: 'text',
  text: 'Hello, World!'
}
client.reply_message(event['replyToken'], message)

Send multiple balloons to a user.


messages = [
 {type: 'text', text: 'Message1'},
 {type: 'text', text: 'Message2'}
]
client.reply_message(event['replyToken'], messages)

Parameters:

  • token (String)

    Reply Token

  • messages (Hash, Array)

    Message Objects

Returns:

  • (Net::HTTPResponse)


248
249
250
251
252
253
254
255
256
# File 'lib/line/bot/client.rb', line 248

def reply_message(token, messages)
  channel_token_required

  messages = [messages] if messages.is_a?(Hash)

  endpoint_path = '/bot/message/reply'
  payload = { replyToken: token, messages: 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

Parameters:

  • access_token (String)

Returns:

  • (Net::HTTPResponse)


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

Returns:

  • (Net::HTTPResponse)


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)

Parameters:

  • rich_menu_id (String)

    ID of an uploaded rich menu

Returns:

  • (Net::HTTPResponse)


666
667
668
669
670
671
# File 'lib/line/bot/client.rb', line 666

def set_default_rich_menu(rich_menu_id)
  channel_token_required

  endpoint_path = "/bot/user/all/richmenu/#{rich_menu_id}"
  post(endpoint, endpoint_path, nil, credentials)
end

#set_rich_menus_alias(rich_menu_id, rich_menu_alias_id) ⇒ Net::HTTPResponse

Set rich menu alias

Parameters:

  • rich_menu_id (String)

    ID of an uploaded rich menu

  • rich_menu_alias_id (String)

    string of alias words rich menu

Returns:

  • (Net::HTTPResponse)


689
690
691
692
693
694
# File 'lib/line/bot/client.rb', line 689

def set_rich_menus_alias(rich_menu_id, rich_menu_alias_id)
  channel_token_required

  endpoint_path = '/bot/richmenu/alias'
  post(endpoint, endpoint_path, { richMenuId: rich_menu_id, richMenuAliasId: rich_menu_alias_id }.to_json, credentials)
end

#set_webhook_endpoint(webhook_endpoint) ⇒ Net::HTTPResponse

Sets the webhook endpoint URL.

Parameters:

  • webhook_endpoint (String)

Returns:

  • (Net::HTTPResponse)


925
926
927
928
929
930
931
# File 'lib/line/bot/client.rb', line 925

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.

Parameters:

  • webhook_endpoint (String) (defaults to: nil)

    options

Returns:

  • (Net::HTTPResponse)


938
939
940
941
942
943
944
945
946
947
948
# File 'lib/line/bot/client.rb', line 938

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 a rich menu from a user

Parameters:

  • user_id (String)

    ID of the user

Returns:

  • (Net::HTTPResponse)


764
765
766
767
768
769
# File 'lib/line/bot/client.rb', line 764

def unlink_user_rich_menu(user_id)
  channel_token_required

  endpoint_path = "/bot/user/#{user_id}/richmenu"
  delete(endpoint, endpoint_path, credentials)
end

#unset_default_rich_menuNet::HTTPResponse

Unset default rich menu (Unlink a rich menu from all user)

Returns:

  • (Net::HTTPResponse)


676
677
678
679
680
681
# File 'lib/line/bot/client.rb', line 676

def unset_default_rich_menu
  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

Parameters:

  • rich_menu_alias_id (String)

    string of alias words rich menu

Returns:

  • (Net::HTTPResponse)


701
702
703
704
705
706
# File 'lib/line/bot/client.rb', line 701

def unset_rich_menus_alias(rich_menu_alias_id)
  channel_token_required

  endpoint_path = "/bot/richmenu/alias/#{rich_menu_alias_id}"
  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

Parameters:

  • authority_level (String)

    value must be ‘PUBLIC` or `PRIVATE`

Returns:

  • (Net::HTTPResponse)


1118
1119
1120
1121
1122
1123
1124
# File 'lib/line/bot/client.rb', line 1118

def update_audience_authority_level(authority_level)
  channel_token_required

  endpoint_path = "/bot/audienceGroup/authorityLevel"
  body = {authorityLevel: authority_level}
  put(endpoint, endpoint_path, body.to_json, credentials)
end

#update_liff_app(liff_id, app) ⇒ Object



964
965
966
967
968
969
# File 'lib/line/bot/client.rb', line 964

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

Parameters:

  • rich_menu_id (String)

    ID of an uploaded rich menu

  • rich_menu_alias_id (String)

    string of alias words rich menu

Returns:

  • (Net::HTTPResponse)


714
715
716
717
718
719
# File 'lib/line/bot/client.rb', line 714

def update_rich_menus_alias(rich_menu_id, rich_menu_alias_id)
  channel_token_required

  endpoint_path = "/bot/richmenu/alias/#{rich_menu_alias_id}"
  post(endpoint, endpoint_path, { richMenuId: rich_menu_id }.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

Parameters:

  • params (Hash)

    options

Returns:

  • (Net::HTTPResponse)

    This response includes an audience_group_id.



1001
1002
1003
1004
1005
1006
# File 'lib/line/bot/client.rb', line 1001

def update_user_id_audience(params)
  channel_token_required

  endpoint_path = '/bot/audienceGroup/upload'
  put(endpoint, endpoint_path, params.to_json, credentials)
end

#validate_broadcast_message_objects(messages) ⇒ Net::HTTPResponse

Validate message objects of a broadcast message

Parameters:

  • messages (Array)

    Array of message objects to validate

Returns:

  • (Net::HTTPResponse)


595
596
597
598
599
600
601
# File 'lib/line/bot/client.rb', line 595

def validate_broadcast_message_objects(messages)
  channel_token_required

  endpoint_path = '/bot/message/validate/broadcast'
  payload = { messages: messages }.to_json
  post(endpoint, endpoint_path, payload, credentials)
end

#validate_multicast_message_objects(messages) ⇒ Net::HTTPResponse

Validate message objects of a multicast message

Parameters:

  • messages (Array)

    Array of message objects to validate

Returns:

  • (Net::HTTPResponse)


569
570
571
572
573
574
575
# File 'lib/line/bot/client.rb', line 569

def validate_multicast_message_objects(messages)
  channel_token_required

  endpoint_path = '/bot/message/validate/multicast'
  payload = { messages: messages }.to_json
  post(endpoint, endpoint_path, payload, credentials)
end

#validate_narrowcast_message_objects(messages) ⇒ Net::HTTPResponse

Validate message objects of a narrowcast message

Parameters:

  • messages (Array)

    Array of message objects to validate

Returns:

  • (Net::HTTPResponse)


582
583
584
585
586
587
588
# File 'lib/line/bot/client.rb', line 582

def validate_narrowcast_message_objects(messages)
  channel_token_required

  endpoint_path = '/bot/message/validate/narrowcast'
  payload = { messages: messages }.to_json
  post(endpoint, endpoint_path, payload, credentials)
end

#validate_push_message_objects(messages) ⇒ Net::HTTPResponse

Validate message objects of a push message

Parameters:

  • messages (Array)

    Array of message objects to validate

Returns:

  • (Net::HTTPResponse)


556
557
558
559
560
561
562
# File 'lib/line/bot/client.rb', line 556

def validate_push_message_objects(messages)
  channel_token_required

  endpoint_path = '/bot/message/validate/push'
  payload = { messages: messages }.to_json
  post(endpoint, endpoint_path, payload, credentials)
end

#validate_reply_message_objects(messages) ⇒ Net::HTTPResponse

Validate message objects of a reply message

Parameters:

  • messages (Array)

    Array of message objects to validate

Returns:

  • (Net::HTTPResponse)


543
544
545
546
547
548
549
# File 'lib/line/bot/client.rb', line 543

def validate_reply_message_objects(messages)
  channel_token_required

  endpoint_path = '/bot/message/validate/reply'
  payload = { messages: messages }.to_json
  post(endpoint, endpoint_path, payload, credentials)
end

#validate_rich_menu_object(rich_menu) ⇒ Net::HTTPResponse

Validate a rich menu object

Parameters:

  • rich_menu (Hash)

    The rich menu represented as a rich menu object

Returns:

  • (Net::HTTPResponse)


620
621
622
623
624
625
# File 'lib/line/bot/client.rb', line 620

def validate_rich_menu_object(rich_menu)
  channel_token_required

  endpoint_path = '/bot/richmenu/validate'
  post(endpoint, endpoint_path, rich_menu.to_json, credentials)
end

#validate_signature(content, channel_signature) ⇒ Boolean

Parameters:

  • content (String)

    Request’s body

  • channel_signature (String)

    Request’header ‘X-LINE-Signature’ # HTTP_X_LINE_SIGNATURE

Returns:

  • (Boolean)


1286
1287
1288
1289
1290
1291
1292
1293
# File 'lib/line/bot/client.rb', line 1286

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

#verify_access_token(access_token) ⇒ Net::HTTPResponse

Verify access token v2.1

Parameters:

  • access_token (String)

    access token

Returns:

  • (Net::HTTPResponse)


174
175
176
177
178
179
180
# File 'lib/line/bot/client.rb', line 174

def verify_access_token(access_token)
  payload = URI.encode_www_form(
    access_token: access_token
  )
  endpoint_path = "/oauth2/v2.1/verify?#{payload}"
  get(oauth_endpoint, endpoint_path)
end

#verify_id_token(id_token, nonce: nil, user_id: nil) ⇒ Net::HTTPResponse

Verify ID token

Parameters:

  • id_token (String)

    ID token

  • nonce (String) (defaults to: nil)

    Expected nonce value. Use the nonce value provided in the authorization request. Omit if the nonce value was not specified in the authorization request.

  • user_id (String) (defaults to: nil)

    Expected user ID.

Returns:

  • (Net::HTTPResponse)


155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/line/bot/client.rb', line 155

def verify_id_token(id_token, nonce: nil, user_id: nil)
  channel_id_required

  endpoint_path = '/oauth2/v2.1/verify'
  payload = URI.encode_www_form({
    client_id: channel_id,
    id_token: id_token,
    nonce: nonce,
    user_id: user_id
  }.compact)
  headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
  post(oauth_endpoint, endpoint_path, payload, headers)
end