qismo 0.13.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/qismo/api.rb +556 -324
  3. data/lib/qismo/client.rb +31 -19
  4. data/lib/qismo/collection.rb +21 -0
  5. data/lib/qismo/object.rb +21 -0
  6. data/lib/qismo/objectified_hash.rb +30 -0
  7. data/lib/qismo/objects/agent_service.rb +53 -0
  8. data/lib/qismo/objects/broadcast_job.rb +99 -0
  9. data/lib/qismo/objects/broadcast_log.rb +59 -0
  10. data/lib/qismo/objects/custom_channel.rb +35 -0
  11. data/lib/qismo/objects/custom_channel_message_response.rb +19 -0
  12. data/lib/qismo/objects/customer_room.rb +85 -0
  13. data/lib/qismo/objects/fb_channel.rb +31 -0
  14. data/lib/qismo/objects/hsm_template.rb +111 -0
  15. data/lib/qismo/objects/ig_channel.rb +43 -0
  16. data/lib/qismo/objects/line_channel.rb +27 -0
  17. data/lib/qismo/objects/list_channels_response.rb +39 -0
  18. data/lib/qismo/objects/office_hour.rb +67 -0
  19. data/lib/qismo/objects/qiscus_channel.rb +27 -0
  20. data/lib/qismo/objects/room_additional_info.rb +15 -0
  21. data/lib/qismo/objects/tag.rb +27 -0
  22. data/lib/qismo/objects/telegram_channel.rb +31 -0
  23. data/lib/qismo/objects/user.rb +99 -0
  24. data/lib/qismo/objects/wa_channel.rb +111 -0
  25. data/lib/qismo/objects/wa_credit_info.rb +71 -0
  26. data/lib/qismo/objects/waca_channel.rb +55 -0
  27. data/lib/qismo/objects/webhook.rb +15 -0
  28. data/lib/qismo/types.rb +10 -1
  29. data/lib/qismo/version.rb +1 -1
  30. data/lib/qismo/webhook_requests/on_agent_allocation_needed.rb +8 -2
  31. data/lib/qismo/webhook_requests/on_custom_button_clicked.rb +15 -7
  32. data/lib/qismo/webhook_requests/on_custom_channel_message_sent.rb +18 -6
  33. data/lib/qismo/webhook_requests/on_message_for_bot_sent.rb +18 -6
  34. data/lib/qismo/webhook_requests/on_new_session_initiated.rb +30 -10
  35. data/lib/qismo/webhook_requests/on_room_resolved.rb +15 -5
  36. data/lib/qismo.rb +28 -34
  37. data/qismo.gemspec +1 -0
  38. metadata +40 -6
  39. data/lib/qismo/model.rb +0 -102
  40. data/lib/qismo/models/base.rb +0 -13
  41. data/lib/qismo/models/customer_room.rb +0 -6
  42. data/lib/qismo/util.rb +0 -31
data/lib/qismo/api.rb CHANGED
@@ -1,109 +1,135 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Qismo
4
+ # API wrappers
5
+ #
4
6
  module Api
5
7
  # @!parse include Qismo::Client
6
8
 
7
9
  # List customer rooms
8
10
  #
