qismo 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -17
- data/lib/qismo/api.rb +2 -0
- data/lib/qismo/client.rb +73 -35
- data/lib/qismo/version.rb +1 -1
- data/qismo.gemspec +0 -1
- data/vscode-snippet/qismo.code-snippets +100 -16
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a49672ff24211ad4828574e849c42e85022b9f316e149a6a20e13514e86d512
|
4
|
+
data.tar.gz: 854c58aea3339b1f9766eb4465861ecbced5a0f6ec6a05c73fde4404a1109b0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f525de18bd21459e091056bd3c19053bc3fbad5597b59b78824f2f55c322e195106d3ef4e06916e43831321fad6842c937d3852d25ad3fe61a179ad90c3d316
|
7
|
+
data.tar.gz: d1be120b5b9643e094ce0fb94d2dd27ca25dacd9a6f60ba30cb179d34d6a55e5cc09e14764bef4bd7d8240989f8c4992424bae7feccdcaae231c9205ba74ab5b
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ bundle add qismo
|
|
13
13
|
## Usage
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
|
16
|
+
qismo = Qismo::Client.new(app_id: "QISCUS_APP_ID", secret_key: "QISCUS_SECRET_KEY")
|
17
17
|
|
18
18
|
params = {
|
19
19
|
channel: [{ channel_id: 12345, source: "wa" }],
|
@@ -22,7 +22,7 @@ params = {
|
|
22
22
|
is_handled_by_bot: true,
|
23
23
|
}
|
24
24
|
|
25
|
-
pp
|
25
|
+
pp qismo.list_rooms(params)
|
26
26
|
|
27
27
|
# [
|
28
28
|
# #<Qismo::Objects::CustomerRoom
|
@@ -57,7 +57,7 @@ Qismo ruby also provide some optional configuration that you can pass, they are:
|
|
57
57
|
Defaultly, Qismo ruby will use your QISCUS_OMNICHANNEL_URL env as base url. If its nil, it will use https://qismo.qiscus.com. If you need to customize URL other than that, you can pass it at client initialization
|
58
58
|
|
59
59
|
```ruby
|
60
|
-
|
60
|
+
qismo.url = "https://qismo.qiscus.com"
|
61
61
|
```
|
62
62
|
|
63
63
|
**logger**
|
@@ -67,7 +67,7 @@ You can also log the request and response the any HTTP request you make in Qismo
|
|
67
67
|
```ruby
|
68
68
|
require "logger"
|
69
69
|
|
70
|
-
|
70
|
+
qismo.logger = Logger.new($stdout)
|
71
71
|
```
|
72
72
|
|
73
73
|
**instrumentation**
|
@@ -79,13 +79,13 @@ ActiveSupport::Notifications.subscribe('start_request.http') do |name, start, fi
|
|
79
79
|
pp name: name, start: start.to_f, finish: finish.to_f, id: id, payload: payload
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
qismo.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }
|
83
83
|
```
|
84
84
|
|
85
85
|
You can also customize the instrumentation's namespace by using this configuration
|
86
86
|
|
87
87
|
```ruby
|
88
|
-
|
88
|
+
qismo.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter, namespace: "qiscus.http_request" }
|
89
89
|
```
|
90
90
|
|
91
91
|
**timeout**
|
@@ -95,13 +95,13 @@ By default, the Qismo ruby gem does not enforce timeout on a request. You can en
|
|
95
95
|
Per operation timeouts are what `Net::HTTP` and the majority of HTTP clients do:
|
96
96
|
|
97
97
|
```ruby
|
98
|
-
|
98
|
+
qismo.timeout = { connect: 5, write: 2, read: 10 }
|
99
99
|
```
|
100
100
|
|
101
101
|
Global timeouts let you set an upper bound of how long a request can take
|
102
102
|
|
103
103
|
```ruby
|
104
|
-
|
104
|
+
qismo.timeout = 5 # in seconds
|
105
105
|
```
|
106
106
|
|
107
107
|
**proxy**
|
@@ -109,13 +109,13 @@ client.timeout = 5 # in seconds
|
|
109
109
|
Making request behind proxy is as simple as making them directly. Just specify hostname (or IP address) of your proxy server and its port, and here you go
|
110
110
|
|
111
111
|
```ruby
|
112
|
-
|
112
|
+
qismo.proxy = ["proxy-hostname.local", 8080]
|
113
113
|
```
|
114
114
|
|
115
115
|
Proxy needs authentication?
|
116
116
|
|
117
117
|
```ruby
|
118
|
-
|
118
|
+
qismo.proxy = ["proxy-hostname.local", 8080, "username", "password"]
|
119
119
|
```
|
120
120
|
|
121
121
|
## Handling pagination
|
@@ -126,11 +126,11 @@ Some of the Qiscus Omnichannel API will return list of data with pagination. To
|
|
126
126
|
|
127
127
|
all_rooms = []
|
128
128
|
|
129
|
-
rooms =
|
129
|
+
rooms = qismo.list_rooms
|
130
130
|
all_rooms.append(rooms)
|
131
131
|
|
132
132
|
while rooms.next_page.present?
|
133
|
-
rooms =
|
133
|
+
rooms = qismo.list_rooms(cursor_after: rooms.next_page)
|
134
134
|
all_rooms.append(rooms)
|
135
135
|
end
|
136
136
|
```
|
@@ -141,7 +141,7 @@ Qismo ruby raise error while getting non successful http code from Qiscus Omnich
|
|
141
141
|
|
142
142
|
```ruby
|
143
143
|
begin
|
144
|
-
|
144
|
+
qismo.list_rooms
|
145
145
|
rescue Qismo::BadRequestError => e
|
146
146
|
puts e.message
|
147
147
|
puts e.status_code
|
@@ -186,8 +186,8 @@ class QiscusWebhooksController < ApplicationController
|
|
186
186
|
|
187
187
|
# Do any action you want using payload that has been objectified
|
188
188
|
if webhook.candidate_agent.present?
|
189
|
-
|
190
|
-
|
189
|
+
qismo = Qismo::Client.new(app_id: "", secret_key: "")
|
190
|
+
qismo.assign_agent(
|
191
191
|
room_id: webhook.room_id,
|
192
192
|
agent_id: webhook.candidate_agent.id
|
193
193
|
)
|
@@ -250,11 +250,13 @@ class QiscusWebhooksController < ApplicationController
|
|
250
250
|
bot_message = response.query_result.fulfillment_text
|
251
251
|
|
252
252
|
# Send message to Qismo room
|
253
|
-
|
254
|
-
|
253
|
+
qismo = Qismo::Client.new(app_id: "", secret_key: "")
|
254
|
+
qismo.send_bot_message(
|
255
255
|
room_id: webhook.payload.room.id,
|
256
256
|
message: bot_message
|
257
257
|
)
|
258
258
|
end
|
259
259
|
end
|
260
260
|
```
|
261
|
+
## Developer Experience
|
262
|
+
> TODO documentation
|
data/lib/qismo/api.rb
CHANGED
data/lib/qismo/client.rb
CHANGED
@@ -1,43 +1,90 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "logger"
|
4
|
+
|
3
5
|
module Qismo
|
4
6
|
# Qismo ruby client
|
5
7
|
#
|
6
8
|
class Client
|
7
9
|
include Qismo::Api
|
8
10
|
|
9
|
-
# @return [String
|
11
|
+
# @return [String]
|
10
12
|
DEFAULT_APP_ID = ENV["QISCUS_APP_ID"]
|
11
13
|
|
12
|
-
# @return [String
|
14
|
+
# @return [String]
|
13
15
|
DEFAULT_SECRET_KEY = ENV["QISCUS_SECRET_KEY"]
|
14
16
|
|
15
17
|
# @return [String]
|
16
|
-
DEFAULT_URL = ENV["QISCUS_OMNICHANNEL_URL"] || "https://
|
18
|
+
DEFAULT_URL = (ENV["QISCUS_OMNICHANNEL_URL"] || "https://multichannel.qiscus.com")
|
17
19
|
|
18
|
-
# @return [
|
19
|
-
|
20
|
+
# @return [String]
|
21
|
+
attr_accessor :app_id
|
22
|
+
|
23
|
+
# @return [String]
|
24
|
+
attr_accessor :secret_key
|
25
|
+
|
26
|
+
# @return [Addressable::URI]
|
27
|
+
attr_accessor :url
|
28
|
+
|
29
|
+
# @return [Logger]
|
30
|
+
attr_accessor :logger
|
31
|
+
|
32
|
+
# @return [ActiveSupport::Notifications::Instrumenter]
|
33
|
+
attr_accessor :instrumentation
|
34
|
+
|
35
|
+
# @return [Integer,Hash]
|
36
|
+
attr_accessor :timeout
|
37
|
+
|
38
|
+
# @return [Array<String,Integer>]
|
39
|
+
attr_accessor :proxy
|
40
|
+
|
41
|
+
# @return [String,Proc]
|
42
|
+
attr_accessor :admin_email
|
43
|
+
|
44
|
+
# Initiate Qismo Ruby client
|
45
|
+
#
|
46
|
+
# @param app_id [String]
|
47
|
+
# Your account's app id. Can be checked in Qiscus Omnichannel dashboard.
|
48
|
+
# We will use ENV["QISCUS_APP_ID"] value as default value.
|
49
|
+
# @param secret_key [String]
|
50
|
+
# Your account's secret key. Can be checked in Qiscus Omnichannel dashboard.
|
51
|
+
# We will use ENV["QISCUS_SECRET_KEY"] value as default value.
|
52
|
+
# @param url [String]
|
53
|
+
# Custom base url for Qiscus Omnichannel client.
|
54
|
+
# We will use ENV["QISCUS_OMNICHANNEL_URL"] value as default value.
|
55
|
+
# If its not provided, we will use https://multichannel.qiscus.com as default value
|
56
|
+
# @param logger [Logger]
|
57
|
+
# Http client logging. Default is nil
|
58
|
+
# @param instrumentation [ActiveSupport::Notifications::Instrumenter]
|
59
|
+
# Http client instrumenter. Use ActiveSupport Instrumenter
|
60
|
+
# @param timeout [Integer, Hash]
|
61
|
+
# Http client timout. Default is 5 seconds
|
62
|
+
# @param proxy [Array<String,Integer>]
|
63
|
+
# Http client proxy
|
64
|
+
# @param admin_email [String,Proc]
|
65
|
+
# Your account's admin email. Can be checked in Qiscus Omnichannel dashboard
|
66
|
+
def initialize(
|
20
67
|
app_id: DEFAULT_APP_ID,
|
21
68
|
secret_key: DEFAULT_SECRET_KEY,
|
22
69
|
url: DEFAULT_URL,
|
23
70
|
logger: nil,
|
24
71
|
instrumentation: nil,
|
25
|
-
timeout:
|
26
|
-
proxy: nil
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@admin_email = "#{@app_id}_admin@qismo.com"
|
72
|
+
timeout: 5,
|
73
|
+
proxy: nil,
|
74
|
+
admin_email: nil
|
75
|
+
)
|
76
|
+
@app_id = app_id
|
77
|
+
@secret_key = secret_key
|
78
|
+
|
79
|
+
# @type [Addressable::URI]
|
80
|
+
@url = Addressable::URI.parse(url)
|
81
|
+
|
82
|
+
@logger = logger
|
83
|
+
@instrumentation = instrumentation
|
84
|
+
@timeout = timeout
|
85
|
+
@proxy = proxy
|
86
|
+
|
87
|
+
@admin_email = (admin_email || -> { "#{@app_id}_admin@qismo.com" })
|
41
88
|
end
|
42
89
|
|
43
90
|
# Send http request with post method
|
@@ -85,7 +132,7 @@ module Qismo
|
|
85
132
|
# @param json [Hash]
|
86
133
|
# @return [Qismo::ObjectifiedHash]
|
87
134
|
def request(method, path, options = {})
|
88
|
-
res = connection.request(method, @url
|
135
|
+
res = connection.request(method, @url.join(path), options.compact)
|
89
136
|
|
90
137
|
if res.status.success?
|
91
138
|
begin
|
@@ -124,16 +171,11 @@ module Qismo
|
|
124
171
|
# @return [HTTP::Chainable]
|
125
172
|
def connection
|
126
173
|
http = HTTP
|
174
|
+
http = http.use(logging: {logger: @logger}) if @logger.present?
|
175
|
+
http = http.use(instrumentation: @instrumentation) if @instrumentation.present?
|
176
|
+
http = http.via(*@proxy) if @proxy.present?
|
127
177
|
|
128
|
-
|
129
|
-
http = http.use(logging: @logger)
|
130
|
-
end
|
131
|
-
|
132
|
-
unless @instrumentation.nil?
|
133
|
-
http = http.use(instrumentation: @instrumentation)
|
134
|
-
end
|
135
|
-
|
136
|
-
unless @timeout.nil?
|
178
|
+
if @timeout.present?
|
137
179
|
http = if @timeout.is_a?(Hash)
|
138
180
|
http.timeout(**@timeout)
|
139
181
|
else
|
@@ -141,10 +183,6 @@ module Qismo
|
|
141
183
|
end
|
142
184
|
end
|
143
185
|
|
144
|
-
unless @proxy.nil?
|
145
|
-
http = http.via(*@proxy)
|
146
|
-
end
|
147
|
-
|
148
186
|
http.headers({
|
149
187
|
"Qiscus-App-Id": @app_id,
|
150
188
|
"Qiscus-Secret-Key": @secret_key,
|
data/lib/qismo/version.rb
CHANGED
data/qismo.gemspec
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"Initiate Qismo client": {
|
3
|
-
"prefix": "Qismo",
|
3
|
+
"prefix": "Qismo::Client",
|
4
|
+
"scope": "ruby",
|
4
5
|
"body": [
|
5
|
-
"
|
6
|
+
"qismo = Qismo::Client.new(",
|
6
7
|
" app_id: \"${1:app_id}\",",
|
7
8
|
" secret_key: \"${2:secret_key}\",",
|
8
9
|
" url: \"https://qismo.qiscus.com\",",
|
@@ -14,22 +15,105 @@
|
|
14
15
|
"description": "Initiate Qismo client"
|
15
16
|
},
|
16
17
|
"List rooms": {
|
17
|
-
"prefix": "
|
18
|
-
"body": [
|
19
|
-
"rooms =
|
20
|
-
" channels: [{ source: \"wa\", channel_id: 716171 }],",
|
21
|
-
" status: \"unresolved\",",
|
22
|
-
" serve_status: \"served\",",
|
23
|
-
" is_handled_by_bot: false,",
|
24
|
-
" name: \"
|
25
|
-
" limit:
|
26
|
-
" tag_ids: [
|
27
|
-
" user_ids: [
|
28
|
-
" order: \"desc\",",
|
29
|
-
" cursor_before: \"\",",
|
30
|
-
" cursor_after: \"\"",
|
18
|
+
"prefix": "qismo.list_rooms",
|
19
|
+
"body": [
|
20
|
+
"rooms = qismo.list_rooms(",
|
21
|
+
" channels: [{ source: \"${1|wa,telegram,qiscus,line,fb|}\", channel_id: 716171 }],",
|
22
|
+
" status: \"${2|unresolved,resolved,almost_expired,expired|}\",",
|
23
|
+
" serve_status: \"${3|served,unserved|}\",",
|
24
|
+
" is_handled_by_bot: ${4|true,false|},",
|
25
|
+
" name: \"${5:customer_name}\",",
|
26
|
+
" limit: ${6:limit},",
|
27
|
+
" tag_ids: [${7:tag_ids}],",
|
28
|
+
" user_ids: [${8:user_ids}],",
|
29
|
+
" order: \"${9|desc,asc|}\",",
|
30
|
+
" cursor_before: \"${10:cursor_before}\",",
|
31
|
+
" cursor_after: \"${11:cursor_after}\"",
|
31
32
|
")"
|
32
33
|
],
|
33
34
|
"description": "List rooms"
|
35
|
+
},
|
36
|
+
"Get room by id": {
|
37
|
+
"scope": "ruby",
|
38
|
+
"prefix": "qismo.get_room",
|
39
|
+
"body": [
|
40
|
+
"room = qismo.get_room(room_id: ${1:room_id})"
|
41
|
+
],
|
42
|
+
"description": "Get room by id"
|
43
|
+
},
|
44
|
+
"List room tags": {
|
45
|
+
"prefix": "qismo.list_room_tags",
|
46
|
+
"body": [
|
47
|
+
"room_tags = qismo.list_room_tags(room_id: ${1:12345})"
|
48
|
+
],
|
49
|
+
"description": "List room tags"
|
50
|
+
},
|
51
|
+
"Add room tag": {
|
52
|
+
"prefix": "qismo.add_room_tag",
|
53
|
+
"body": [
|
54
|
+
"room_tag = qismo.add_room_tag(room_id: ${1:12345}, tag: \"${2:tag_name}\")"
|
55
|
+
],
|
56
|
+
"description": "Add room tag"
|
57
|
+
},
|
58
|
+
"Delete room tag": {
|
59
|
+
"prefix": "qismo.delete_room_tag",
|
60
|
+
"body": [
|
61
|
+
"qismo.delete_room_tag(room_id: ${1:12345}, tag_id: ${2:12345})"
|
62
|
+
],
|
63
|
+
"description": "Delete room tag"
|
64
|
+
},
|
65
|
+
"List room additional info": {
|
66
|
+
"prefix": "qismo.list_room_info",
|
67
|
+
"body": [
|
68
|
+
"room_info = qismo.list_room_info(room_id: ${1:12345})",
|
69
|
+
"room_info.each do |info|",
|
70
|
+
" puts info.key",
|
71
|
+
" puts info.value",
|
72
|
+
"end"
|
73
|
+
],
|
74
|
+
"description": "List room additional info"
|
75
|
+
},
|
76
|
+
"Create room additional info": {
|
77
|
+
"prefix": "qismo.create_room_info",
|
78
|
+
"body": [
|
79
|
+
"room_info = qismo.create_room_info(room_id: ${1:12345}, info: [{key: \"${2:key}\", value: \"${3:value}\"}])",
|
80
|
+
"room_info.each do |info|",
|
81
|
+
" puts info.key",
|
82
|
+
" puts info.value",
|
83
|
+
"end"
|
84
|
+
],
|
85
|
+
"description": "Create room additional info"
|
86
|
+
},
|
87
|
+
"Update room additional info": {
|
88
|
+
"prefix": "qismo.update_room_info",
|
89
|
+
"body": [
|
90
|
+
"room_info = qismo.create_room_info(room_id: ${1:12345}, info: [{key: \"${2:key}\", value: \"${3:value}\"}])",
|
91
|
+
"room_info.each do |info|",
|
92
|
+
" puts info.key",
|
93
|
+
" puts info.value",
|
94
|
+
"end"
|
95
|
+
],
|
96
|
+
"description": "Update room additional info"
|
97
|
+
},
|
98
|
+
"List wa broadcast in room": {
|
99
|
+
"prefix": "qismo.list_room_broadcasts",
|
100
|
+
"body": [
|
101
|
+
"room_broadcasts = qismo.list_room_broadcasts(room_id: ${1:12345}, page: ${2:1}, limit: ${3:25})"
|
102
|
+
],
|
103
|
+
"description": "List wa broadcast in room"
|
104
|
+
},
|
105
|
+
"Assign an agent to a room": {
|
106
|
+
"prefix": "qismo.assign_agent",
|
107
|
+
"body": [
|
108
|
+
"qismo.assign_agent(room_id: ${1:12345}, agent_id: ${2:12345}, replace_latest_agent: ${3|false,true|}, max_agent: ${4:1})"
|
109
|
+
],
|
110
|
+
"description": "Assign an agent to a room"
|
111
|
+
},
|
112
|
+
"Remove an agent from a room": {
|
113
|
+
"prefix": "qismo.remove_agent",
|
114
|
+
"body": [
|
115
|
+
"qismo.remove_agent(room_id: ${1:12345}, agent_id: ${2:12345})"
|
116
|
+
],
|
117
|
+
"description": "Remove an agent from a room"
|
34
118
|
}
|
35
119
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qismo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Qiscus Integration
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.6'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: dry-validation
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.10'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.10'
|
69
55
|
description: Ruby wrapper for Qiscus Omnichannel public API
|
70
56
|
email:
|
71
57
|
- developer@qiscus.net
|
@@ -120,7 +106,7 @@ homepage: https://bitbucket.org/qiscus/qismo-rb
|
|
120
106
|
licenses:
|
121
107
|
- MIT
|
122
108
|
metadata:
|
123
|
-
source_code_uri: https://bitbucket.org/qiscus/qismo-rb/src/v0.18.
|
109
|
+
source_code_uri: https://bitbucket.org/qiscus/qismo-rb/src/v0.18.2
|
124
110
|
documentation_uri: https://www.rubydoc.info/gems/qismo
|
125
111
|
homepage_uri: https://bitbucket.org/qiscus/qismo-rb
|
126
112
|
rubygems_mfa_required: 'true'
|