whatsapp_sdk 1.0.3 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68fa7bcce031d800ba3b8c541992921e602fd9266172fda8c2b9db9a0d400efc
4
- data.tar.gz: e7922f22f38e79a5e2cca6377c86d0bc5a1a2a26beb859b2311b21f6a9be33e7
3
+ metadata.gz: 17de6b59f97c39b0d49c911d4e153d241f60d7f92727a10ec895ff4dc4d9822b
4
+ data.tar.gz: f2f25357ffa9d35972e157f57abfaa4a3ac2b2a9debb0f86fdb15230581c6ce6
5
5
  SHA512:
6
- metadata.gz: f4ae0d0f4f0fff5d85d22255ed36eb063f7b4a3eac744f4d31dca4fc5c86605116bf34043932e17a4b10e8dba9433cf1a7c2aaca54a0becd5bf13ae8ce00a167
7
- data.tar.gz: d0a8e8ef860b48363804833bb518dafc5eb417e09f53d1ffd5cfd797368d9611d040fcdbec55977d886bea265924916c35c65e54c07ba1a41773cb1c2060fa9d
6
+ metadata.gz: 1ef8af8f454441f188633dab7295b20da476d8692af1bf6602032b7504c08d1931bc9fbb9544452f981b3b58111ed0bec034de6138540c3445d6379a50f813ac
7
+ data.tar.gz: ead1a38b14a8d5d16539e61ba4b65c36c6652525ca10d7aab554dd3b83a8cd1b11fff52dc38e0c121f574db108ce3ea64546bf62a386b46078dfc369dd559710
data/.rubocop.yml CHANGED
@@ -8,7 +8,6 @@ AllCops:
8
8
  - 'example.rb'
9
9
  - 'tmp/*'
10
10
  - 'vendor/**/*'
11
- TargetRubyVersion: 3.1
12
11
 
13
12
  Style/HashSyntax:
14
13
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Unreleased
2
2
 
3
+ # v 1.0.5
4
+ - Added GET template endpoint. @osvaldo-santos [185](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/185)
5
+ - Adding support for named paremeters in Templates API. @osvaldo-santos [184](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/184)
6
+ - Fixed bug for empty templates. @osvaldo-santos [183](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/183)
7
+
8
+ # v 1.0.4
9
+ - Support for version 23 and 24 API. [180](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/180)
10
+
3
11
  # v 1.0.3