9
- # @see https://s.id/list-customer-rooms
10
- # @param [Hash] options
11
- # @option options [String] :status Filter by room status. Valid values are "resolved", "unresolved", "expired", or "almost_expired"
12
- # @option options [String] :serve_status Filter by room serve status. Valid values are "served" or "unserved"
13
- # @option options [Array<Hash>] :channels Filter by channels. Example: [{ source: "wa", channel_id: 716171 }]
14
- # @option options [TrueClass,FalseClass] :is_handled_by_bot Filter by bot handling status
15
- # @option options [String] :name Filter by customer name
16
- # @option options [Integer] :limit Number of data returned in one page. Default is 50
17
- # @option options [String] :order Order data by timestamp. Can be ordered "asc" or "desc". Default is "desc"
18
- # @option options [String] :cursor_after Next page cursor. If you are on last page, the cursor returned will be nil
19
- # @option options [String] :cursor_before Previous page cursor. If you are on first page, the cursor returned will be nil
20
- # @option options [Array<Integer>] :tag_ids Filter by tags
21
- # @option options [Array<Integer>] :user_ids Filter by agent who handled or assigned to the room
22
- # @return [Qismo::CollectionObject]
23
- def rooms(options = {})
24
- body = post("/api/v2/customer_rooms", options)
25
- CollectionObject.new(
26
- body.data.customer_rooms,
27
- prev_page: body.meta&.cursor_before,
28
- next_page: body.meta&.cursor_after,
29
- prev_func: -> { rooms(options.merge(cursor_before: body.meta&.cursor_before)) },
30
- next_func: -> { rooms(options.merge(cursor_after: body.meta&.cursor_after)) }
11
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#704a0c40-56b2-4a94-9c1d-e1529923cbb6
12
+ # @param channels [Array<Hash>]
13
+ # Filter rooms by channels. Example: [{ source: "wa", channel_id: 716171 }]
14
+ # @param status [String]
15
+ # Filter rooms by status. Valid values are "resolved", "unresolved", "expired",or "almost_expired"
16
+ # @param serve_status [String]
17
+ # Filter rooms by serve status. Valid values are "served" or "unserved". By default, we will retrieve all serve_status
18
+ # @param name [String]
19
+ # Filter rooms by customer nam
20
+ # @param limit [Integer]
21
+ # Limit the number of rooms returned in one page. By default, it will return 50 rooms data
22
+ # @param tag_ids [Array<Integer>]
23
+ # Filter rooms by its tag
24
+ # @param agent_ids [Array<Integer>]
25
+ # Filter rooms by the agent who handled the rooms
26
+ # @param order [String]
27
+ # Order returned data by the timestamp. By default, we will return the newest rooms first
28
+ # @param cursor_after [String]
29
+ # Next page cursor. If you are on last page, the cursor returned will be nil
30
+ # @param cursor_before [String]
31
+ # Previous page cursor. If you are on first page, the cursor returned will be nil
32
+ # @return [Qismo::Collection<Qismo::CustomerRoom>]
33
+ def rooms(channels: nil, status: nil, serve_status: nil, name: nil, limit: 50, tag_ids: nil, agent_ids: nil, order: "desc", cursor_after: nil, cursor_before: nil)
34
+ body = post("/api/v2/customer_rooms", json: {
35
+ channels: channels,
36
+ status: status,
37
+ serve_status: serve_status,
38
+ name: name,
39
+ limit: limit,
40
+ tag_ids: tag_ids,
41
+ user_ids: agent_ids,
42
+ order: order,
43
+ cursor_after: cursor_after,
44
+ cursor_before: cursor_before
45
+ }.compact)
46
+
47
+ Collection.new(
48
+ Qismo::Objects::CustomerRoom.from_array(body.data.customer_rooms),
49
+ next_page: body.meta.cursor_after,
50
+ prev_page: body.meta.cursor_before
31
51
  )
32
52
  end
33
53
 
34
54
  # Get room by id
35
- #
36
- # @see https://s.id/get-room-by-room-id
55
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#8c803377-eea2-4879-9d66-8906d9f41275
37
56
  # @param room_id [Integer]
38
- # @return [Qismo::SingleObject]
39
- def room(room_id)
57
+ # @return [Qismo::Objects::CustomerRoom]
58
+ def room(room_id:)
40
59
  body = get("/api/v2/customer_rooms/#{room_id}")
41
60
  if body.data.customer_room.nil?
42
61
  raise Qismo::NotFoundError.new("Room not found", status_code: 404, response_body: body.to_json)
43
62
  end
44
63
 
45
- body.data.customer_room
64
+ Qismo::Objects::CustomerRoom.new(body.data.customer_room)
46
65
  end
47
66
 
48
67
  # List tags inside room
49
68
  #
50
- # @see https://s.id/list-room-tags
69
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#d40b54a7-2b37-4afc-b474-62593001274e
51
70
  # @param room_id [Integer]
52
- # @return [Qismo::CollectionObject]
53
- def room_tags(room_id)
54
- CollectionObject.new(get("/api/v2/room_tags/#{room_id}").data)
71
+ # @return [Qismo::Collection<Qismo::Objects::Tag>]
72
+ def room_tags(room_id:)
73
+ Qismo::Collection.new(
74
+ Qismo::Objects::Tag.from_array(
75
+ get("/api/v2/room_tags/#{room_id}").data
76
+ )
77
+ )
55
78
  end
56
79
 
57
80
  # Add room tag
58
81
  #
59
- # @see https://s.id/add-room-tag
82
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#9737d580-d156-4213-85a8-95fb3f1ad964
60
83
  # @param room_id [Integer]
61
84
  # @param tag_name [String]
62
- # @return [Qismo::SingleObject]
63
- def add_room_tag(room_id, tag_name)
64
- post("/api/v2/room_tags/#{room_id}", tag: tag_name).data
85
+ # @return [Qismo::Objects::Tag]
86
+ def add_room_tag(room_id:, tag_name:)
87
+ Qismo::Objects::Tag.new(
88
+ post("/api/v2/room_tags/#{room_id}", tag_name: tag).data
89
+ )
65
90
  end
66
91
 
67
92
  # Delete room tag
68
93
  #
69
- # @see https://s.id/delete-room-tag
94
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#f4d173a1-3fb1-4151-87fd-106982bcc4a2
70
95
  # @param room_id [Integer]
71
96
  # @param tag_id [Integer]
72
97
  # @return [TrueClass]
73
- def delete_room_tag(room_id, tag_id)
98
+ def delete_room_tag(room_id:, tag_id:)
74
99
  delete("/api/v2/room_tags/#{room_id}/#{tag_id}")
75
100
  true
76
101
  end
77
102
 
78
103
  # List room additional info
79
104
  #
80
- # @see https://s.id/list-room-info
105
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#88c2287b-21af-4afd-b495-aaaa2818c381
81
106
  # @param room_id [Integer]
82
- # @return [Qismo::CollectionObject]
83
- def room_additional_info(room_id)
84
- CollectionObject.new(
85
- get(
86
- "/api/v1/qiscus/room/#{room_id}/user_info"
87
- ).data&.extras&.user_properties
88
- ) || CollectionObject.new
107
+ # @return [Array<Qismo::Objects::RoomAdditionalInfo>]
108
+ def room_additional_info(room_id:)
109
+ Qismo::Objects::RoomAdditionalInfo.from_array(
110
+ get("/api/v1/qiscus/room/#{room_id}/user_info").data.extras.user_properties
111
+ )
112
+ rescue NoMethodError
113
+ Qismo::Objects::RoomAdditionalInfo.from_array([])
89
114
  end
90
115
 
91
116
  alias_method :room_info, :room_additional_info
92
117
 
93
118
  # Set room additional info
94
119
  #
95
- # @see https://s.id/set-room-info
120
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#2b968e9e-2a76-4569-8763-f883e11dc5a7
96
121
  # @note This will replace your current room additional info
97
122
  # @param room_id [Integer]
98
- # @param additional_info [Array<Hash>]
99
- # @return [Qismo::CollectionObject]
100
- def set_room_additional_info(room_id, additional_info)
101
- CollectionObject.new(
123
+ # @param info [Array<Hash>]
124
+ # Key value pair of additional info. Ex: [{ key: "Ticket Link", value: "https://ticket.com" }]
125
+ # @return [Array<Qismo::Objects::RoomAdditionalInfo>]
126
+ def set_room_additional_info(room_id:, info:)
127
+ Qismo::Objects::RoomAdditionalInfo.from_array(
102
128
  post(
103
129
  "/api/v1/qiscus/room/#{room_id}/user_info",
104
- user_properties: additional_info
105
- ).data&.extras&.user_properties
106
- ) || CollectionObject.new
130
+ user_properties: info
131
+ ).data.extras.user_properties
132
+ )
107
133
  end
108
134
 
109
135
  alias_method :set_room_info, :set_room_additional_info
@@ -113,212 +139,303 @@ module Qismo
113
139
  # Update room additional info
114
140
  #
115
141
  # @param room_id [Integer]
116
- # @param additional_info [Array]
117
- # @return [Qismo::CollectionObject]
118
- def update_room_additional_info(room_id, additional_info)
119
- old_additional_info = room_additional_info(room_id)
120
- new_additional_info = (additional_info + old_additional_info).uniq { |h| h.values_at("key") }
121
- set_room_additional_info(room_id, new_additional_info)
142
+ # @param info [Array<Hash>]
143
+ # Key value pair of additional info. Ex: [{ key: "Ticket Link", value: "https://ticket.com" }]
144
+ # @return [Array<Qismo::Objects::RoomAdditionalInfo>]
145
+ def update_room_additional_info(room_id:, info:)
146
+ old_info = room_additional_info(room_id).as_json
147
+ new_info = (info.as_json + old_info).uniq { |h| h.values_at("key") }
148
+ set_room_additional_info(room_id: room_id, info: new_info)
122
149
  end
123
150
 
124
151
  alias_method :update_room_info, :update_room_additional_info
125
152
 
126
- # List Whatsapp broadcast history inside room
153
+ # List broadcast history inside room
127
154
  #
128
- # @see https://s.id/list-room-broadcast-history
129
155
  # @param room_id [Integer]
