19
19
20
20
module Line
21
21
module Bot
22
+ # API Client of LINE Bot SDK Ruby
23
+ #
24
+ # @client ||= Line::Bot::Client.new do |config|
25
+ # config.channel_id = ENV["LINE_CHANNEL_ID"]
26
+ # config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
27
+ # config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
28
+ # end
22
29
class Client
23
30
# @return [String]
24
31
attr_accessor :channel_token , :channel_id , :channel_secret , :endpoint , :blob_endpoint
@@ -29,10 +36,9 @@ class Client
29
36
# @return [Hash]
30
37
attr_accessor :http_options
31
38
32
- # Initialize a new Bot Client .
39
+ # Initialize a new client .
33
40
#
34
41
# @param options [Hash]
35
- #
36
42
# @return [Line::Bot::Client]
37
43
def initialize ( options = { } )
38
44
options . each do |key , value |
@@ -96,11 +102,10 @@ def revoke_channel_token(access_token)
96
102
post ( endpoint , endpoint_path , payload , headers )
97
103
end
98
104
99
- # Push messages to line server and to user.
100
- #
101
- # @param user_id [String] User's identifiers
102
- # @param messages [Hash or Array]
105
+ # Push messages to a user using user_id.
103
106
#
107
+ # @param user_id [String] User Id
108
+ # @param messages [Hash or Array] Message Objects
104
109
# @return [Net::HTTPResponse]
105
110
def push_message ( user_id , messages )
106
111
channel_token_required
@@ -112,11 +117,25 @@ def push_message(user_id, messages)
112
117
post ( endpoint , endpoint_path , payload , credentials )
113
118
end
114
119
115
- # Reply messages to line server and to users.
120
+ # Reply messages to a user using replyToken.
121
+ #
122
+ # @example Send a balloon to a user.
123
+ # message = {
124
+ # type: 'text',
125
+ # text: 'Hello, World!'
126
+ # }
127
+ # client.reply_message(event['replyToken'], message)
116
128
#
117
- # @param token [String]
118
- # @param messages [Hash or Array]
129
+ # @example Send multiple balloons to a user.
119
130
#
131
+ # messages = [
132
+ # {type: 'text', text: 'Message1'},
133
+ # {type: 'text', text: 'Message2'}
134
+ # ]
135
+ # client.reply_message(event['replyToken'], messages)
136
+ #
137
+ # @param token [String] Reply Token
138
+ # @param messages [Hash or Array] Message Objects
120
139
# @return [Net::HTTPResponse]
121
140
def reply_message ( token , messages )
122
141
channel_token_required
@@ -128,11 +147,10 @@ def reply_message(token, messages)
128
147
post ( endpoint , endpoint_path , payload , credentials )
129
148
end
130
149
131
- # Multicast messages to line server and to users.
132
- #
133
- # @param to [Array or String]
134
- # @param messages [Hash or Array]
150
+ # Send messages to multiple users using userIds.
135
151
#
152
+ # @param to [Array or String] Array of userIds
153
+ # @param messages [Hash or Array] Message Objects
136
154
# @return [Net::HTTPResponse]
137
155
def multicast ( to , messages )
138
156
channel_token_required
@@ -145,10 +163,9 @@ def multicast(to, messages)
145
163
post ( endpoint , endpoint_path , payload , credentials )
146
164
end
147
165
148
- # Broadcast messages to users
149
- #
150
- # @param messages [Hash or Array]
166
+ # Send messages to all friends.
151
167
#
168
+ # @param messages [Hash or Array] Message Objects
152
169
# @return [Net::HTTPResponse]
153
170
def broadcast ( messages )
154
171
channel_token_required
@@ -177,7 +194,6 @@ def leave_room(room_id)
177
194
# Get message content.
178
195
#
179
196
# @param identifier [String] Message's identifier
180
- #
181
197
# @return [Net::HTTPResponse]
182
198
def get_message_content ( identifier )
183
199
channel_token_required
@@ -188,8 +204,7 @@ def get_message_content(identifier)
188
204
189
205
# Get an user's profile.
190
206
#
191
- # @param user_id [String] User's identifier
192
- #
207
+ # @param user_id [String] User Id user_id
193
208
# @return [Net::HTTPResponse]
194
209
def get_profile ( user_id )
195
210
channel_token_required
@@ -201,7 +216,7 @@ def get_profile(user_id)
201
216
# Get an user's profile of a group.
202
217
#
203
218
# @param group_id [String] Group's identifier
204
- # @param user_id [String] User's identifier
219
+ # @param user_id [String] User Id user_id
205
220
#
206
221
# @return [Net::HTTPResponse]
207
222
def get_group_member_profile ( group_id , user_id )
@@ -214,7 +229,7 @@ def get_group_member_profile(group_id, user_id)
214
229
# Get an user's profile of a room.
215
230
#
216
231
# @param room_id [String] Room's identifier
217
- # @param user_id [String] User's identifier
232
+ # @param user_id [String] User Id user_id
218
233
#
219
234
# @return [Net::HTTPResponse]
220
235
def get_room_member_profile ( room_id , user_id )
@@ -241,7 +256,7 @@ def get_group_member_ids(group_id, continuation_token = nil)
241
256
242
257
# Get user IDs of a room
243
258
#
244
- # @param group_id [String] Room's identifier
259
+ # @param room_id [String] Room's identifier
245
260
# @param continuation_token [String] Identifier to return next page
246
261
# (next property to be included in the response)
247
262
#
@@ -394,6 +409,9 @@ def unset_default_rich_menu
394
409
395
410
# Link a rich menu to a user
396
411
#
412
+ # If you want to link a rich menu to multiple users,
413
+ # please consider to use bulk_link_rich_menus.
414
+ #
397
415
# @param user_id [String] ID of the user
398
416
# @param rich_menu_id [String] ID of an uploaded rich menu
399
417
#
@@ -531,7 +549,7 @@ def get_number_of_followers(date)
531
549
get ( endpoint , endpoint_path , credentials )
532
550
end
533
551
534
- # Retrieves the demographic attributes for a bot's friends.
552
+ # Get the demographic attributes for a bot's friends.
535
553
#
536
554
# @return [Net::HTTPResponse]
537
555
def get_friend_demographics
@@ -596,7 +614,9 @@ def parse_events_from(request_body)
596
614
end
597
615
end
598
616
599
- # Validate signature
617
+ # Validate signature of a webhook event.
618
+ #
619
+ # https://developers.line.biz/en/reference/messaging-api/#signature-validation
600
620
#
601
621
# @param content [String] Request's body
602
622
# @param channel_signature [String] Request'header 'X-LINE-Signature' # HTTP_X_LINE_SIGNATURE
0 commit comments