4
12
  - Fix configuration bug setting `api_version` on Configure. @frenesim [#168](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/168)
5
13
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whatsapp_sdk (1.0.3)
4
+ whatsapp_sdk (1.0.5)
5
5
  faraday (~> 2.0, > 2.0.1)
6
6
  faraday-multipart (~> 1)
7
7
  zeitwerk (~> 2)
@@ -16,23 +16,23 @@ GEM
16
16
  coderay (1.1.3)
17
17
  crack (0.4.5)
18
18
  rexml
19
- faraday (2.12.0)
20
- faraday-net_http (>= 2.0, < 3.4)
19
+ faraday (2.14.0)
20
+ faraday-net_http (>= 2.0, < 3.5)
21
21
  json
22
22
  logger
23
- faraday-multipart (1.0.4)
24
- multipart-post (~> 2)
25
- faraday-net_http (3.3.0)
26
- net-http
23
+ faraday-multipart (1.2.0)
24
+ multipart-post (~> 2.0)
25
+ faraday-net_http (3.4.2)
26
+ net-http (~> 0.5)
27
27
  hashdiff (1.0.1)
28
- json (2.7.2)
29
- logger (1.6.1)
28
+ json (2.18.0)
29
+ logger (1.7.0)
30
30
  method_source (1.0.0)
31
31
  minitest (5.16.1)
32
32
  mocha (1.14.0)
33
33
  multipart-post (2.4.1)
34
- net-http (0.4.1)
35
- uri
34
+ net-http (0.9.1)
35
+ uri (>= 0.11.1)
36
36
  parallel (1.22.1)
37
37
  parser (3.1.2.0)
38
38
  ast (~> 2.4.1)
@@ -45,7 +45,7 @@ GEM
45
45
  rainbow (3.1.1)
46
46
  rake (12.3.3)
47
47
  regexp_parser (2.5.0)
48
- rexml (3.3.9)
48
+ rexml (3.4.2)
49
49
  rubocop (1.30.1)
50
50
  parallel (~> 1.10)
51
51
  parser (>= 3.1.0.0)
@@ -64,18 +64,20 @@ GEM
64
64
  rubocop-ast (>= 0.4.0)
65
65
  ruby-progressbar (1.11.0)
66
66
  unicode-display_width (2.2.0)
67
- uri (0.13.1)
67
+ uri (1.1.1)
68
68
  vcr (6.3.1)
69
69
  base64
70
70
  webmock (3.18.1)
71
71
  addressable (>= 2.8.0)
72
72
  crack (>= 0.3.2)
73
73
  hashdiff (>= 0.4.0, < 2.0.0)
74
- zeitwerk (2.6.18)
74
+ zeitwerk (2.7.4)
75
75
 
76
76
  PLATFORMS
77
77
  arm64-darwin-21
78
78
  arm64-darwin-22
79
+ arm64-darwin-23
80
+ arm64-darwin-24
79
81
  x86_64-darwin-19
80
82
  x86_64-darwin-21
81
83
  x86_64-linux
data/README.md CHANGED
@@ -7,6 +7,39 @@
7
7
  The SDK provides a set of operations and classes to use the Whatsapp API.
8
8
  Send stickers, messages, audio, videos, locations, react and reply to messages or just ask for the phone numbers through this library in a few steps!
9
9
 
10
+ ## Table of Contents
11
+
12
+ - [Features](#features)
13
+ - [Installation](#installation)
14
+ - [Quick Start](#quick-start)
15
+ - [Set up a Meta app](#set-up-a-meta-app)
16
+ - [Usage Overview](#usage-overview)
17
+ - [APIs](#apis)
18
+ - [Templates](#templates)
19
+ - [Business Profile API](#business-profile-api)
20
+ - [Phone numbers API](#phone-numbers-api)
21
+ - [Media API](#media-api)
22
+ - [Messages API](#messages-api)
23
+ - [Errors](#errors)
24
+ - [Examples](#examples)
25
+ - [Whatsapp Cloud API](#whatsapp-cloud-api)
26
+ - [Troubleshooting](#troubleshooting)
27
+ - [Development](#development)
28
+ - [Contributing](#contributing)
29
+ - [Changelog](#changelog)
30
+ - [License](#license)
31
+
32
+ ## Features
33
+
34
+ - **Send Messages**: Text, images, audio, video, documents, stickers, locations, and contacts.
35
+ - **React & Reply**: React to messages with emojis and reply to specific messages.
36
+ - **Message Templates**: Send pre-approved message templates for notifications.
37
+ - **Interactive Messages**: List messages and reply buttons.
38
+ - **Media Management**: Upload, download, and delete media files.
39
+ - **Phone Numbers**: Register, deregister, and query phone numbers.
40
+ - **Business Profile**: Get and update business profile details.
41
+ - **Templates Management**: Create, list, and delete message templates.
42
+
10
43
  ## Demo
11
44
 
12
45
  https://user-images.githubusercontent.com/11672878/173238826-6fc0a6f8-d0ee-4eae-8947-7dfd3b8b3446.mov
@@ -56,11 +89,10 @@ Available API version can be found [here](https://developers.facebook.com/docs/g
56
89
  #### Option 2) Create a `Client` instance :
57
90
 
58
91
  ```ruby
59
-
60
- # without
92
+ # Basic usage
61
93
  client = WhatsappSdk::Api::Client.new("<ACCESS TOKEN>") # replace this with a valid access token
62
94
 
63
- # OR optionally use a logger, api_version and
95
+ # With optional logger and API version
64
96
  logger = Logger.new(STDOUT)
65
97
  logger_options = { bodies: true }
66
98
  client = WhatsappSdk::Api::Client.new("<ACCESS TOKEN>", "<API VERSION>", logger, logger_options)
@@ -86,8 +118,6 @@ Try sending a message to your phone in the UI.
86
118
  <img width="1010" alt="Screen Shot 2022-09-05 at 11 13 24 AM" src="https://user-images.githubusercontent.com/11672878/188480634-369f8de1-b851-4735-86de-f49e96f78d8c.png">
87
119
  </details>
88
120
 
89
- </details>
90
-
91
121
  <details><summary>5) Use the GEM to interact with Whatsapp</summary>
92
122
 
93
123
  Example:
@@ -131,20 +161,20 @@ Check the [example.rb file](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk
131
161
 
132
162
  </details>
133
163
 
134
- ## Sneak Peek
164
+ ## Usage Overview
135
165
 
136
166
  ```ruby
137
167
  client = WhatsappSdk::Api::Client.new("<ACCESS TOKEN>") # replace this with a valid access token
138
168
 
139
- client.phone_numbers.register_number(SENDER_ID, 123456) # register the phone number to uplaod media and send message from.
169
+ client.phone_numbers.register_number(SENDER_ID, 123456) # register the phone number to upload media and send messages from.
140
170
 
141
171
  # send a text and a location
142
- client.messages.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,message: "Hey there! it's Whatsapp Ruby SDK")
172
+ client.messages.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message: "Hey there! it's Whatsapp Ruby SDK")
143
173
 
144
174
  client.messages.send_location(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, longitude: -75.6898604, latitude: 45.4192206, name: "Ignacio", address: "My house")
145
175
 
146
176
  # upload a photo and send it
147
- image = client.media.upload(sender_id: SENDER_ID, file_path: "test/fixtures/assets/whatsapp.png", type: "image/png")image = client.media.get(media_id: uploaded_media.id)
177
+ image = client.media.upload(sender_id: SENDER_ID, file_path: "test/fixtures/assets/whatsapp.png", type: "image/png")
148
178
  client.messages.send_image(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, image_id: image.id)
149
179
 
150
180
  # upload a sticker and send it
@@ -166,6 +196,9 @@ client.templates.list(business_id: BUSINESS_ID)
166
196
  # The message template namespace is required to send messages using the message templates.
167
197
  client.templates.get_message_template_namespace(business_id: BUSINESS_ID)
168
198
 
199
+ # Get template by id
200
+ template = client.templates.get(template_id: id)
201
+
169
202
  # Create a template
170
203
  client.templates.create(
171
204
  business_id: BUSINESS_ID, name: "seasonal_promotion", language: "en_US", category: "MARKETING",
@@ -183,7 +216,7 @@ client.templates.delete(business_id: BUSINESS_ID, name: "my_name") # delete by n
183
216
 
184
217
  ```ruby
185
218
  # Get the details of your business
186
- client.business_profiles.get(phone_number_id)
219
+ client.business_profiles.get(SENDER_ID)
187
220
 
188
221
  # Update the details of your business
189
222
  client.business_profiles.update(phone_number_id: SENDER_ID, params: { about: "A very cool business" } )
@@ -196,16 +229,16 @@ client.business_profiles.update(phone_number_id: SENDER_ID, params: { about: "A
196
229
 
197
230
  ```ruby
198
231
  # Get the list of phone numbers registered
199
- client.phone_numbers.list(business_id)
232
+ client.phone_numbers.list(BUSINESS_ID)
200
233
 
201
- # Get the a phone number by id
202
- client.phone_numbers.get(phone_number_id)
234
+ # Get a phone number by id
235
+ client.phone_numbers.get(SENDER_ID)
203
236
 
204
237
  # Register a phone number
205
- client.phone_numbers.register_number(phone_number_id, pin)
238
+ client.phone_numbers.register_number(SENDER_ID, pin)
206
239
 
207
240
  # Deregister a phone number
208
- client.phone_numbers.deregister_number(phone_number_id)
241
+ client.phone_numbers.deregister_number(SENDER_ID)
209
242
  ```
210
243
 
211
244
  </details>
@@ -235,68 +268,68 @@ client.media.delete(media_id: MEDIA_ID)
235
268
 
236
269
  ```ruby
237
270
  # Send a text message
238
- client.messages.send_text(sender_id: 1234, recipient_number: 112345678, message: "hola")
271
+ client.messages.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message: "hola")
239
272
 
240
273
  # Read a message
241
- client.messages.read_message(sender_id: 1234, message_id: "wamid.HBgLMTM0M12345678910=")
274
+ client.messages.read_message(sender_id: SENDER_ID, message_id: "wamid.HBgLMTM0M12345678910=")
242
275
 
243
276
  # Note: To get the `message_id` you can set up [Webhooks](https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components) that will listen and fire an event when a message is received.
244
277
 
245
278
  # Send a reaction to message
246
279
  # To send a reaction to a message, you need to obtain the message id and look for the emoji's unicode you want to use.
247
- client.messages.send_reaction(sender_id: 123_123, recipient_number: 56_789, message_id: "12345", emoji: "\u{1f550}")
248
- client.messages.send_reaction(sender_id: 123_123, recipient_number: 56_789, message_id: "12345", emoji: "⛄️")
280
+ client.messages.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: "12345", emoji: "\u{1f550}")
281
+ client.messages.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: "12345", emoji: "⛄️")
249
282
 
250
283
  # Reply to a message
251
284
  # To reply to a message, just include the id of the message in the `client.messages` methods. For example, to reply to a text message include the following:
252
- client.messages.send_text(sender_id: 123_123, recipient_number: 56_789, message: "I'm a reply", message_id: "wamid.1234")
285
+ client.messages.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message: "I'm a reply", message_id: "wamid.1234")
253
286
 
254
287
  # Send a location message
255
288
  client.messages.send_location(
256
- sender_id: 123123, recipient_number: 56789,
289
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,
257
290
  longitude: 45.4215, latitude: 75.6972, name: "nacho", address: "141 cooper street"
258
291
  )
259
292
 
260
293
  # Send an image message
261
294
  # It uses a link or an image_id.
262
295
  # with a link
263
- client.messages.send_image(sender_id: 123123, recipient_number: 56789, link: "image_link", caption: "Ignacio Chiazzo Profile")
296
+ client.messages.send_image(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "image_link", caption: "Ignacio Chiazzo Profile")
264
297
 
265
298
  # with an image id
266
- client.messages.send_image(sender_id: 123123, recipient_number: 56789, image_id: "1234", caption: "Ignacio Chiazzo Profile")
299
+ client.messages.send_image(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, image_id: "1234", caption: "Ignacio Chiazzo Profile")
267
300
 
268
301
 
269
302
  # Send an audio message
270
303
  # It uses a link or an audio_id.
271
304
  # with a link
272
- client.messages.send_audio(sender_id: 123123, recipient_number: 56789, link: "audio_link")
305
+ client.messages.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "audio_link")
273
306
 
274
307
  # with an audio id
275
- client.messages.send_audio(sender_id: 123123, recipient_number: 56789, audio_id: "1234")
308
+ client.messages.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, audio_id: "1234")
276
309
 
277
310
  # Send a document message
278
311
  # It uses a link or a document_id.
279
312
  # with a link
280
- client.messages.send_document(sender_id: 123123, recipient_number: 56789, link: "document_link", caption: "Ignacio Chiazzo")
313
+ client.messages.send_document(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "document_link", caption: "Ignacio Chiazzo")
281
314
 
282
315
  # with a document id
283
- client.messages.send_document(sender_id: 123123, recipient_number: 56789, document_id: "1234", caption: "Ignacio Chiazzo")
284
- # Note, you can specify the filename via argument [`filename`](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages).
316
+ client.messages.send_document(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, document_id: "1234", caption: "Ignacio Chiazzo")
317
+ # Note, you can specify the filename via argument [`filename`](https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages).
285
318
 
286
319
  # Send a sticker message
287
320
  # It could use a link or a sticker_id.
288
321
  # with a link
289
- client.messages.send_sticker(sender_id: 123123, recipient_number: 56789, link: "link")
322
+ client.messages.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "link")
290
323
 
291
324
  # with a sticker_id
292
- client.messages.send_sticker(sender_id: 123123, recipient_number: 56789, sticker_id: "1234")
325
+ client.messages.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, sticker_id: "1234")
293
326
 
294
327
  # Send contacts message
295
328
  # To send a contact, you need to create a Contact instance object that contain objects embedded like `addresses`, `birthday`, `emails`, `name`, `org`. See this [guide](/test/contact_helper.rb) to learn how to create contacts objects.
296
- client.messages.send_contacts(sender_id: 123123, recipient_number: 56789, contacts: [create_contact(params)])
329
+ client.messages.send_contacts(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, contacts: [create_contact(params)])
297
330
 
298
331
  # Alternatively, you could pass a plain json like this:
299
- client.messages.send_contacts(sender_id: 123123, recipient_number: 56789, contacts_json: {...})
332
+ client.messages.send_contacts(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, contacts_json: {...})
300
333
 
301
334
  # Send a template message
302
335
  # WhatsApp message templates are specific message formats that businesses use to send out notifications or customer care messages to people that have opted in to notifications. Messages can include appointment reminders, shipping information, issue resolution or payment updates.
@@ -323,7 +356,7 @@ parameter_location = WhatsappSdk::Resource::ParameterObject.new(type: "location"
323
356
  header_component = WhatsappSdk::Resource::Component.new(type: "header", parameters: [parameter_image])
324
357
 
325
358
  body_component = WhatsappSdk::Resource::Component.new(
326
- type: "body",
359
+ type: "body",
327
360
  parameters: [parameter_text, parameter_currency, parameter_date_time]
328
361
  )
329
362
 
@@ -347,7 +380,7 @@ button_component2 = WhatsappSdk::Resource::Component.new(
347
380
 
348
381
  location_component = WhatsappSdk::Resource::Component.new(type: "header", parameters: [parameter_location])
349
382
  client.messages.send_template(
350
- sender_id: 12_345, recipient_number: 12345678, name: "hello_world", language: "en_US", components: [...]
383
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, name: "hello_world", language: "en_US", components: [...]
351
384
  )
352
385
  ```
353
386
 
@@ -356,7 +389,7 @@ client.messages.send_template(
356
389
  Alternatively, you could pass a plain json like this:
357
390
 
358
391
  ```ruby
359
- client.messages.send_template(sender_id: 12_345, recipient_number: 12345678, name: "hello_world", language: "en_US", components_json: [{...}])
392
+ client.messages.send_template(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, name: "hello_world", language: "en_US", components_json: [{...}])
360
393
  ```
361
394
 
362
395
  **Send interactive messages**
@@ -402,7 +435,7 @@ Alternatively, you could pass a plain json like this:
402
435
 
403
436
  ```ruby
404
437
  client.messages.send_interactive_list_messages(
405
- sender_id: 12_345, recipient_number: 1234567890
438
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER
406
439
  interactive_json: {...}
407
440
  )
408
441
  ```
@@ -437,27 +470,27 @@ interactive_reply_buttons = WhatsappSdk::Resource::Interactive.new(
437
470
  )
438
471
 
439
472
  client.messages.send_interactive_reply_buttons(
440
- sender_id: 12_345, recipient_number: 1234567890,
473
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,
441
474
  interactive: interactive_reply_buttons
442
475
  )
443
476
  ```
444
477
 
445
478
  </details>
446
479
 
447
- Alternative, you could pass a plain json like this:
480
+ Alternatively, you could pass a plain json like this:
448
481
 
449
482
  ```ruby
450
483
  client.messages.send_interactive_reply_buttons(
451
- sender_id: 12_345, recipient_number: 1234567890
484
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER
452
485
  interactive_json: {...}
453
486
  )
454
487
  ```
455
488
 
456
489
  </details>
457
490
 
458
- ### Errors
491
+ ## Errors
459
492
 
460
- If the API returns an error then an exception `WhatsappSdk::Api::Responses::HttpResponseError` is raised. The object contains information returned by the Cloud API. For more information about the potential error check the [official documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/support/error-codes/).
493
+ If the API returns an error then an exception `WhatsappSdk::Api::Responses::HttpResponseError` is raised. The object contains information returned by the Cloud API. For more information about the potential error check the [official documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/support/error-codes/).
461
494
 
462
495
  ## Examples
463
496
 
@@ -473,7 +506,7 @@ Visit [the example file](/example.rb) with examples to call the API in a single
473
506
  If you try to send a text message directly without a message template created and approved in your Meta control panel, you can't start a chat with other people. But if you receive a message before, it's possible to send a message.
474
507
 
475
508
  If the API response is still `success`, but the message is not delivered:
476
- - ensure the device you're sending the message to is using a supported Whatsapp version. [Check documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/support/troubleshooting#message-not-delivered). Try also replying a message to the number you are registered on your Whatsapp.
509
+ - Ensure the device you're sending the message to is using a supported Whatsapp version. [Check documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/support/troubleshooting#message-not-delivered). Try also replying a message to the number you are registered on your Whatsapp.
477
510
  - Ensure your Meta App uses an API version greater than or equal to `v.14`.
478
511
  - Ensure that the Panel in the Facebook dashboard doesn't display any errors.
479
512
 
@@ -483,15 +516,14 @@ Note: Sometimes the messages are delayed; see [Meta documentation](https://devel
483
516
 
484
517
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
485
518
 
486
- Run ' bundle exec rake install' to install this gem onto your local machine. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
519
+ Run `bundle exec rake install` to install this gem onto your local machine. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
487
520
 
488
521
  ### Run all the tests
489
522
 
490
523
  - **Unit tests:** Run `rake test`
491
- - **Sorbet Typecheck:** run `srb tc`
492
524
  - **Linters:** `bundle exec rubocop`
493
525
 
494
- To update the Cloud API version update the version in `lib/whatsapp_sdk/api/api_configuration.rb`. Check the [Cloud API changelog for API udpates](https://developers.facebook.com/docs/whatsapp/business-platform/changelog#api-error-response-behavior).
526
+ To update the Cloud API version update the version in `lib/whatsapp_sdk/api/api_configuration.rb`. Check the [Cloud API changelog for API updates](https://developers.facebook.com/docs/whatsapp/business-platform/changelog#api-error-response-behavior).
495
527
 
496
528
  ## Contributing
497
529
 
@@ -503,6 +535,10 @@ Do you want to contribute and are unsure where to start? Ping me on Twitter, and
503
535
 
504
536
  Check [Contributing](/CONTRIBUTING.MD) file.
505
537
 
538
+ ## Changelog
539
+
540
+ See [CHANGELOG.md](CHANGELOG.md) for a list of changes.
541
+
506
542
  ## License
507
543
 
508
544
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/example.rb CHANGED
@@ -14,6 +14,7 @@ gemfile(true) do
14
14
  gem "whatsapp_sdk", path: "../"
15
15
  gem "pry"
16
16
  gem "pry-nav"
17
+ gem "debug"
17
18
  end
18
19
 
19
20
  require 'whatsapp_sdk'
@@ -56,12 +57,8 @@ end
56
57
 
57
58
  client = WhatsappSdk::Api::Client.new
58
59
 
59
-
60
-
61
-
62
60
  # ############################## Templates API ##############################
63
61
  puts "\n\n ------------------ Testing Templates API ------------------------"
64
-
65
62
  # ## Get list of templates
66
63
  templates = client.templates.list(business_id: BUSINESS_ID)
67
64
  puts "GET Templates list : #{ templates.records.map(&:name) }"
@@ -70,6 +67,13 @@ puts "GET Templates list : #{ templates.records.map(&:name) }"
70
67
  template_namespace = client.templates.get_message_template_namespace(business_id: BUSINESS_ID)
71
68
  puts "GET template by namespace: #{template_namespace.id}"
72
69
 
70
+ ## GET
71
+ id = templates.records.first.id
72
+ if id
73
+ template = client.templates.get(template_id: id)
74
+ puts "GET template by id: #{template.id}"
75
+ end
76
+
73
77
  # Create a template
74
78
  components_json = [
75
79
  {
@@ -7,9 +7,9 @@ module WhatsappSdk
7
7
  module Api
8
8
  class Client
9
9
  API_VERSIONS = [
10
- 'v21.0', 'v20.0', 'v19.0', 'v18.0', 'v17.0', 'v16.0', 'v15.0', 'v14.0', 'v13.0', 'v12.0',
11
- 'v11.0', 'v10.0', 'v9.0', 'v8.0', 'v7.0', 'v6.0', 'v5.0', 'v4.0', 'v3.3',
12
- 'v3.2', 'v3.1', 'v3.0', 'v2.12', 'v2.11', 'v2.10', 'v2.9', 'v2.8', 'v2.7',
10
+ 'v24.0', 'v23.0', 'v22.0', 'v21.0', 'v20.0', 'v19.0', 'v18.0', 'v17.0', 'v16.0', 'v15.0', 'v14.0',
11
+ 'v13.0', 'v12.0', 'v11.0', 'v10.0', 'v9.0', 'v8.0', 'v7.0', 'v6.0', 'v5.0', 'v4.0',
12
+ 'v3.3', 'v3.2', 'v3.1', 'v3.0', 'v2.12', 'v2.11', 'v2.10', 'v2.9', 'v2.8', 'v2.7',
13
13
  'v2.6', 'v2.5', 'v2.4', 'v2.3', 'v2.2', 'v2.1'
14
14
  ].freeze
15
15
 
@@ -50,7 +50,7 @@ module WhatsappSdk
50
50
  def send_request(endpoint: "", full_url: nil, http_method: "post", params: {}, headers: {}, multipart: false)
51
51
  url = full_url || "#{ApiConfiguration::API_URL}/#{@api_version}/"
52
52
 
53
- faraday_request = faraday(url:, multipart:)
53
+ faraday_request = faraday(url: url, multipart: multipart)
54
54
 
55
55
  response = faraday_request.public_send(http_method, endpoint, request_params(params, headers), headers)
56
56
 
@@ -411,6 +411,31 @@ module WhatsappSdk
411
411
  Api::Responses::MessageDataResponse.build_from_response(response: response)
412
412
  end
413
413
 
414
+ # Send typing indicator
415
+ #
416
+ # @param sender_id [Integer] Sender' phone number.
417
+ # @param message_id [String] the id of the message received in the messages webhooks.
418
+ # @return [Hash] Response object with success status.
419
+ def send_typing_indicator(sender_id:, message_id:)
420
+ params = {
421
+ messaging_product: "whatsapp",
422
+ recipient_type: "individual",
423
+ status: "read",
424
+ message_id: message_id,
425
+ typing_indicator: {
426
+ type: "text"
427
+ }
428
+ }
429
+
430
+ response = send_request(
431
+ endpoint: endpoint(sender_id),
432
+ params: params,
433
+ headers: DEFAULT_HEADERS
434
+ )
435
+
436
+ Api::Responses::SuccessResponse.success_response?(response: response)
437
+ end
438
+
414
439
  private
415
440
 
416
441
  def endpoint(sender_id)
@@ -18,6 +18,18 @@ module WhatsappSdk
18
18
  end
19
19
  end
20
20
 
21
+ # Get a template
22
+ # @param template_id [String] Required. The template ID.
23
+ # @return [Template] Template object.
24
+ def get(template_id:)
25
+ response = send_request(
26
+ endpoint: template_id,
27
+ http_method: "get"
28
+ )
29
+
30
+ Resource::Template.from_hash(response)
31
+ end
32
+
21
33
  # Create a template
22
34
  #
23
35
  # @param business_id [Integer] Business Id.
@@ -28,11 +40,13 @@ module WhatsappSdk
28
40
  # @param components_json [Component] Components that make up the template. See the list of possible components:
29
41
  # https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/components
30
42
  # @param allow_category_change [Boolean] Optional Allow category change.
43
+ # @param parameter_format [String] Optional Parameter format. Possible values: named, positional.
31
44
  # Set to true to allow us to assign a category based on the template guidelines and the template's contents.
32
45
  # This can prevent your template from being rejected for miscategorization.
33
46
  # @return [Template] Template object.
34
47
  def create(
35
- business_id:, name:, category:, language:, components_json: nil, allow_category_change: nil
48
+ business_id:, name:, category:, language:, components_json: nil, allow_category_change: nil,
49
+ parameter_format: nil
36
50
  )
37
51
  unless WhatsappSdk::Resource::Template::Category.valid?(category)
38
52
  raise InvalidCategoryError.new(category: category)
@@ -42,6 +56,10 @@ module WhatsappSdk
42
56
  raise WhatsappSdk::Resource::Errors::InvalidLanguageError.new(language: language)
43
57
  end
44
58
 
59
+ if parameter_format && !WhatsappSdk::Resource::ParameterObject::Format.valid?(parameter_format)
60
+ raise WhatsappSdk::Resource::Errors::InvalidParameterFormatError.new(format: parameter_format)
61
+ end
62
+
45
63
  params = {
46
64
  name: name,
47
65
  category: category,
@@ -49,6 +67,7 @@ module WhatsappSdk
49
67
  components: components_json
50
68
  }
51
69
  params["allow_category_change"] = allow_category_change if allow_category_change
70
+ params["parameter_format"] = parameter_format if parameter_format
52
71
 
53
72
  response = send_request(
54
73
  endpoint: "#{business_id}/message_templates",
@@ -77,8 +96,8 @@ module WhatsappSdk
77
96
 
78
97
  Api::Responses::PaginationRecords.new(
79
98
  records: parse_templates(response['data']),
80
- before: response['paging']['cursors']['before'],
81
- after: response['paging']['cursors']['after']
99
+ before: response.dig('paging', 'cursors', 'before'),
100
+ after: response.dig('paging', 'cursors', 'after')
82
101
  )
83
102
  end
84
103
 
@@ -49,6 +49,16 @@ module WhatsappSdk
49
49
  class InvalidInteractiveActionSectionRow < Error; end
50
50
 
51
51
  class InvalidInteractiveFooter < Error; end
52
+
53
+ class InvalidParameterFormatError < StandardError
54
+ attr_reader :format
55
+
56
+ def initialize(format:)
57
+ @format = format
58
+
59
+ super("Invalid Parameter Format. The possible values are: named and positional.")
60
+ end
61
+ end
52
62
  end
53
63
  end
54
64
  end
@@ -42,6 +42,19 @@ module WhatsappSdk
42
42
  end
43
43
  end
44
44
 
45
+ module Format
46
+ NAMED = "named"
47
+ POSITIONAL = "positional"
48
+
49
+ FORMATS = [
50
+ NAMED,
51
+ POSITIONAL
52
+ ].freeze
53
+
54
+ def self.valid?(format)
55
+ FORMATS.include?(format)
56
+ end
57
+ end
45
58
  # Returns Text string if the parameter object type is text.
46
59
  # For the header component, the character limit is 60 characters.
47
60
  # For the body component, the character limit is 1024 characters.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WhatsappSdk
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatsapp_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ignacio-chiazzo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-08 00:00:00.000000000 Z
11
+ date: 2026-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -208,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
208
  - !ruby/object:Gem::Version
209
209
  version: '0'
210
210
  requirements: []
211
- rubygems_version: 3.3.3
211
+ rubygems_version: 3.4.1
212
212
  signing_key:
213
213
  specification_version: 4
214
214
  summary: Use the Ruby Whatsapp SDK to communicate with Whatsapp API using the Cloud