130
- # @param options [Hash]
131
- # @return [Qismo::CollectionObject]
132
- def room_broadcast_history(room_id, options = {})
133
- body = get("/api/v2/customer_rooms/#{room_id}/broadcast_history", options)
134
-
135
- next_page = (body.meta.page < body.meta.total_page) ? (body.meta.page + 1) : nil
136
- prev_page = (body.meta.page > 1) ? (body.meta.page - 1) : nil
137
-
138
- CollectionObject.new(
139
- body.data.broadcast_logs,
140
- next_page: next_page,
141
- prev_page: prev_page,
142
- next_func: -> { room_broadcast_history(options.merge(page: next_page)) },
143
- prev_func: -> { room_broadcast_history(options.merge(page: prev_page)) }
156
+ # @param page [Integer]
157
+ # @param limit [Integer]
158
+ # @return [Qismo::Collection<Qismo::Objects::BroadcastLog>]
159
+ def room_broadcast_history(room_id:, page: 1, limit: 25)
160
+ body = get("/api/v2/customer_rooms/#{room_id}/broadcast_history", {
161
+ page: page,
162
+ limit: limit
163
+ })
164
+
165
+ Qismo::Collection.new(
166
+ Qismo::Objects::BroadcastLog.from_array(body.data.broadcast_logs),
167
+ next_page: ((body.meta.page < body.dig("meta", "total_page")) ? (body.meta.page + 1) : nil),
168
+ prev_page: ((body.meta.page > 1) ? (body.meta.page - 1) : nil)
144
169
  )
145
170
  end
146
171
 
147
- # Assign agent to room
172
+ # Assign an agent to a room
148
173
  #
149
- # @see https://s.id/assign-agent
150
174
  # @param room_id [Integer]
151
175
  # @param agent_id [Integer]
152
- # @param options [Hash]
153
- # @return [Qismo::SingleObject]
154
- def assign_agent(room_id, agent_id, options = {})
155
- body = post("/api/v1/admin/service/assign_agent", options.merge(room_id: room_id.to_s, agent_id: agent_id))
156
- body.data.added_agent
176
+ # @param replace_agents [TrueClass,FalseClass]
177
+ # Replace agents in room or not. Don't combine this param
178
+ # with :max_agent param
179
+ # @param max_agent [Integer]
180
+ # Specify max agent that can be assigned to a room. For
181
+ # example, if there are 1 agent in a room and you specific
182
+ # max_agent to 1, you will get bad request error. If you set
183
+ # param :relpace_agents to true, this param will be forced
184
+ # to nil, which no be sent on http request
185
+ # @return [Qismo::Objects::User]
186
+ def assign_agent(room_id:, agent_id:, replace_agents: false, max_agent: nil)
187
+ Qismo::Objects::User.new(
188
+ post("/api/v1/admin/service/assign_agent", {
189
+ room_id: room_id.to_s,
190
+ agent_id: agent_id,
191
+ replace_latest_agent: replace_agents,
192
+ max_agent: (replace_agents == true) ? nil : max_agent
193
+ }).data.assign_agent
194
+ )
157
195
  end
158
196
 
159
197
  # Remove agent from room
160
198
  #
161
- # @see https://s.id/remove-agent
199
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#7a67e214-28e5-47c1-b4ee-7246977dfcff
162
200
  # @param room_id [Integer]
163
201
  # @param agent_id [Integer]
164
202
  # @return [TrueClass]
165
- def remove_agent(room_id, agent_id)
166
- post("/api/v1/admin/service/remove_agent", room_id: room_id.to_s, agent_id: agent_id)
203
+ def remove_agent(room_id:, agent_id:)
204
+ post(
205
+ "/api/v1/admin/service/remove_agent", {
206
+ room_id: room_id.to_s,
207
+ agent_id: agent_id
208
+ }
209
+ )
210
+
167
211
  true
168
212
  end
169
213
 
170
214
  # Resolve room
171
215
  #
172
- # @see https://s.id/resolve-room
216
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#a1ff75d0-b637-4b79-a259-fb9d084d1659
173
217
  # @param room_id [Integer]
174
218
  # @param last_comment_id [Integer]
175
- # @param options [Hash]
176
- # @return [Qismo::SingleObject]
177
- def resolve_room(room_id, last_comment_id, options = {})
178
- body = post("/api/v1/admin/service/mark_as_resolved",
179
- options.merge(room_id: room_id.to_s, last_comment_id: last_comment_id))
180
- body.data.service
219
+ # Id of last message in the room. If you dont specify this param,
220
+ # we will use current epoc timestamp
221
+ # @param notes [String]
222
+ # Specify room notes. You can also use simple markdown markup
223
+ # for this param
224
+ # @param send_email [TrueClass,FalseClass]
225
+ # Send email to customer or no. This param will only worked if
226
+ # you are using valid email as customer identifier
227
+ # @param extras [Hash]
228
+ # Room extras in valid hash
229
+ # @return [Qismo::Objects::AgentService]
230
+ def resolve_room(room_id:, last_comment_id: Time.now.to_i, notes: nil, send_email: false, extras: nil)
231
+ Qismo::Objects::AgentService.new(
232
+ post("/api/v1/admin/service/mark_as_resolved", {
233
+ room_id: room_id.to_s,
234
+ last_comment_id: last_comment_id,
235
+ notes: notes,
236
+ is_send_email: send_email,
237
+ extras: extras
238
+ }).data.service
239
+ )
181
240
  end
182
241
 
183
242
  alias_method :resolve, :resolve_room
184
243
 
185
244
  # Get agent that can be assigned to room
186
245
  #
187
- # @see https://s.id/allocate-agent
246
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#a62432c6-1aba-4e2b-be9a-2f7151db9119
188
247
  # @param source [String]
189
- # @param options [Hash]
190
- # @return [Qismo::SingleObject]
191
- def allocate_agent(source, options = {})
192
- body = post("/api/v1/admin/service/allocate_agent", options.merge(source: source))
193
- body.data.agent
248
+ # Channel source. Available sources are `wa`, `line`, `telegram`,
249
+ # `qiscus`, `ig`, or `fb`. For custom channel, use that channel's
250
+ # identifier_key as source
251
+ # @param channel_id [Integer]
252
+ # The channel id you want to allocate
253
+ # @param ignore_availability [TrueClass,FalseClass]
254
+ # Ignore agent availability. If you set this param to true, agent
255
+ # that are unavailable will be considered as allocatable too
256
+ # @return [Qismo::Objects::User]
257
+ def allocate_agent(source:, channel_id:, ignore_availability: false)
258
+ Qismo::Objects::User.new(
259
+ post("/api/v1/admin/service/allocate_agent", {
260
+ source: source,
261
+ channel_id: channel_id,
262
+ ignore_availability: ignore_availability
263
+ }).data.agent
264
+ )
194
265
  end
195
266
 
196
267
  # Get agent that can be allocated to room and automatically assign them
197
268
  #
198
- # @see https://s.id/allocate-and-assign-agent
269
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#f88465ed-379f-4202-a8a4-e0c3bebcfeab
199
270
  # @param room_id [Integer]
200
- # @param options [Hash]
201
- # @return [Qismo::SingleObject]
202
- def allocate_and_assign_agent(room_id, options = {})
203
- body = post("/api/v1/admin/service/allocate_assign_agent", options.merge(room_id: room_id))
204
- body.data.agent
271
+ # @param ignore_availability [TrueClass,FalseClass]
272
+ # Ignore agent availability. If you set this param to true, agent
273
+ # that are unavailable will be considered as allocatable too
274
+ # @return [Qismo::Objects::User]
275
+ def allocate_and_assign_agent(room_id:, ignore_availability: false)
276
+ Qismo::Objects::User.new(
277
+ post("/api/v1/admin/service/allocate_assign_agent", {
278
+ room_id: room_id.to_s,
279
+ ignore_availability: ignore_availability
280
+ }).data.agent
281
+ )
205
282
  end
206
283
 
207
284
  # List agents that are not in room and can be assigned to room
208
285
  #
209
- # @see https://s.id/list-other-agents
286
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#10d75d0c-ebd2-44c6-ab19-a0bafe7ad982
210
287
  # @param room_id [Integer]
211
- # @param options [Hash]
212
- # @return [Qismo::CollectionObject]
213
- def other_agents(room_id, options = {})
214
- body = get("/api/v2/admin/service/other_agents", options.merge(room_id: room_id))
215
- CollectionObject.new(
216
- body.data.agents,
217
- prev_page: body.meta&.cursor_before,
218
- next_page: body.meta&.cursor_after,
219
- prev_func: -> { other_agents(options.merge(cursor_before: body.meta&.cursor_before)) },
220
- next_func: -> { other_agents(options.merge(cursor_after: body.meta&.cursor_after)) }
288
+ # @param search [String]
289
+ # @param limit [Integer]
290
+ # @param cursor_after [String]
291
+ # @param cursor_before [String]
292
+ # @return [Qismo::Collection<Qismo::Objects::User>]
293
+ def other_agents(room_id:, search: nil, limit: 15, cursor_after: nil, cursor_before: nil)
294
+ body = get("/api/v2/admin/service/other_agents", {
295
+ room_id: room_id.to_s,
296
+ search: search,
297
+ limit: limit,
298
+ cursor_after: cursor_after,
299
+ cursor_before: cursor_before
300
+ })
301
+
302
+ Collection.new(
303
+ Qismo::Objects::User.from_array(body.data.agents),
304
+ next_page: body.meta.cursor_after,
305
+ prev_page: body.meta.cursor_before
221
306
  )
222
307
  end
223
308
 
224
309
  # List available agents in room
225
310
  #
226
- # @see https://s.id/list-available-agents
311
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#0d5db283-c7f8-42e0-ba02-6cbcbc1d2bb3
227
312
  # @param room_id [Integer]
228
- # @param options [Hash]
229
- # @return [Qismo::CollectionObject]
230
- def available_agents(room_id, options = {})
231
- body = get("/api/v2/admin/service/available_agents", options.merge(room_id: room_id))
232
- CollectionObject.new(
233
- body.data.agents,
234
- prev_page: body.meta&.cursor_before,
235
- next_page: body.meta&.cursor_after,
236
- prev_func: -> { available_agents(options.merge(cursor_before: body.meta&.cursor_before)) },
237
- next_func: -> { available_agents(options.merge(cursor_after: body.meta&.cursor_after)) }
313
+ # @param available_in_room [TrueClass,FalseClass]
314
+ # @param search [String]
315
+ # @param limit [Integer]
316
+ # @param cursor_after [String]
317
+ # @param cursor_before [String]
318
+ # @return [Qismo::Collection<Qismo::Objects::User>]
319
+ def available_agents(room_id:, available_in_room: true, search: nil, limit: 15, cursor_after: nil, cursor_before: nil)
320
+ body = get("/api/v2/admin/service/available_agents", {
321
+ room_id: room_id.to_s,
322
+ is_available_in_room: available_in_room,
323
+ search: search,
324
+ limit: limit,
325
+ cursor_after: cursor_after,
326
+ cursor_before: cursor_before
327
+ })
328
+
329
+ Collection.new(
330
+ Qismo::Objects::User.from_array(body.data.agents),
331
+ next_page: body.meta.cursor_after,
332
+ prev_page: body.meta.cursor_before
238
333
  )
239
334
  end
240
335
 
241
336
  # Get new session webhook config
242
337
  #
243
- # @return [Qismo::SingleObject]
338
+ # @return [Qismo::Objects::Webhook]
244
339
  def new_session_webhook
245
- get("/api/v2/app/config/new_session_webhook").data.configs
340
+ config = get("/api/v2/app/config/new_session_webhook").data.configs
341
+ Qismo::Objects::Webhook.new(
342
+ enabled: config.is_new_session_webhook_enabled,
343
+ url: config.new_session_webhook_url
344
+ )
246
345
  end
247
346
 
248
347
  # Set new session webhook
249
348
  #
250
349
  # @param url [String]
251
- # @param options [Hash]
252
- # @return [Qismo::SingleObject]
253
- def set_new_session_webhook(url, options = {})
254
- post("/api/v2/app/config/new_session_webhook", options.merge(url: url)).data.configs
350
+ # @param enabled [TrueClass,FalseClass]
351
+ # @return [Qismo::Objects::Webhook]
352
+ def set_new_session_webhook(url:, enabled: true)
353
+ config = post("/api/v2/app/config/new_session_webhook", url: url, enabled: enabled).data.configs
354
+ Qismo::Objects::Webhook.new(
355
+ enabled: config.is_new_session_webhook_enabled,
356
+ url: config.new_session_webhook_url
357
+ )
255
358
  end
256
359
 
257
360
  # Get auth webhook config
258
361
  #
259
- # @return [Qismo::SingleObject]
362
+ # @return [Qismo::Objects::Webhook]
260
363
  def auth_webhook
261
- get("/api/v2/app/config/auth_webhook").data.configs
364
+ config = get("/api/v2/app/config/auth_webhook").data.configs
365
+ Qismo::Objects::Webhook.new(
366
+ enabled: config.is_auth_webhook_enabled,
367
+ url: config.auth_webhook_url
368
+ )
262
369
  end
263
370
 
264
371
  # Set auth webhook
265
372
  #
266
373
  # @param url [String]
267
374
  # @param enabled [TrueClass, FalseClass]
268
- # @param options [Hash]
269
- # @return [Qismo::SingleObject]
270
- def set_auth_webhook(url, enabled = true, options = {})
271
- post("/api/v2/app/config/auth_webhook", options.merge(url: url, enabled: enabled)).data.configs
375
+ # @return [Qismo::Objects::Webhook]
376
+ def set_auth_webhook(url:, enabled: true)
377
+ config = post("/api/v2/app/config/auth_webhook", url: url, enabled: enabled).data.configs
378
+ Qismo::Objects::Webhook.new(
379
+ enabled: config.is_auth_webhook_enabled,
380
+ url: config.auth_webhook_url
381
+ )
272
382
  end
273
383
 
274
384
  # Get resolve webhook config
275
385
  #
276
- # @return [Qismo::SingleObject]
386
+ # @return [Qismo::Objects::Webhook]
277
387
  def resolve_webhook
278
- get("/api/v1/app/webhook/mark_as_resolved").data
388
+ config = get("/api/v1/app/webhook/mark_as_resolved").data
389
+ Qismo::Objects::Webhook.new(
390
+ enabled: config.is_mark_as_resolved_webhook_enabled,
391
+ url: config.mark_as_resolved_webhook_url
392
+ )
279
393
  end
280
394
 
281
395
  # Set resolve webhook
282
396
  #
283
397
  # @param url [String]
284
398
  # @param options [Hash]
285
- # @return [Qismo::SingleObject]
286
- def set_resolve_webhook(url, options = {})
287
- post("/api/v1/app/webhook/mark_as_resolved", options.merge(url: url)).data
399
+ # @return [Qismo::Objects::Webhook]
400
+ def set_resolve_webhook(url:, enabled: true)
401
+ config = post("/api/v1/app/webhook/mark_as_resolved", webhook_url: url, is_webhook_enabled: enabled).data
402
+ Qismo::Objects::Webhook.new(
403
+ enabled: config.is_mark_as_resolved_webhook_enabled,
404
+ url: config.mark_as_resolved_webhook_url
405
+ )
288
406
  end
289
407
 
290
408
  # List agents
291
409
  #
292
410
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#849205ca-00d9-4356-9fdd-f05bff777b4e
293
411
  # @param options [Hash]
294
- # @return [Qismo::CollectionObject]
295
- def agents(options = {})
296
- if options[:page].nil? || options[:page].empty?
297
- options[:page] = 1
298
- end
299
-
300
- body = get("/api/v2/admin/agents", options)
412
+ # @return [Qismo::Collection<Qismo::Objects::User>]
413
+ def agents(page: 1, limit: 10, search: nil, scope: nil)
414
+ body = get("/api/v2/admin/agents", {
415
+ page: page,
416
+ limit: limit,
417
+ search: search,
418
+ scope: scope
419
+ })
301
420
 
302
421
  total_page = (body.meta.total_count.to_f / body.meta.per_page.to_f).ceil
303
- next_page = (options[:page] < total_page) ? (options[:page] + 1) : nil
304
- prev_page = (options[:page] > 1) ? (options[:page] - 1) : nil
305
422
 
306
- CollectionObject.new(
307
- body.data.agents,
308
- next_page: next_page,
309
- prev_page: prev_page,
310
- next_func: -> { agents(options.merge(page: next_page)) },
311
- prev_func: -> { agents(options.merge(page: prev_page)) }
423
+ Qismo::Collection.new(
424
+ Qismo::Objects::User.from_array(body.data.agents),
425
+ next_page: ((page < total_page) ? (page + 1) : nil),
426
+ prev_page: ((page > 1) ? (page - 1) : nil)
312
427
  )
313
428
  end
314
429
 
315
- # List agents by id
430
+ # List agents by ids
316
431
  #
317
432
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#3db6c8c8-8ffe-4a88-b630-41f9d5b62298
318
433
  # @param ids [Array<Integer>]
319
- # @return [Qismo::CollectionObject]
320
- def agents_by_ids(ids)
321
- CollectionObject.new(get("/api/v1/admin/agents/get_by_ids", {"ids[]": ids}).data) || CollectionObject.new
434
+ # @return [Qismo::Collection<Qismo::Objects::User>]
435
+ def agents_by_ids(agent_ids:)
436
+ Qismo::Collection.new(
437
+ Qismo::Objects::User.from_array(get("/api/v1/admin/agents/get_by_ids", {"ids[]": agent_ids}).data)
438
+ )
322
439
  end
323
440
 
324
441
  # List agents by divisions
@@ -326,19 +443,20 @@ module Qismo
326
443
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#94eeb9cb-dd70-4baf-9f63-361e7922299a
327
444
  # @param division_ids [Array<Integer>]
328
445
  # @param options [Hash]
329
- # @return [Qismo::CollectionObject]
330
- def agents_by_divisions(division_ids, options = {})
331
- body = get("/api/v2/admin/agents/by_division", options.merge({"division_ids[]": division_ids}))
332
-
333
- next_page = (body.meta.page < body.meta.total_page) ? (body.meta.page + 1) : nil
334
- prev_page = (body.meta.page > 1) ? (body.meta.page - 1) : nil
335
-
336
- CollectionObject.new(
337
- body.data,
338
- next_page: next_page,
339
- prev_page: prev_page,
340
- next_func: -> { agents_by_divisions(options.merge(page: next_page)) },
341
- prev_func: -> { agents_by_divisions(options.merge(page: prev_page)) }
446
+ # @return [Qismo::Collection<Qismo::Objects::User>]
447
+ def agents_by_divisions(division_ids, page: 1, limit: 10, available: nil, sort: "asc")
448
+ body = get("/api/v2/admin/agents/by_division", {
449
+ "division_ids[]": division_ids,
450
+ page: page,
451
+ limit: limit,
452
+ is_available: available,
453
+ sort: sort
454
+ })
455
+
456
+ Qismo::Collection.new(
457
+ Qismo::Objects::User.from_array(body.data),
458
+ next_page: ((body.meta.page < body.meta.total_page) ? (body.meta.page + 1) : nil),
459
+ prev_page: ((body.meta.page > 1) ? (body.meta.page - 1) : nil)
342
460
  )
343
461
  end
344
462
 
@@ -346,54 +464,96 @@ module Qismo
346
464
  #
347
465
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#c6184a6b-ba4d-4f3e-a4da-c6d0fa4597af
348
466
  # @param agent_id [Integer]
349
- # @return [Qismo::SingleObject]
350
- def agent(agent_id)
351
- get("/api/v2/admin/agent/#{agent_id}").data.agent
467
+ # @return [Qismo::Objects::User]
468
+ def agent(agent_id:)
469
+ Qismo::Objects::User.new(get("/api/v2/admin/agent/#{agent_id}").data.agent)
352
470
  end
353
471
 
354
472
  # Get office hour config
355
473
  #
356
474
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#6f3f0cb0-a391-4945-b01a-95ce81138913
357
- # @return [Qismo::SingleObject]
475
+ # @return [Qismo::Objects::OfficeHour]
358
476
  def office_hours
359
- data = get("/api/v1/admin/office_hours").data
360
- data_hash = data.as_json
361
- data_hash["is_in_office_hour"] = Util.in_office_hour?(data)
362
-
363
- SingleObject.new(data_hash)
477
+ Qismo::Objects::OfficeHour.new(
478
+ get("/api/v1/admin/office_hours").data
479
+ )
364
480
  end
365
481
 
366
482
  # List WA broadcast templates
367
483
  #
368
484
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#e38d2244-9559-4015-99d5-8c707f6c01bd
369
485
  # @param options [Hash]
370
- # @return [Qismo::CollectionObject]
371
- def wa_broadcast_templates(options = {})
372
- body = get("/api/v3/admin/hsm", options)
373
-
374
- meta = body.meta
375
- next_page = (meta.page < meta.total_page) ? (meta.page + 1) : nil
376
- prev_page = (meta.page > 1) ? (meta.page - 1) : nil
377
-
378
- CollectionObject.new(
379
- body.data.hsm_templates,
380
- next_page: next_page,
381
- prev_page: prev_page,
382
- next_func: -> { wa_broadcast_templates(options.merge(page: next_page)) },
383
- prev_func: -> { wa_broadcast_templates(options.merge(page: prev_page)) }
486
+ # @return [Qismo::Collection<Qismo::Objects::HsmTemplate>]
487
+ def wa_broadcast_templates(page: 1, limit: 10, approved: nil)
488
+ body = get("/api/v3/admin/hsm", {
489
+ page: page,
490
+ limit: limit,
491
+ approved: approved
492
+ })
493
+
494
+ Qismo::Collection.new(
495
+ Qismo::Objects::HsmTemplate.from_array(body.data.hsm_templates),
496
+ next_page: ((body.meta.page < body.meta.total_page) ? (body.meta.page + 1) : nil),
497
+ prev_page: ((body.meta.page > 1) ? (body.meta.page - 1) : nil)
384
498
  )
385
499
  end
386
500
 
387
501
  alias_method :wa_message_templates, :wa_broadcast_templates
388
502
  alias_method :wa_outbound_templates, :wa_broadcast_templates
389
503
 
504
+ # Get Whatsapp channel credit info
505
+ #
506
+ # @return [Qismo::Objects::WaCreditInfo]
507
+ def wa_credit
508
+ Qismo::Objects::WaCreditInfo.new(
509
+ get("/api/v2/admin/wa_pricing/balance").data
510
+ )
511
+ end
512
+
390
513
  # Send WA outbound message
391
514
  #
392
515
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#d0183cf6-deca-439b-aff3-2e2f007c15a9
393
- # @param options [Hash]
394
- # @return [Qismo::SingleObject]
395
- def send_wa_outbound(options = {})
396
- post("/api/v3/admin/broadcast/client", options).data
516
+ # @param phone_number [String]
517
+ # @param channel_id [Integer]
518
+ # @param template_name [String]
519
+ # @param namespace [String]
520
+ # @param language [String]
521
+ # @param template_detail_id [Integer]
522
+ # @param variables [Array<String>]
523
+ # @param button_params [Array<Hash>]
524
+ # @param header_value [Hash]
525
+ # @return [Qismo::Objects::BroadcastJob]
526
+ def send_wa_outbound(
527
+ phone_number:,
528
+ template_detail_id: nil,
529
+ channel_id: nil,
530
+ template_name: nil,
531
+ namespace: nil,
532
+ language: nil,
533
+ variables: [],
534
+ button_params: nil,
535
+ header_value: nil
536
+ )
537
+ if template_detail_id.nil?
538
+ raise ArgumentError, ":channel_id is required if you dont use :template_detail_id" if channel_id.nil?
539
+ raise ArgumentError, ":template_name is required if you dont use :template_detail_id" if template_name.nil?
540
+ raise ArgumentError, ":namespace is required if you dont use :template_detail_id" if namespace.nil?
541
+ raise ArgumentError, ":language is required if you dont use :template_detail_id" if language.nil?
542
+ end
543
+
544
+ body = post("/api/v3/admin/broadcast/client", {
545
+ phone_number: phone_number,
546
+ template_detail_id: template_detail_id,
547
+ channel_id: channel_id,
548
+ template_name: template_name,
549
+ namespace: namespace,
550
+ language: language,
551
+ variables: variables,
552
+ button_params: button_params,
553
+ header_value: header_value
554
+ })
555
+
556
+ Qismo::Objects::BroadcastJob.new(body.data)
397
557
  end
398
558
 
399
559
  # Upload wa broadcast file that want to be sent in broadcast
@@ -401,41 +561,82 @@ module Qismo
401
561
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#030acde2-21cf-4373-8d11-075206053c1d
402
562
  # @param file [HTTP::FormData]
403
563
  # @param template_detail_id [Integer]
404
- # @return [Qismo::SingleObject]
405
- def upload_wa_broadcast_csv(file, template_detail_id)
564
+ # @return [Integer]
565
+ def upload_wa_broadcast_csv(file:, template_detail_id:, separator: ",")
406
566
  raise ArgumentError, "Invalid file" unless file.is_a?(HTTP::FormData::File)
407
567
 
408
- post_upload("/api/v3/admin/broadcast/upload_csv", file: file, template_detail_id: template_detail_id)
568
+ body = post_upload("/api/v3/admin/broadcast/upload_csv", {
569
+ file: file,
570
+ template_detail_id: template_detail_id,
571
+ separator: separator
572
+ })
573
+
574
+ body.broadcast_file_id
409
575
  end
410
576
 
411
- # Send wa broadcast
577
+ # Send WA broadcast
412
578
  #
413
579
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#717c1a12-facb-4945-aed5-04557696b873
414
- # @param options [Hash]
415
- # @return [Qismo::SingleObject]
416
- def send_wa_broadcast(options = {})
417
- post("/api/v3/admin/broadcast/send_broadcast", options).data.broadcast_job
580
+ # @param file [HTTP::FormData::File,Integer]
581
+ # @param template_detail_id [Integer]
582
+ # @param name [String]
583
+ # @param separator [String]
584
+ # @param started_at [Time]
585
+ # @return [Qismo::Objects::BroadcastJob]
586
+ def send_wa_broadcast(file:, template_detail_id:, name: nil, separator: ",", started_at: nil)
587
+ if name.blank?
588
+ name = default_broadcast_name
589
+ end
590
+
591
+ if started_at.present? && !started_at.is_a?(Time)
592
+ unless started_at.is_a?(Time)
593
+ raise ArgumentError, "You must past :Time class for this parameter"
594
+ end
595
+
596
+ unless started_at.utc_offset == 0
597
+ raise ArgumentError, "You must set your timezone to UTC"
598
+ end
599
+ end
600
+
601
+ file_id = if file.is_a?(HTTP::FormData::File)
602
+ upload_wa_broadcast_csv(file, template_detail_id, separator: separator)
603
+ else
604
+ file.to_i
605
+ end
606
+
607
+ Qismo::Objects::BroadcastJob.new(
608
+ post("/api/v3/admin/broadcast/send_broadcast", {
609
+ broadcast_file_id: file_id,
610
+ name: name,
611
+ separator: separator,
612
+ started_at: started_at,
613
+ template_detail_id: template_detail_id
614
+ }).data.broadcast_job
615
+ )
418
616
  end
419
617
 
420
618
  alias_method :create_wa_broadcast, :send_wa_broadcast
421
619
 
422
- # List wa broadcast jobs
620
+ # List WA broadcast jobs
423
621
  #
424
- # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#3a4caa8b-eef4-427f-adcb-d065989899c9
425
- # @param options [Hash]
426
- # @return [Qismo::CollectionObject]
427
- def wa_broadcast_jobs(options = {})
428
- body = get("/api/v2/admin/broadcast_jobs", options)
429
-
430
- prev_page = (body.meta.page > 1) ? (body.meta.meta - 1) : nil
431
- next_page = (body.meta.page < body.meta.total_page) ? (body.meta.page + 1) : nil
432
-
433
- CollectionObject.new(
434
- body.data.broadcast_jobs,
435
- next_page: next_page,
436
- prev_page: prev_page,
437
- next_func: -> { wa_broadcast_jobs(options.merge(page: next_page)) },
438
- prev_func: -> { wa_broadcast_jobs(options.merge(page: prev_page)) }
622
+ # @param page [Integer]
623
+ # @param limit [Integer]
624
+ # @param cursor_after [Integer]
625
+ # @param cursor_before [Integer]
626
+ # @param name [String]
627
+ # @return [Qismo::Collection<Qismo::Objects::BroadcastJob>]
628
+ def wa_broadcast_jobs(limit: 10, cursor_after: nil, cursor_before: nil, name: nil)
629
+ body = get("/api/v2/admin/broadcast_jobs", {
630
+ limit: limit,
631
+ cursor_after: cursor_after,
632
+ cursor_before: cursor_before,
633
+ name: name
634
+ })
635
+
636
+ Qismo::Collection.new(
637
+ Qismo::Objects::BroadcastJob.from_array(body.data.broadcast_jobs),
638
+ next_page: body.meta.cursor_after,
639
+ prev_page: body.meta.cursor_before
439
640
  )
440
641
  end
441
642
 
@@ -443,9 +644,11 @@ module Qismo
443
644
  #
444
645
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#ed0806c8-2e4a-4ea4-8acb-45c84c63c2da
445
646
  # @param broadcast_job_id [Integer]
446
- # @return [Qismo::SingleObject]
447
- def wa_broadcast_job(broadcast_job_id)
448
- get("/api/v2/admin/broadcast_jobs/#{broadcast_job_id}").data.broadcast_job
647
+ # @return [Qismo::Objects::BroadcastJob]
648
+ def wa_broadcast_job(broadcast_job_id:)
649
+ Qismo::Objects::BroadcastJob.new(
650
+ get("/api/v2/admin/broadcast_jobs/#{broadcast_job_id}").data.broadcast_job
651
+ )
449
652
  end
450
653
 
451
654
  # List wa broadcast logs
@@ -453,30 +656,46 @@ module Qismo
453
656
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#3f2d8ba8-ab14-43b2-af82-74c8b766216f
454
657
  # @param broadcast_job_id [Integer]
455
658
  # @param options [Hash]
456
- # @return [Qismo::CollectionObject]
457
- def wa_broadcast_logs(broadcast_job_id, options = {})
458
- body = get("/api/v2/admin/broadcast_logs/#{broadcast_job_id}", options)
659
+ # @return [Qismo::Collection<Qismo::Objects::BroadcastLog>]
660
+ def wa_broadcast_logs(broadcast_job_id:, page: 1, limit: 10)
661
+ body = get("/api/v2/admin/broadcast_logs/#{broadcast_job_id}", {
662
+ page: page,
663
+ limit: limit
664
+ })
459
665
 
460
666
  prev_page = (body.meta.page > 1) ? (body.meta.meta - 1) : nil
461
667
  next_page = (body.meta.page < body.meta.total_page) ? (body.meta.page + 1) : nil
462
668
 
463
- CollectionObject.new(
464
- body.data.broadcast_logs,
669
+ Qismo::Collection.new(
670
+ Qismo::Objects::BroadcastLog.from_array(body.data.broadcast_logs),
465
671
  next_page: next_page,
466
- prev_page: prev_page,
467
- next_func: -> { wa_broadcast_logs(options.merge(page: next_page)) },
468
- prev_func: -> { wa_broadcast_jobs(options.merge(page: prev_page)) }
672
+ prev_page: prev_page
469
673
  )
470
674
  end
471
675
 
472
676
  # Send message as bot
473
677
  #
474
678
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#bb77c653-5daa-4e1c-a866-43bca7c494fc
475
- # @param options [Hash]
679
+ # @param room_id [Integer]
680
+ # @param message [String]
681
+ # @param type [String]
682
+ # @param payload [Hash]
683
+ # @param extras [Hash]
476
684
  # @return [TrueClass]
477
- def send_bot_message(room_id, options = {})
478
- options = options.merge(room_id: room_id.to_s, sender_email: admin_email)
479
- post("#{app_id}/bot", options)
685
+ def send_bot_message(room_id:, message:, type: "text", payload: {}, extras: {})
686
+ body = post("/#{app_id}/bot", {
687
+ sender_email: admin_email,
688
+ room_id: room_id.to_s,
689
+ message: message,
690
+ type: type,
691
+ payload: payload,
692
+ extras: extras
693
+ })
694
+
695
+ if body != "ok"
696
+ raise Qismo::BadRequestError.new(body.to_s, status_code: 400, response_body: body.to_s)
697
+ end
698
+
480
699
  true
481
700
  end
482
701
 
@@ -485,7 +704,7 @@ module Qismo
485
704
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#494d825f-a49c-4b18-954e-eaaccb738bcd
486
705
  # @param room_id [Integer]
487
706
  # @return [TrueClass]
488
- def enable_bot_in_room(room_id)
707
+ def enable_bot_in_room(room_id:)
489
708
  post("/bot/#{room_id}/activate", is_active: true)
490
709
  true
491
710
  end
@@ -495,7 +714,7 @@ module Qismo
495
714
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#494d825f-a49c-4b18-954e-eaaccb738bcd
496
715
  # @param room_id [Integer]
497
716
  # @return [TrueClass]
498
- def disable_bot_in_room(room_id)
717
+ def disable_bot_in_room(room_id:)
499
718
  post("/bot/#{room_id}/activate", is_active: false)
500
719
  true
501
720
  end
@@ -505,20 +724,40 @@ module Qismo
505
724
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#40867e85-7412-4e0d-84bd-e2506df23df8
506
725
  # @param room_id [Integer]
507
726
  # @return [TrueClass]
508
- def handover_room_from_bot(room_id)
509
- post("/#{app_id}/bot/#{room_id}/hand_over")
727
+ def handover_room_from_bot(room_id:)
728
+ request(:post, "/#{app_id}/bot/#{room_id}/hand_over", headers: {
729
+ Authorization: secret_key
730
+ })
731
+
510
732
  true
511
733
  end
512
734
 
513
735
  # Handover room from chatbot to human agent in specific divisions
514
736
  #
515
- # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#8218db08-9753-4d74-ae5f-0ee62f8579b9
737
+ # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#8218db08-9753-4d74-ae5f-0ee62f8579b9# <Description>
738
+ #
516
739
  # @param room_id [Integer]
517
- # @param roles [Array<Integer>]
518
- # @param options [Hash]
519
- # @return [TrueClass]
520
- def handover_room_from_bot_to_division(room_id, roles, options = {})
521
- post("/#{app_id}/bot/#{room_id}/hand_over_to_role", options.merge(roles: roles))
740
+ # @param roles [Integer,Array<Integer>]
741
+ # @param find_online_agent [TrueClass,FalseClass]
742
+ # @return [TrueClass,FalseClass]
743
+ def handover_room_from_bot_to_division(room_id:, roles:, find_online_agent: true)
744
+ options = {}
745
+ options[:room_id] = room_id.to_s
746
+ options[:find_online_agent] = find_online_agent
747
+
748
+ if roles.is_a?(Array)
749
+ options[:roles] = roles
750
+ else
751
+ options[:role] = roles
752
+ end
753
+
754
+ request(
755
+ :post,
756
+ "/#{app_id}/bot/#{room_id}/hand_over_to_role",
757
+ headers: {Authorization: secret_key},
758
+ json: options
759
+ )
760
+
522
761
  true
523
762
  end
524
763
 
@@ -527,95 +766,88 @@ module Qismo
527
766
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#d5a555de-59e0-4705-9582-c216d79e9390
528
767
  # @param user_id [String]
529
768
  # @param name [String]
530
- # @param options [Hash]
531
- # @return [Qismo::SingleObject]
532
- def initiate_widget_chat(user_id, name, options = {})
533
- options = options.merge(app_id: app_id, user_id: user_id, name: name)
534
- post("/api/v2/qiscus/initiate_chat", options).data.customer_room
769
+ # @param nonce [String]
770
+ # @param channel_id [Integer]
771
+ # @param extras [Hash]
772
+ # @param reset_extras [TrueClass,FalseClass]
773
+ # @param room_badge [String]
774
+ # @param avatar [String]
775
+ # @param allocate_agent [TrueClass,FalseClass]
776
+ # @param user_properties [Hash]
777
+ # @param sdk_user_extras [Hash]
778
+ # @param timezone_offset [String]
779
+ # @param notes [String]
780
+ # @param phone_number [String]
781
+ # @param email [String]
782
+ # @return [Qismo::Objects::CustomerRoom]
783
+ def initiate_widget_chat(user_id:, name:, nonce: nil, channel_id: nil, extras: nil, reset_extras: false, room_badge: nil, avatar: nil, allocate_agent: nil, user_properties: nil, sdk_user_extras: nil, timezone_offset: nil, notes: nil, phone_number: nil, email: nil)
784
+ options = {
785
+ user_id: user_id,
786
+ name: name,
787
+ nonce: nonce,
788
+ channel_id: channel_id,
789
+ extras: extras,
790
+ reset_extras: reset_extras,
791
+ room_badge: room_badge,
792
+ avatar: avatar,
793
+ allocate_agent: allocate_agent,
794
+ user_properties: user_properties,
795
+ sdk_user_extras: sdk_user_extras,
796
+ timezone_offset: timezone_offset,
797
+ notes: notes,
798
+ phone_number: phone_number,
799
+ email: email
800
+ }.compact
801
+
802
+ Qismo::Objects::CustomerRoom.new(post("/api/v2/qiscus/initiate_chat", options).data.customer_room)
535
803
  end
536
804
 
537
805
  alias_method :initiate_chat, :initiate_widget_chat
538
806
 
539
- # Send message to custom channel
807
+ # Send messsage to custom channel
540
808
  #
541
809
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#aee54b21-68f1-4d31-9d81-d3c73b3e125b
542
810
  # @param identifier_key [String]
543
811
  # @param user_id [String]
544
812
  # @param name [String]
545
- # @param options [Hash]
546
- # @return [Qismo::SingleObject]
547
- def send_message_to_custom_channel(identifier_key, user_id, name, options = {})
548
- post("/#{app_id}/api/v2/custom_channel/send",
549
- options.merge(identifier_key: identifier_key, user_id: user_id, name: name)).data
813
+ # @param message [String]
814
+ # @param avatar [String]
815
+ # @param type [String]
816
+ # @param payload [Hash]
817
+ # @param extras [Hash]
818
+ # @return [Qismo::Objects::CustomChannelMessageResponse]
819
+ def send_message_to_custom_channel(
820
+ identifier_key:,
821
+ user_id:,
822
+ name:,
823
+ message:,
824
+ avatar: nil,
825
+ type: "text",
826
+ payload: {},
827
+ extras: {}
828
+ )
829
+ Qismo::Objects::CustomChannelMessageResponse.new(
830
+ post("/#{app_id}/api/v2/custom_channel/send", {
831
+ identifier_key: identifier_key,
832
+ user_id: user_id,
833
+ name: name,
834
+ message: message,
835
+ avatar: avatar,
836
+ type: type,
837
+ payload: payload,
838
+ extras: extras
839
+ }).data
840
+ )
550
841
  end
551
842
 
552
843
  # List integrated channels
553
844
  #
554
845
  # @see https://documenter.getpostman.com/view/8259884/TVsuCSeT#aee54b21-68f1-4d31-9d81-d3c73b3e125b
555
- # @return [Qismo::SingleObject]
846
+ # @return [Qismo::Objects::ListChannelsResponse]
556
847
  def channels
557
- get("/api/v2/channels").data
558
- end
559
-
560
- # Create customchannel
561
- #
562
- # @param identifier_key [String]
563
- # @param name [String]
564
- # @param webhook_url [String]
565
- # @param options [Hash]
566
- # @return [Qismo::SingleObject]
567
- def create_custom_channel(identifier_key, name, webhook_url, options = {})
568
- options = options.merge(
569
- identifier_key: identifier_key,
570
- name: name,
571
- webhook_url: webhook_url
848
+ Qismo::Objects::ListChannelsResponse.new(
849
+ get("/api/v2/channels").data
572
850
  )
573
-
574
- options[:is_active] = true unless options[:is_active].nil?
575
-
576
- post("/api/v1/custom_channel/connect", options.merge).data
577
- end
578
-
579
- # Update custom channel
580
- #
581
- # @param id [Integer]
582
- # @param options [Hash]
583
- # @return [Qismo::SingleObject]
584
- def update_custom_channel(id, options = {})
585
- channel = channels.custom_channels.find { |cc| cc.id == id }
586
- if channel.nil?
587
- raise Qismo::NotFoundError.new("Channel not found", status_code: 404, response_body: nil)
588
- end
589
-
590
- channel_hash = JSON.parse(channel.to_json, symbolize_names: true)
591
- new_channel_config = channel_hash.merge(options)
592
-
593
- post("/api/v1/custom_channel/connect/update", new_channel_config).data
594
- end
595
-
596
- # Activate custom channel
597
- #
598
- # @param id [Integer]
599
- # @return [Qismo::SingleObject]
600
- def activate_custom_channel(id)
601
- update_custom_channel(id, is_active: true)
602
- end
603
-
604
- # Deactivate custom channel
605
- #
606
- # @param id [Integer]
607
- # @return [Qismo::SingleObject]
608
- def deactivate_custom_channel(id)
609
- update_custom_channel(id, is_active: false)
610
- end
611
-
612
- # Delete custom channel
613
- #
614
- # @param id [Integer]
615
- # @return [TrueClass]
616
- def delete_custom_channel(id)
617
- post("/api/v2/custom_channel/connect/#{id}/delete")
618
- true
619
851
  end
620
852
  end
621
853
  end