qismo 0.12.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +128 -28
- data/lib/qismo/api.rb +482 -249
- data/lib/qismo/client.rb +33 -19
- data/lib/qismo/collection.rb +19 -0
- data/lib/qismo/object.rb +19 -0
- data/lib/qismo/objectified_hash.rb +25 -0
- data/lib/qismo/objects/agent_service.rb +49 -0
- data/lib/qismo/objects/broadcast_job.rb +95 -0
- data/lib/qismo/objects/broadcast_log.rb +57 -0
- data/lib/qismo/objects/custom_channel_message_response.rb +17 -0
- data/lib/qismo/objects/customer_room.rb +83 -0
- data/lib/qismo/objects/hsm_template.rb +105 -0
- data/lib/qismo/objects/office_hour.rb +63 -0
- data/lib/qismo/objects/room_additional_info.rb +13 -0
- data/lib/qismo/objects/tag.rb +25 -0
- data/lib/qismo/objects/user.rb +93 -0
- data/lib/qismo/objects/wa_credit_info.rb +65 -0
- data/lib/qismo/objects/webhook.rb +13 -0
- data/lib/qismo/types.rb +10 -0
- data/lib/qismo/version.rb +1 -1
- data/lib/qismo/webhook_requests/on_agent_allocation_needed.rb +75 -0
- data/lib/qismo/webhook_requests/on_custom_button_clicked.rb +86 -0
- data/lib/qismo/webhook_requests/on_custom_channel_message_sent.rb +95 -0
- data/lib/qismo/webhook_requests/on_message_for_bot_sent.rb +95 -0
- data/lib/qismo/webhook_requests/on_new_session_initiated.rb +170 -0
- data/lib/qismo/webhook_requests/on_room_resolved.rb +81 -0
- data/lib/qismo.rb +27 -32
- data/qismo.gemspec +2 -0
- metadata +52 -4
- data/lib/qismo/model.rb +0 -102
- data/lib/qismo/util.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbb77849305f7812a453eefbea9e5f288ede162774aadb8f638760ae6349b519
|
4
|
+
data.tar.gz: e5f4fd6c8bbae34bc30707cd08f629ac32932b20f10a73307edd8689707ab532
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 292760f08f8b16bf5093916564ee4ea0e3f641c7e51ca4c0e65aa6a54bbb3e67a83204a1b087a9e60d7fdcfd5dbced2179e6334b783f87e0570fae5f8f762b1d
|
7
|
+
data.tar.gz: 5af35068e56009c635b0e43af48c2b51517095c610e29ea3d353f5519d4ed29935cee99158cf88a896945607f4c215895037e682c06e39dd45ec90863ef1f234
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -12,57 +12,73 @@ bundle add qismo
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
-
### Initialize and make request
|
16
|
-
|
17
|
-
To start using Qismo ruby, you must get your account's `App ID` and `Qiscus Secret Key` which can be checked in your admin dashboard's [settings page](https://omnichannel.qiscus.com/settings). After getting these data, you can start initialize the client.
|
18
|
-
|
19
15
|
```ruby
|
16
|
+
# config/initializers/qismo.rb
|
17
|
+
|
20
18
|
Qismo.configure do |client|
|
21
|
-
client.app_id = "
|
22
|
-
client.secret_key = "
|
23
|
-
|
24
|
-
## Optional
|
25
|
-
client.url = "https://qismo.qiscus.com"
|
26
|
-
client.logger = { logger: Logger.new($stdout) }
|
27
|
-
client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }
|
28
|
-
client.timeout = { connect: 5, write: 2, read: 5 }
|
29
|
-
client.proxy = ["proxy-hostname.local", 8080, "username", "password"]
|
19
|
+
client.app_id = ENV["QISCUS_APP_ID"]
|
20
|
+
client.secret_key = ENV["QISCUS_SECRET_KEY"]
|
30
21
|
end
|
31
22
|
```
|
32
23
|
|
33
|
-
Then, start requesting to
|
24
|
+
Then, start requesting to available endpoint
|
34
25
|
|
35
26
|
```ruby
|
36
27
|
params = {
|
37
|
-
channel: {
|
28
|
+
channel: { channel_id: 12345, source: "wa" },
|
38
29
|
status: "unresolved",
|
39
30
|
serve_status: "served",
|
40
|
-
is_handled_by_bot:
|
31
|
+
is_handled_by_bot: true,
|
41
32
|
}
|
42
33
|
|
34
|
+
# List rooms
|
43
35
|
rooms = Qismo.rooms(params)
|
44
|
-
```
|
45
36
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
37
|
+
puts rooms
|
38
|
+
# [
|
39
|
+
# #<Qismo::SingleObject
|
40
|
+
# channel_id=6171,
|
41
|
+
# contact_id=71716,
|
42
|
+
# id=181917,
|
43
|
+
# is_handled_by_bot=true,
|
44
|
+
# is_resolved=false,
|
45
|
+
# is_waiting=false,
|
46
|
+
# last_comment_sender="admin@qismo.com",
|
47
|
+
# last_comment_sender_type="system",
|
48
|
+
# last_comment_text="Agent joined this conversation",
|
49
|
+
# last_comment_timestamp="2022-12-09T04:25:55Z",
|
50
|
+
# last_customer_comment_text=nil,
|
51
|
+
# last_customer_timestamp="2022-11-28T09:03:08Z",
|
52
|
+
# name="Customer - Yogyakarta",
|
53
|
+
# room_badge="https://multichannel.qiscus.com/img/whatsapp_badge.svg",
|
54
|
+
# room_id="8191816171",
|
55
|
+
# room_type="individual",
|
56
|
+
# source="wa",
|
57
|
+
# user_avatar_url="https://multichannel.qiscus.com/img/default_avatar.svg",
|
58
|
+
# user_id="628155555711"
|
59
|
+
# >
|
60
|
+
# ]
|
50
61
|
```
|
51
62
|
|
52
|
-
|
63
|
+
## Multiple app id client initialization
|
53
64
|
|
54
65
|
```ruby
|
66
|
+
client = Qismo::Client.new(app_id: "QISCUS_APP_ID", secret_key: "QISCUS_SECRET_KEY")
|
67
|
+
|
55
68
|
params = {
|
56
|
-
channel: {
|
69
|
+
channel: { channel_id: 12345, source: "wa" },
|
57
70
|
status: "unresolved",
|
58
71
|
serve_status: "served",
|
59
|
-
is_handled_by_bot:
|
72
|
+
is_handled_by_bot: true,
|
60
73
|
}
|
61
74
|
|
62
|
-
|
75
|
+
# This will produce same result as explained before
|
76
|
+
client.rooms(params)
|
63
77
|
```
|
64
78
|
|
65
|
-
|
79
|
+
## Client optional configuration
|
80
|
+
|
81
|
+
Qismo ruby also provide some optional configuration that you can pass, they are:
|
66
82
|
|
67
83
|
**url**
|
68
84
|
|
@@ -130,7 +146,7 @@ Proxy needs authentication?
|
|
130
146
|
client.proxy = ["proxy-hostname.local", 8080, "username", "password"]
|
131
147
|
```
|
132
148
|
|
133
|
-
|
149
|
+
## Handling pagination
|
134
150
|
|
135
151
|
Some of the Qiscus Omnichannel API will return list of data with pagination. To handle the pagination, you can to that like this example:
|
136
152
|
|
@@ -145,7 +161,7 @@ while rooms.has_next_page?
|
|
145
161
|
end
|
146
162
|
```
|
147
163
|
|
148
|
-
|
164
|
+
## Handling error
|
149
165
|
|
150
166
|
Qismo ruby raise error while getting non successful http code from Qiscus Omnichannel API. To handle it, you follow this example:
|
151
167
|
|
@@ -158,3 +174,87 @@ rescue Qismo::HTTPRequestError => e
|
|
158
174
|
e.response_body
|
159
175
|
end
|
160
176
|
```
|
177
|
+
|
178
|
+
## Handle incoming webhook request
|
179
|
+
|
180
|
+
Qiscus Omnichannel provide webhooks that triggered from various action on your account. Qismo ruby gem provide convenient way to handle the request.
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
class QiscusWebhooksController < ApplicationController
|
184
|
+
skip_before_action :verify_authenticity_token
|
185
|
+
|
186
|
+
def handle_agent_allocation_webhook
|
187
|
+
webhook = Qismo::WebhookRequests::OnAgentAllocationNeeded.new(JSON.parse(request.raw_body))
|
188
|
+
|
189
|
+
# Do any action you want using payload that has been objectified
|
190
|
+
if webhook.candidate_agent.present?
|
191
|
+
Qismo.assign_agent(
|
192
|
+
webhook.room_id,
|
193
|
+
webhook.candidate_agent.id
|
194
|
+
)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def handle_custom_button_webhook
|
199
|
+
webhook = Qismo::WebhookRequests::OnCustomButtonClicked.new(JSON.parse(request.raw_body))
|
200
|
+
|
201
|
+
# Do any action you want using payload that has been objectified. The
|
202
|
+
# following example assuming you want to create Zendesk ticket
|
203
|
+
# everytime your agent click custom button "Create Ticket". We are
|
204
|
+
# assuming, you have setup Zendesk ruby client
|
205
|
+
zendesk_ticket_subject = webhook.additional_info.find do |info|
|
206
|
+
info.key == "Zendesk Ticket Subject"
|
207
|
+
end
|
208
|
+
|
209
|
+
if zendesk_ticket_subject.present?
|
210
|
+
ZendeskAPI::Ticket.create!(
|
211
|
+
zendesk_client,
|
212
|
+
subject: zendesk_ticket_subject.value,
|
213
|
+
submitter_id: webhook.agent.email,
|
214
|
+
priority: "urgent"
|
215
|
+
)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def handle_custom_channel_webhook
|
220
|
+
webhook = Qismo::WebhookRequests::OnCustomChannelMessageSent.new(JSON.parse(request.raw_body))
|
221
|
+
|
222
|
+
# Do any action you want
|
223
|
+
# The following example assuming you want to reply customer's message from Twitter
|
224
|
+
# Assuming that you have installed and setup twitter ruby client
|
225
|
+
|
226
|
+
# Fetch customer from room participants
|
227
|
+
customer = webhook.payload.room.participants.find { |participant| participant.email.start_with?("twitter_customer_") }
|
228
|
+
if customer.present?
|
229
|
+
twitter_rest_client.create_direct_message(webhook.payload.rooms, webhook.payload.message.text)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def handle_bot_webhook
|
234
|
+
webhook = Qismo::WebhookRequests::OnMessageForBotSent.new(JSON.parse(request.raw_body))
|
235
|
+
|
236
|
+
# Do any action you want. The following example assuming you want to use
|
237
|
+
# Dialogflow as bot engine
|
238
|
+
|
239
|
+
# Detect intent for customer's message
|
240
|
+
response = dialogflow_client.detect_intent(
|
241
|
+
session: "session_#{webhook.payload.room.id}",
|
242
|
+
query_input: {
|
243
|
+
text: {
|
244
|
+
text: webhook.payload.message.text,
|
245
|
+
language_code: "en-US"
|
246
|
+
}
|
247
|
+
}
|
248
|
+
)
|
249
|
+
|
250
|
+
# Parse bot message which will be sent back to customer
|
251
|
+
bot_message = response.query_result.fulfillment_text
|
252
|
+
|
253
|
+
# Send message to Qismo room
|
254
|
+
Qismo.send_bot_message(
|
255
|
+
webhook.payload.room.id,
|
256
|
+
message: bot_message
|
257
|
+
)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
```
|