kapso-client-ruby 1.0.1 → 1.0.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/.rubocop.yml +81 -81
- data/CHANGELOG.md +262 -91
- data/Gemfile +20 -20
- data/RAILS_INTEGRATION.md +477 -477
- data/README.md +1053 -752
- data/Rakefile +40 -40
- data/TEMPLATE_TOOLS_GUIDE.md +120 -120
- data/WHATSAPP_24_HOUR_GUIDE.md +133 -133
- data/examples/advanced_features.rb +352 -349
- data/examples/advanced_messaging.rb +241 -0
- data/examples/basic_messaging.rb +139 -136
- data/examples/enhanced_interactive.rb +400 -0
- data/examples/flows_usage.rb +307 -0
- data/examples/interactive_messages.rb +343 -0
- data/examples/media_management.rb +256 -253
- data/examples/rails/jobs.rb +387 -387
- data/examples/rails/models.rb +239 -239
- data/examples/rails/notifications_controller.rb +226 -226
- data/examples/template_management.rb +393 -390
- data/kapso-ruby-logo.jpg +0 -0
- data/lib/kapso_client_ruby/client.rb +321 -316
- data/lib/kapso_client_ruby/errors.rb +348 -329
- data/lib/kapso_client_ruby/rails/generators/install_generator.rb +75 -75
- data/lib/kapso_client_ruby/rails/generators/templates/env.erb +20 -20
- data/lib/kapso_client_ruby/rails/generators/templates/initializer.rb.erb +32 -32
- data/lib/kapso_client_ruby/rails/generators/templates/message_service.rb.erb +137 -137
- data/lib/kapso_client_ruby/rails/generators/templates/webhook_controller.rb.erb +61 -61
- data/lib/kapso_client_ruby/rails/railtie.rb +54 -54
- data/lib/kapso_client_ruby/rails/service.rb +188 -188
- data/lib/kapso_client_ruby/rails/tasks.rake +166 -166
- data/lib/kapso_client_ruby/resources/calls.rb +172 -172
- data/lib/kapso_client_ruby/resources/contacts.rb +190 -190
- data/lib/kapso_client_ruby/resources/conversations.rb +103 -103
- data/lib/kapso_client_ruby/resources/flows.rb +382 -0
- data/lib/kapso_client_ruby/resources/media.rb +205 -205
- data/lib/kapso_client_ruby/resources/messages.rb +760 -380
- data/lib/kapso_client_ruby/resources/phone_numbers.rb +85 -85
- data/lib/kapso_client_ruby/resources/templates.rb +283 -283
- data/lib/kapso_client_ruby/types.rb +348 -262
- data/lib/kapso_client_ruby/version.rb +5 -5
- data/lib/kapso_client_ruby.rb +75 -74
- data/scripts/.env.example +17 -17
- data/scripts/kapso_template_finder.rb +91 -91
- data/scripts/sdk_setup.rb +404 -404
- data/scripts/test.rb +60 -60
- metadata +12 -3
|
@@ -1,173 +1,173 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module KapsoClientRuby
|
|
4
|
-
module Resources
|
|
5
|
-
class Calls
|
|
6
|
-
def initialize(client)
|
|
7
|
-
@client = client
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
# Initiate a call
|
|
11
|
-
def connect(phone_number_id:, to:, session: nil, biz_opaque_callback_data: nil)
|
|
12
|
-
payload = {
|
|
13
|
-
messaging_product: 'whatsapp',
|
|
14
|
-
to: to,
|
|
15
|
-
action: 'connect'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
payload[:session] = session if session
|
|
19
|
-
payload[:biz_opaque_callback_data] = biz_opaque_callback_data if biz_opaque_callback_data
|
|
20
|
-
|
|
21
|
-
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
22
|
-
body: payload.to_json, response_type: :json)
|
|
23
|
-
Types::CallConnectResponse.new(response)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Pre-accept a call
|
|
27
|
-
def pre_accept(phone_number_id:, call_id:, session:)
|
|
28
|
-
raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty?
|
|
29
|
-
raise ArgumentError, 'session cannot be nil' if session.nil?
|
|
30
|
-
|
|
31
|
-
payload = {
|
|
32
|
-
messaging_product: 'whatsapp',
|
|
33
|
-
call_id: call_id,
|
|
34
|
-
action: 'pre_accept',
|
|
35
|
-
session: session
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
39
|
-
body: payload.to_json, response_type: :json)
|
|
40
|
-
Types::CallActionResponse.new(response)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Accept a call
|
|
44
|
-
def accept(phone_number_id:, call_id:, session:, biz_opaque_callback_data: nil)
|
|
45
|
-
raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty?
|
|
46
|
-
raise ArgumentError, 'session cannot be nil' if session.nil?
|
|
47
|
-
|
|
48
|
-
payload = {
|
|
49
|
-
messaging_product: 'whatsapp',
|
|
50
|
-
call_id: call_id,
|
|
51
|
-
action: 'accept',
|
|
52
|
-
session: session
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
payload[:biz_opaque_callback_data] = biz_opaque_callback_data if biz_opaque_callback_data
|
|
56
|
-
|
|
57
|
-
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
58
|
-
body: payload.to_json, response_type: :json)
|
|
59
|
-
Types::CallActionResponse.new(response)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# Reject a call
|
|
63
|
-
def reject(phone_number_id:, call_id:)
|
|
64
|
-
raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty?
|
|
65
|
-
|
|
66
|
-
payload = {
|
|
67
|
-
messaging_product: 'whatsapp',
|
|
68
|
-
call_id: call_id,
|
|
69
|
-
action: 'reject'
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
73
|
-
body: payload.to_json, response_type: :json)
|
|
74
|
-
Types::CallActionResponse.new(response)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Terminate a call
|
|
78
|
-
def terminate(phone_number_id:, call_id:)
|
|
79
|
-
raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty?
|
|
80
|
-
|
|
81
|
-
payload = {
|
|
82
|
-
messaging_product: 'whatsapp',
|
|
83
|
-
call_id: call_id,
|
|
84
|
-
action: 'terminate'
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
88
|
-
body: payload.to_json, response_type: :json)
|
|
89
|
-
Types::CallActionResponse.new(response)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
# List calls (Kapso Proxy only)
|
|
93
|
-
def list(phone_number_id:, direction: nil, status: nil, since: nil,
|
|
94
|
-
until_time: nil, call_id: nil, limit: nil, after: nil,
|
|
95
|
-
before: nil, fields: nil)
|
|
96
|
-
assert_kapso_proxy('Call history API')
|
|
97
|
-
|
|
98
|
-
query_params = {
|
|
99
|
-
direction: direction,
|
|
100
|
-
status: status,
|
|
101
|
-
since: since,
|
|
102
|
-
until: until_time,
|
|
103
|
-
call_id: call_id,
|
|
104
|
-
limit: limit,
|
|
105
|
-
after: after,
|
|
106
|
-
before: before,
|
|
107
|
-
fields: fields
|
|
108
|
-
}.compact
|
|
109
|
-
|
|
110
|
-
response = @client.request(:get, "#{phone_number_id}/calls",
|
|
111
|
-
query: query_params, response_type: :json)
|
|
112
|
-
Types::PagedResponse.new(response, Types::CallRecord)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# Get call details (Kapso Proxy only)
|
|
116
|
-
def get(phone_number_id:, call_id:, fields: nil)
|
|
117
|
-
assert_kapso_proxy('Call details API')
|
|
118
|
-
|
|
119
|
-
query_params = {}
|
|
120
|
-
query_params[:fields] = fields if fields
|
|
121
|
-
|
|
122
|
-
response = @client.request(:get, "#{phone_number_id}/calls/#{call_id}",
|
|
123
|
-
query: query_params, response_type: :json)
|
|
124
|
-
Types::CallRecord.new(response)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# Call permissions management
|
|
128
|
-
class Permissions
|
|
129
|
-
def initialize(client)
|
|
130
|
-
@client = client
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
# Get call permissions
|
|
134
|
-
def get(phone_number_id:, user_wa_id:)
|
|
135
|
-
raise ArgumentError, 'user_wa_id cannot be empty' if user_wa_id.nil? || user_wa_id.strip.empty?
|
|
136
|
-
|
|
137
|
-
query_params = { user_wa_id: user_wa_id }
|
|
138
|
-
|
|
139
|
-
response = @client.request(:get, "#{phone_number_id}/call_permissions",
|
|
140
|
-
query: query_params, response_type: :json)
|
|
141
|
-
response
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
# Update call permissions
|
|
145
|
-
def update(phone_number_id:, user_wa_id:, permission:)
|
|
146
|
-
raise ArgumentError, 'user_wa_id cannot be empty' if user_wa_id.nil? || user_wa_id.strip.empty?
|
|
147
|
-
raise ArgumentError, 'permission cannot be empty' if permission.nil?
|
|
148
|
-
|
|
149
|
-
payload = {
|
|
150
|
-
user_wa_id: user_wa_id,
|
|
151
|
-
permission: permission
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
response = @client.request(:post, "#{phone_number_id}/call_permissions",
|
|
155
|
-
body: payload.to_json, response_type: :json)
|
|
156
|
-
Types::GraphSuccessResponse.new(response)
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def permissions
|
|
161
|
-
@permissions ||= Permissions.new(@client)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
private
|
|
165
|
-
|
|
166
|
-
def assert_kapso_proxy(feature)
|
|
167
|
-
unless @client.kapso_proxy?
|
|
168
|
-
raise Errors::KapsoProxyRequiredError.new(feature)
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module KapsoClientRuby
|
|
4
|
+
module Resources
|
|
5
|
+
class Calls
|
|
6
|
+
def initialize(client)
|
|
7
|
+
@client = client
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Initiate a call
|
|
11
|
+
def connect(phone_number_id:, to:, session: nil, biz_opaque_callback_data: nil)
|
|
12
|
+
payload = {
|
|
13
|
+
messaging_product: 'whatsapp',
|
|
14
|
+
to: to,
|
|
15
|
+
action: 'connect'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
payload[:session] = session if session
|
|
19
|
+
payload[:biz_opaque_callback_data] = biz_opaque_callback_data if biz_opaque_callback_data
|
|
20
|
+
|
|
21
|
+
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
22
|
+
body: payload.to_json, response_type: :json)
|
|
23
|
+
Types::CallConnectResponse.new(response)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Pre-accept a call
|
|
27
|
+
def pre_accept(phone_number_id:, call_id:, session:)
|
|
28
|
+
raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty?
|
|
29
|
+
raise ArgumentError, 'session cannot be nil' if session.nil?
|
|
30
|
+
|
|
31
|
+
payload = {
|
|
32
|
+
messaging_product: 'whatsapp',
|
|
33
|
+
call_id: call_id,
|
|
34
|
+
action: 'pre_accept',
|
|
35
|
+
session: session
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
39
|
+
body: payload.to_json, response_type: :json)
|
|
40
|
+
Types::CallActionResponse.new(response)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Accept a call
|
|
44
|
+
def accept(phone_number_id:, call_id:, session:, biz_opaque_callback_data: nil)
|
|
45
|
+
raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty?
|
|
46
|
+
raise ArgumentError, 'session cannot be nil' if session.nil?
|
|
47
|
+
|
|
48
|
+
payload = {
|
|
49
|
+
messaging_product: 'whatsapp',
|
|
50
|
+
call_id: call_id,
|
|
51
|
+
action: 'accept',
|
|
52
|
+
session: session
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
payload[:biz_opaque_callback_data] = biz_opaque_callback_data if biz_opaque_callback_data
|
|
56
|
+
|
|
57
|
+
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
58
|
+
body: payload.to_json, response_type: :json)
|
|
59
|
+
Types::CallActionResponse.new(response)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Reject a call
|
|
63
|
+
def reject(phone_number_id:, call_id:)
|
|
64
|
+
raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty?
|
|
65
|
+
|
|
66
|
+
payload = {
|
|
67
|
+
messaging_product: 'whatsapp',
|
|
68
|
+
call_id: call_id,
|
|
69
|
+
action: 'reject'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
73
|
+
body: payload.to_json, response_type: :json)
|
|
74
|
+
Types::CallActionResponse.new(response)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Terminate a call
|
|
78
|
+
def terminate(phone_number_id:, call_id:)
|
|
79
|
+
raise ArgumentError, 'call_id cannot be empty' if call_id.nil? || call_id.strip.empty?
|
|
80
|
+
|
|
81
|
+
payload = {
|
|
82
|
+
messaging_product: 'whatsapp',
|
|
83
|
+
call_id: call_id,
|
|
84
|
+
action: 'terminate'
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
response = @client.request(:post, "#{phone_number_id}/calls",
|
|
88
|
+
body: payload.to_json, response_type: :json)
|
|
89
|
+
Types::CallActionResponse.new(response)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# List calls (Kapso Proxy only)
|
|
93
|
+
def list(phone_number_id:, direction: nil, status: nil, since: nil,
|
|
94
|
+
until_time: nil, call_id: nil, limit: nil, after: nil,
|
|
95
|
+
before: nil, fields: nil)
|
|
96
|
+
assert_kapso_proxy('Call history API')
|
|
97
|
+
|
|
98
|
+
query_params = {
|
|
99
|
+
direction: direction,
|
|
100
|
+
status: status,
|
|
101
|
+
since: since,
|
|
102
|
+
until: until_time,
|
|
103
|
+
call_id: call_id,
|
|
104
|
+
limit: limit,
|
|
105
|
+
after: after,
|
|
106
|
+
before: before,
|
|
107
|
+
fields: fields
|
|
108
|
+
}.compact
|
|
109
|
+
|
|
110
|
+
response = @client.request(:get, "#{phone_number_id}/calls",
|
|
111
|
+
query: query_params, response_type: :json)
|
|
112
|
+
Types::PagedResponse.new(response, Types::CallRecord)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Get call details (Kapso Proxy only)
|
|
116
|
+
def get(phone_number_id:, call_id:, fields: nil)
|
|
117
|
+
assert_kapso_proxy('Call details API')
|
|
118
|
+
|
|
119
|
+
query_params = {}
|
|
120
|
+
query_params[:fields] = fields if fields
|
|
121
|
+
|
|
122
|
+
response = @client.request(:get, "#{phone_number_id}/calls/#{call_id}",
|
|
123
|
+
query: query_params, response_type: :json)
|
|
124
|
+
Types::CallRecord.new(response)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Call permissions management
|
|
128
|
+
class Permissions
|
|
129
|
+
def initialize(client)
|
|
130
|
+
@client = client
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Get call permissions
|
|
134
|
+
def get(phone_number_id:, user_wa_id:)
|
|
135
|
+
raise ArgumentError, 'user_wa_id cannot be empty' if user_wa_id.nil? || user_wa_id.strip.empty?
|
|
136
|
+
|
|
137
|
+
query_params = { user_wa_id: user_wa_id }
|
|
138
|
+
|
|
139
|
+
response = @client.request(:get, "#{phone_number_id}/call_permissions",
|
|
140
|
+
query: query_params, response_type: :json)
|
|
141
|
+
response
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Update call permissions
|
|
145
|
+
def update(phone_number_id:, user_wa_id:, permission:)
|
|
146
|
+
raise ArgumentError, 'user_wa_id cannot be empty' if user_wa_id.nil? || user_wa_id.strip.empty?
|
|
147
|
+
raise ArgumentError, 'permission cannot be empty' if permission.nil?
|
|
148
|
+
|
|
149
|
+
payload = {
|
|
150
|
+
user_wa_id: user_wa_id,
|
|
151
|
+
permission: permission
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
response = @client.request(:post, "#{phone_number_id}/call_permissions",
|
|
155
|
+
body: payload.to_json, response_type: :json)
|
|
156
|
+
Types::GraphSuccessResponse.new(response)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def permissions
|
|
161
|
+
@permissions ||= Permissions.new(@client)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
private
|
|
165
|
+
|
|
166
|
+
def assert_kapso_proxy(feature)
|
|
167
|
+
unless @client.kapso_proxy?
|
|
168
|
+
raise Errors::KapsoProxyRequiredError.new(feature)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
173
|
end
|