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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb55e3c23efa55080a8c65449b619f5d1016d9f3ef72b0692413654687e98e38
4
- data.tar.gz: 610b16a6507bd54a017602146ce5866111e0bb89a0c36f491ec1898057ffb51d
3
+ metadata.gz: bbb77849305f7812a453eefbea9e5f288ede162774aadb8f638760ae6349b519
4
+ data.tar.gz: e5f4fd6c8bbae34bc30707cd08f629ac32932b20f10a73307edd8689707ab532
5
5
  SHA512:
6
- metadata.gz: 522f77e9e507001a0e6f07834c0e048c88716a93f810a8cdff7dafb38bb31d8faa50d4d2165878468fdbe3ab13bbc7916a63509293e798da99bd4c73582115ae
7
- data.tar.gz: 76e9cead4064ad7f28c3b04144976356c1f46d62f11ec71029820d1043c9e728f71980c389e52be4d215cdd36916652de43544bc56f23ca62ce6362d36866e48
6
+ metadata.gz: 292760f08f8b16bf5093916564ee4ea0e3f641c7e51ca4c0e65aa6a54bbb3e67a83204a1b087a9e60d7fdcfd5dbced2179e6334b783f87e0570fae5f8f762b1d
7
+ data.tar.gz: 5af35068e56009c635b0e43af48c2b51517095c610e29ea3d353f5519d4ed29935cee99158cf88a896945607f4c215895037e682c06e39dd45ec90863ef1f234
data/Gemfile CHANGED
@@ -10,6 +10,5 @@ group :development do
10
10
  gem "byebug", "~> 11.1"
11
11
  gem "rake", "~> 13.0"
12
12
  gem "rspec", "~> 3.0"
13
- gem "solargraph", "~> 0.47.2"
14
13
  gem "standard", ">= 1"
15
14
  end
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 = "YOU_ACCOUNT_APP_ID"
22
- client.secret_key = "YOUR_ACCOUNT_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 any endpoint yg want
24
+ Then, start requesting to available endpoint
34
25
 
35
26
  ```ruby
36
27
  params = {
37
- channel: { id: 12345, source: "wa" },
28
+ channel: { channel_id: 12345, source: "wa" },
38
29
  status: "unresolved",
39
30
  serve_status: "served",
40
- is_handled_by_bot: false,
31
+ is_handled_by_bot: true,
41
32
  }
42
33
 
34
+ # List rooms
43
35
  rooms = Qismo.rooms(params)
44
- ```
45
36
 
46
- If your app manage multiple app id, you initialize the client like below
47
-
48
- ```ruby
49
- client = Qismo::Client.new(app_id: "YOUR_ACCOUNT_APP_ID", secret_key: "YOUR_ACCOUNT_SECRET_KEY")
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
- Then, start requesting to an endpoint using that `client` variable
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: { id: 12345, source: "wa" },
69
+ channel: { channel_id: 12345, source: "wa" },
57
70
  status: "unresolved",
58
71
  serve_status: "served",
59
- is_handled_by_bot: false,
72
+ is_handled_by_bot: true,
60
73
  }
61
74
 
62
- rooms = client.rooms(params)
75
+ # This will produce same result as explained before
76
+ client.rooms(params)
63
77
  ```
64
78
 
65
- ### Client configuration
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
- ### Handling pagination
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
- ### Handling error
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
+ ```