kapso-client-ruby 1.0.0 → 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 +478 -0
- data/README.md +1053 -734
- 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 +388 -0
- data/examples/rails/models.rb +240 -0
- data/examples/rails/notifications_controller.rb +227 -0
- 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 +76 -0
- data/lib/kapso_client_ruby/rails/generators/templates/env.erb +21 -0
- data/lib/kapso_client_ruby/rails/generators/templates/initializer.rb.erb +33 -0
- data/lib/kapso_client_ruby/rails/generators/templates/message_service.rb.erb +138 -0
- data/lib/kapso_client_ruby/rails/generators/templates/webhook_controller.rb.erb +62 -0
- data/lib/kapso_client_ruby/rails/railtie.rb +55 -0
- data/lib/kapso_client_ruby/rails/service.rb +189 -0
- data/lib/kapso_client_ruby/rails/tasks.rake +167 -0
- 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 -68
- 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 +24 -3
|
@@ -1,391 +1,394 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
templates.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
puts "
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
puts "
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
puts "
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
puts "
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
{ type: 'text', text: '
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
puts "
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
template
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
puts "
|
|
287
|
-
puts "
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
puts "
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
#
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'kapso-client-ruby'
|
|
4
|
+
require 'dotenv'
|
|
5
|
+
|
|
6
|
+
Dotenv.load
|
|
7
|
+
|
|
8
|
+
puts "=== Template Management Examples ==="
|
|
9
|
+
|
|
10
|
+
# Initialize client
|
|
11
|
+
client = KapsoClientRuby::Client.new(
|
|
12
|
+
access_token: ENV['WHATSAPP_ACCESS_TOKEN']
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
business_account_id = ENV['BUSINESS_ACCOUNT_ID']
|
|
16
|
+
|
|
17
|
+
# Example 1: List Existing Templates
|
|
18
|
+
puts "\n--- List Existing Templates ---"
|
|
19
|
+
|
|
20
|
+
begin
|
|
21
|
+
templates = client.templates.list(business_account_id: business_account_id)
|
|
22
|
+
|
|
23
|
+
puts "Found #{templates.data.length} templates:"
|
|
24
|
+
templates.data.each do |template|
|
|
25
|
+
puts "- #{template.name} (#{template.language}) - Status: #{template.status}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Handle pagination if there are more results
|
|
29
|
+
if templates.paging.after
|
|
30
|
+
puts "\nMore templates available. Next cursor: #{templates.paging.after}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
|
34
|
+
puts "Error listing templates: #{e.message}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Example 2: Create Marketing Template
|
|
38
|
+
puts "\n--- Create Marketing Template ---"
|
|
39
|
+
|
|
40
|
+
begin
|
|
41
|
+
# Build a marketing template with the helper method
|
|
42
|
+
template_data = client.templates.build_marketing_template(
|
|
43
|
+
name: 'ruby_sdk_promo',
|
|
44
|
+
language: 'en_US',
|
|
45
|
+
header: {
|
|
46
|
+
type: 'HEADER',
|
|
47
|
+
format: 'TEXT',
|
|
48
|
+
text: 'Special Offer for {{1}}!'
|
|
49
|
+
},
|
|
50
|
+
body: 'Hi {{1}}, we have a special {{2}} discount just for you! Use code {{3}} to get {{4}} off your next purchase.',
|
|
51
|
+
footer: 'This offer expires in 24 hours',
|
|
52
|
+
buttons: [
|
|
53
|
+
{
|
|
54
|
+
type: 'URL',
|
|
55
|
+
text: 'Shop Now',
|
|
56
|
+
url: 'https://example.com/shop?code={{1}}'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: 'QUICK_REPLY',
|
|
60
|
+
text: 'More Info'
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
body_example: {
|
|
64
|
+
body_text: [['John', 'exclusive', 'SAVE20', '20%']]
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Create the template
|
|
69
|
+
response = client.templates.create(
|
|
70
|
+
business_account_id: business_account_id,
|
|
71
|
+
**template_data
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
puts "Marketing template created!"
|
|
75
|
+
puts "Template ID: #{response.id}"
|
|
76
|
+
puts "Status: #{response.status}"
|
|
77
|
+
|
|
78
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
|
79
|
+
puts "Error creating marketing template: #{e.message}"
|
|
80
|
+
|
|
81
|
+
if e.template_error?
|
|
82
|
+
puts "Template-specific error - check template format and content"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Example 3: Create Authentication Template
|
|
87
|
+
puts "\n--- Create Authentication Template ---"
|
|
88
|
+
|
|
89
|
+
begin
|
|
90
|
+
# Build authentication template using helper
|
|
91
|
+
auth_template = client.templates.build_authentication_template(
|
|
92
|
+
name: 'ruby_sdk_auth',
|
|
93
|
+
language: 'en_US',
|
|
94
|
+
ttl_seconds: 300, # 5 minutes
|
|
95
|
+
code_expiration_minutes: 5,
|
|
96
|
+
otp_type: 'COPY_CODE'
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
response = client.templates.create(
|
|
100
|
+
business_account_id: business_account_id,
|
|
101
|
+
**auth_template
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
puts "Authentication template created!"
|
|
105
|
+
puts "Template ID: #{response.id}"
|
|
106
|
+
puts "Status: #{response.status}"
|
|
107
|
+
|
|
108
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
|
109
|
+
puts "Error creating auth template: #{e.message}"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Example 4: Create Utility Template
|
|
113
|
+
puts "\n--- Create Utility Template ---"
|
|
114
|
+
|
|
115
|
+
begin
|
|
116
|
+
utility_template = client.templates.build_utility_template(
|
|
117
|
+
name: 'ruby_sdk_notification',
|
|
118
|
+
language: 'en_US',
|
|
119
|
+
header: {
|
|
120
|
+
type: 'HEADER',
|
|
121
|
+
format: 'TEXT',
|
|
122
|
+
text: 'Order Update'
|
|
123
|
+
},
|
|
124
|
+
body: 'Your order #{{1}} has been {{2}}. Estimated delivery: {{3}}.',
|
|
125
|
+
footer: 'Thank you for choosing our service',
|
|
126
|
+
buttons: [
|
|
127
|
+
{
|
|
128
|
+
type: 'URL',
|
|
129
|
+
text: 'Track Order',
|
|
130
|
+
url: 'https://example.com/track/{{1}}'
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
body_example: {
|
|
134
|
+
body_text: [['12345', 'shipped', 'Tomorrow 2-4 PM']]
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
response = client.templates.create(
|
|
139
|
+
business_account_id: business_account_id,
|
|
140
|
+
**utility_template
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
puts "Utility template created!"
|
|
144
|
+
puts "Template ID: #{response.id}"
|
|
145
|
+
|
|
146
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
|
147
|
+
puts "Error creating utility template: #{e.message}"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Example 5: Create Complex Template with All Components
|
|
151
|
+
puts "\n--- Create Complex Template ---"
|
|
152
|
+
|
|
153
|
+
begin
|
|
154
|
+
components = [
|
|
155
|
+
# Header with image
|
|
156
|
+
{
|
|
157
|
+
type: 'HEADER',
|
|
158
|
+
format: 'IMAGE',
|
|
159
|
+
example: {
|
|
160
|
+
header_handle: ['https://example.com/header-image.jpg']
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
# Body with variables
|
|
164
|
+
{
|
|
165
|
+
type: 'BODY',
|
|
166
|
+
text: 'Hello {{1}}! Your {{2}} order totaling {{3}} is ready for pickup. ' \
|
|
167
|
+
'Please bring your ID and order confirmation {{4}}.',
|
|
168
|
+
example: {
|
|
169
|
+
body_text: [['John Doe', 'premium', '$125.99', '#ORD12345']]
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
# Footer
|
|
173
|
+
{
|
|
174
|
+
type: 'FOOTER',
|
|
175
|
+
text: 'Reply STOP to unsubscribe'
|
|
176
|
+
},
|
|
177
|
+
# Multiple buttons
|
|
178
|
+
{
|
|
179
|
+
type: 'BUTTONS',
|
|
180
|
+
buttons: [
|
|
181
|
+
{
|
|
182
|
+
type: 'URL',
|
|
183
|
+
text: 'View Order',
|
|
184
|
+
url: 'https://example.com/orders/{{1}}'
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
type: 'PHONE_NUMBER',
|
|
188
|
+
text: 'Call Store',
|
|
189
|
+
phone_number: '+1234567890'
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
type: 'QUICK_REPLY',
|
|
193
|
+
text: 'Reschedule'
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
|
|
199
|
+
response = client.templates.create(
|
|
200
|
+
business_account_id: business_account_id,
|
|
201
|
+
name: 'ruby_sdk_complex',
|
|
202
|
+
language: 'en_US',
|
|
203
|
+
category: 'UTILITY',
|
|
204
|
+
components: components
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
puts "Complex template created!"
|
|
208
|
+
puts "Template ID: #{response.id}"
|
|
209
|
+
|
|
210
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
|
211
|
+
puts "Error creating complex template: #{e.message}"
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Example 6: Send Template Messages
|
|
215
|
+
puts "\n--- Send Template Messages ---"
|
|
216
|
+
|
|
217
|
+
begin
|
|
218
|
+
# Send simple template without variables
|
|
219
|
+
response1 = client.messages.send_template(
|
|
220
|
+
phone_number_id: ENV['PHONE_NUMBER_ID'],
|
|
221
|
+
to: '+1234567890',
|
|
222
|
+
name: 'hello_world', # Meta's sample template
|
|
223
|
+
language: 'en_US'
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
puts "Simple template sent: #{response1.messages.first.id}"
|
|
227
|
+
|
|
228
|
+
# Send template with parameters
|
|
229
|
+
response2 = client.messages.send_template(
|
|
230
|
+
phone_number_id: ENV['PHONE_NUMBER_ID'],
|
|
231
|
+
to: '+1234567890',
|
|
232
|
+
name: 'ruby_sdk_promo', # Our created template
|
|
233
|
+
language: 'en_US',
|
|
234
|
+
components: [
|
|
235
|
+
{
|
|
236
|
+
type: 'header',
|
|
237
|
+
parameters: [
|
|
238
|
+
{ type: 'text', text: 'John Doe' }
|
|
239
|
+
]
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
type: 'body',
|
|
243
|
+
parameters: [
|
|
244
|
+
{ type: 'text', text: 'John' },
|
|
245
|
+
{ type: 'text', text: 'exclusive' },
|
|
246
|
+
{ type: 'text', text: 'RUBY20' },
|
|
247
|
+
{ type: 'text', text: '20%' }
|
|
248
|
+
]
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
type: 'button',
|
|
252
|
+
sub_type: 'url',
|
|
253
|
+
index: '0',
|
|
254
|
+
parameters: [
|
|
255
|
+
{ type: 'text', text: 'RUBY20' }
|
|
256
|
+
]
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
puts "Parameterized template sent: #{response2.messages.first.id}"
|
|
262
|
+
|
|
263
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
|
264
|
+
puts "Error sending template: #{e.message}"
|
|
265
|
+
|
|
266
|
+
case e.category
|
|
267
|
+
when :template
|
|
268
|
+
puts "Template error - check template name, language, and parameters"
|
|
269
|
+
when :parameter
|
|
270
|
+
puts "Parameter error - check component parameters format"
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# Example 7: Template Management Operations
|
|
275
|
+
puts "\n--- Template Management Operations ---"
|
|
276
|
+
|
|
277
|
+
begin
|
|
278
|
+
# Get specific template details
|
|
279
|
+
template_id = 'your_template_id' # Replace with actual template ID
|
|
280
|
+
|
|
281
|
+
template = client.templates.get(
|
|
282
|
+
business_account_id: business_account_id,
|
|
283
|
+
template_id: template_id
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
puts "Template Details:"
|
|
287
|
+
puts "Name: #{template.name}"
|
|
288
|
+
puts "Status: #{template.status}"
|
|
289
|
+
puts "Category: #{template.category}"
|
|
290
|
+
puts "Quality Score: #{template.quality_score_category}"
|
|
291
|
+
|
|
292
|
+
# Update template (if allowed)
|
|
293
|
+
if template.status == 'REJECTED'
|
|
294
|
+
puts "Attempting to update rejected template..."
|
|
295
|
+
|
|
296
|
+
client.templates.update(
|
|
297
|
+
business_account_id: business_account_id,
|
|
298
|
+
template_id: template_id,
|
|
299
|
+
category: 'UTILITY' # Change category if needed
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
puts "Template updated successfully"
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
|
306
|
+
puts "Template management error: #{e.message}"
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# Example 8: Delete Templates
|
|
310
|
+
puts "\n--- Delete Templates ---"
|
|
311
|
+
|
|
312
|
+
begin
|
|
313
|
+
# Delete by template ID
|
|
314
|
+
client.templates.delete(
|
|
315
|
+
business_account_id: business_account_id,
|
|
316
|
+
template_id: 'template_id_to_delete'
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
puts "Template deleted by ID"
|
|
320
|
+
|
|
321
|
+
# Delete by name and language
|
|
322
|
+
client.templates.delete(
|
|
323
|
+
business_account_id: business_account_id,
|
|
324
|
+
name: 'ruby_sdk_test',
|
|
325
|
+
language: 'en_US'
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
puts "Template deleted by name"
|
|
329
|
+
|
|
330
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
|
331
|
+
puts "Delete error: #{e.message}"
|
|
332
|
+
|
|
333
|
+
if e.http_status == 404
|
|
334
|
+
puts "Template not found - may already be deleted"
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
# Example 9: Template Validation and Best Practices
|
|
339
|
+
puts "\n--- Template Validation Examples ---"
|
|
340
|
+
|
|
341
|
+
# Good template example
|
|
342
|
+
def create_good_template(client, business_account_id)
|
|
343
|
+
client.templates.create(
|
|
344
|
+
business_account_id: business_account_id,
|
|
345
|
+
name: 'good_template_example',
|
|
346
|
+
language: 'en_US',
|
|
347
|
+
category: 'UTILITY',
|
|
348
|
+
components: [
|
|
349
|
+
{
|
|
350
|
+
type: 'BODY',
|
|
351
|
+
text: 'Your appointment with {{1}} is confirmed for {{2}} at {{3}}.',
|
|
352
|
+
example: {
|
|
353
|
+
body_text: [['Dr. Smith', 'tomorrow', '2:00 PM']]
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
type: 'FOOTER',
|
|
358
|
+
text: 'Reply CANCEL to cancel this appointment'
|
|
359
|
+
}
|
|
360
|
+
]
|
|
361
|
+
)
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# Bad template example (this will likely be rejected)
|
|
365
|
+
def create_bad_template_example(client, business_account_id)
|
|
366
|
+
begin
|
|
367
|
+
client.templates.create(
|
|
368
|
+
business_account_id: business_account_id,
|
|
369
|
+
name: 'bad_template_example',
|
|
370
|
+
language: 'en_US',
|
|
371
|
+
category: 'MARKETING',
|
|
372
|
+
components: [
|
|
373
|
+
{
|
|
374
|
+
type: 'BODY',
|
|
375
|
+
text: 'URGENT!!! Buy now or MISS OUT!!! Limited time offer!!!'
|
|
376
|
+
# No example provided, excessive caps, promotional language
|
|
377
|
+
}
|
|
378
|
+
]
|
|
379
|
+
)
|
|
380
|
+
rescue KapsoClientRuby::Errors::GraphApiError => e
|
|
381
|
+
puts "Bad template rejected (expected): #{e.message}"
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
|
|
385
|
+
begin
|
|
386
|
+
good_response = create_good_template(client, business_account_id)
|
|
387
|
+
puts "Good template created: #{good_response.id}"
|
|
388
|
+
rescue => e
|
|
389
|
+
puts "Error with good template: #{e.message}"
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
create_bad_template_example(client, business_account_id)
|
|
393
|
+
|
|
391
394
|
puts "\n=== Template Management Examples Completed ==="
|