whatsapp_sdk 0.7.1 → 0.7.3

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +233 -38
  3. data/.rubocop.yml +1 -0
  4. data/CHANGELOG.md +11 -3
  5. data/Gemfile +2 -1
  6. data/Gemfile.lock +9 -7
  7. data/README.md +11 -1
  8. data/Rakefile +1 -1
  9. data/bin/tapioca +1 -1
  10. data/example.rb +5 -0
  11. data/lib/whatsapp_sdk/api/api_configuration.rb +13 -0
  12. data/lib/whatsapp_sdk/api/business_profile.rb +1 -1
  13. data/lib/whatsapp_sdk/api/client.rb +2 -5
  14. data/lib/whatsapp_sdk/api/medias.rb +1 -1
  15. data/lib/whatsapp_sdk/api/messages.rb +61 -20
  16. data/lib/whatsapp_sdk/api/phone_numbers.rb +9 -3
  17. data/lib/whatsapp_sdk/api/request.rb +1 -1
  18. data/lib/whatsapp_sdk/api/response.rb +1 -1
  19. data/lib/whatsapp_sdk/api/responses/business_profile_data_response.rb +1 -1
  20. data/lib/whatsapp_sdk/api/responses/data_response.rb +1 -1
  21. data/lib/whatsapp_sdk/api/responses/error_response.rb +1 -1
  22. data/lib/whatsapp_sdk/api/responses/media_data_response.rb +1 -1
  23. data/lib/whatsapp_sdk/api/responses/message_data_response.rb +1 -1
  24. data/lib/whatsapp_sdk/api/responses/message_error_response.rb +1 -1
  25. data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +21 -1
  26. data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +1 -1
  27. data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +1 -1
  28. data/lib/whatsapp_sdk/api/responses/success_response.rb +1 -1
  29. data/lib/whatsapp_sdk/configuration.rb +1 -1
  30. data/lib/whatsapp_sdk/error.rb +1 -1
  31. data/lib/whatsapp_sdk/resource/address.rb +1 -1
  32. data/lib/whatsapp_sdk/resource/address_type.rb +1 -1
  33. data/lib/whatsapp_sdk/resource/button_parameter.rb +1 -1
  34. data/lib/whatsapp_sdk/resource/component.rb +1 -1
  35. data/lib/whatsapp_sdk/resource/contact.rb +1 -1
  36. data/lib/whatsapp_sdk/resource/contact_response.rb +1 -1
  37. data/lib/whatsapp_sdk/resource/currency.rb +1 -1
  38. data/lib/whatsapp_sdk/resource/date_time.rb +1 -1
  39. data/lib/whatsapp_sdk/resource/email.rb +1 -1
  40. data/lib/whatsapp_sdk/resource/media.rb +13 -5
  41. data/lib/whatsapp_sdk/resource/message.rb +1 -1
  42. data/lib/whatsapp_sdk/resource/name.rb +1 -1
  43. data/lib/whatsapp_sdk/resource/org.rb +1 -1
  44. data/lib/whatsapp_sdk/resource/parameter_object.rb +1 -1
  45. data/lib/whatsapp_sdk/resource/phone_number.rb +1 -1
  46. data/lib/whatsapp_sdk/resource/url.rb +1 -1
  47. data/lib/whatsapp_sdk/version.rb +2 -2
  48. data/lib/whatsapp_sdk.rb +1 -1
  49. data/sorbet/tapioca/require.rb +0 -1
  50. data/whatsapp_sdk.gemspec +5 -4
  51. metadata +14 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f391a609a7230a7772cf0328b570c84be187ce2c94d5f9858cb7fe3776798e4
4
- data.tar.gz: 393eebc7cbb96780d02329f9f167b4c1c904bf1e900b9bf31baef72ef2ea4de8
3
+ metadata.gz: d38079d66c6380bef5439626decde3a7051629f303308bbdb9d504b7608444c6
4
+ data.tar.gz: c7eaa83b9edc41a6044f5ddd119e381936edcd1f6c6c5430dd7de29624bb2048
5
5
  SHA512:
6
- metadata.gz: 96005fff84e2b54ae069ebc7dd49e3dcce72ce58f7269a5d20f8a9f25b29ba6fab6e42d2a1fbf33b0c8eb02b9e66663fcf8d441d86557cf5a21032906936e80c
7
- data.tar.gz: c17e00d76ca9a9bd3d9348ae95bea014241dccd101c4f224a0844f85b28c8f7d80223aac542997b006515fb8bfb90a00aa4d4ca4a6479ac74253b28cff46ed01
6
+ metadata.gz: 4f545dfd51217c6339a4b9ea423a529a95079b04be5d67e9e27f5b7d26faf0318a321af9391d82f0d10a72a0a3cd666f117d0a6fac3b25393f9cf25b8e0b51de
7
+ data.tar.gz: 711d449f1358ba11e24e82390d12804771b4402ebf392ff2a4c065682a7222e7e97c139f6ab723d6c8b1102064e86ee4960f40b88575245c01c021911b622502
@@ -1,38 +1,233 @@
1
- # This workflow uses actions that are not certified by GitHub.
2
- # They are provided by a third-party and are governed by
3
- # separate terms of service, privacy policy, and support
4
- # documentation.
5
- # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
- # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
-
8
- name: Ruby
9
-
10
- on:
11
- push:
12
- branches: [ main ]
13
- pull_request:
14
- branches: [ main ]
15
-
16
- permissions:
17
- contents: read
18
-
19
- jobs:
20
- test:
21
-
22
- runs-on: ubuntu-latest
23
- strategy:
24
- matrix:
25
- ruby-version: ['2.6', '2.7', '3.0']
26
-
27
- steps:
28
- - uses: actions/checkout@v3
29
- - name: Set up Ruby
30
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
- # uses: ruby/setup-ruby@v1
33
- uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
34
- with:
35
- ruby-version: ${{ matrix.ruby-version }}
36
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
- - name: Run tests
38
- run: bundle exec rake
1
+ # frozen_string_literal: true
2
+
3
+ # 1) Copy this code into a file and save it `example.rb`
4
+ # 2) Replace the `ACCESS_TOKEN` constant with a valid `access_token`.
5
+ # 3) Run the file with the command `ruby example.rb`
6
+
7
+ require 'bundler/inline'
8
+
9
+ gemfile(true) do
10
+ source 'https://rubygems.org'
11
+
12
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
13
+
14
+ gem "whatsapp_sdk", path: "../"
15
+ gem "pry"
16
+ gem "pry-nav"
17
+ end
18
+
19
+ require 'whatsapp_sdk'
20
+ require "pry"
21
+ require "pry-nav"
22
+
23
+ ################# UPDATE CONSTANTS #################
24
+
25
+ ACCESS_TOKEN = "EAAZAvvr0DZBs0BAF7pwQ7UEDXxNi0fn471RhslKIc2OCfsHolo2bTjISXbISUzGrUDt4NrgLWmnhiCCXSLUxIPfsBXPJYyXiz5aOpsjyj6GuZBKhM0Sf40NGxVLtgrgZAI0EIpypwwF7W5hQa54WiaZCwoQWZBnfubhvMtF9C67A00CVcI66zGVZAC95CDjfO3hiLSUx87ZCM83DRCOltbFz"
26
+ SENDER_ID = 111591145018464
27
+ RECIPIENT_NUMBER = 13437772910
28
+ BUSINESS_ID = 102261539298487
29
+ IMAGE_LINK = "<TODO replace>"
30
+
31
+ if ACCESS_TOKEN == "<TODO replace>"
32
+ puts "\n\n**** Please update the ACCESS_TOKEN constant in this file. ****\n\n"
33
+ exit
34
+ end
35
+
36
+ ################# Initialize Client #################
37
+ WhatsappSdk.configure do |config|
38
+ config.access_token = ACCESS_TOKEN
39
+ end
40
+
41
+ ################# HELPERS ########################
42
+ def print_message_sent(message_response)
43
+ if message_response.ok?
44
+ puts "Message sent to: #{message_response.data.contacts.first.input}"
45
+ else
46
+ puts "Error: #{message_response.error&.to_s}"
47
+ end
48
+ end
49
+ ##################################################
50
+
51
+ medias_api = WhatsappSdk::Api::Medias.new
52
+ messages_api = WhatsappSdk::Api::Messages.new
53
+ phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
54
+ business_profile_api = WhatsappSdk::Api::BusinessProfile.new
55
+ binding.pry
56
+
57
+ ############################## Business API ##############################
58
+ business_profile = business_profile_api.details(SENDER_ID)
59
+ business_profile_api.update(phone_number_id: SENDER_ID, params: { about: "A very cool business" } )
60
+
61
+ ############################## Phone Numbers API ##############################
62
+ registered_number = phone_numbers_api.registered_number(SENDER_ID)
63
+ registered_numbers = phone_numbers_api.registered_numbers(BUSINESS_ID)
64
+
65
+ ############################## Media API ##############################
66
+
67
+ # upload a media
68
+ uploaded_media = medias_api.upload(sender_id: SENDER_ID, file_path: "tmp/whatsapp.png", type: "image/png")
69
+ media_id = uploaded_media.data&.id
70
+ puts "Uploaded media id: #{media_id}"
71
+
72
+ # get a media
73
+ media = medias_api.media(media_id: media_id).data
74
+ puts "Media info: #{media.raw_data_response}"
75
+
76
+ # download media
77
+ download_image = medias_api.download(url: media&.url, file_path: 'tmp/downloaded_whatsapp.png')
78
+ puts "Downloaded: #{download_image.data.success?}"
79
+
80
+ # delete a media
81
+ deleted_media = medias_api.delete(media_id: media&.id)
82
+ puts "Deleted: #{deleted_media.data.success?}"
83
+
84
+ ############################## Messages API ##############################
85
+
86
+ ######### SEND A TEXT MESSAGE
87
+ message_sent = messages_api.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,
88
+ message: "Hey there! it's Whatsapp Ruby SDK")
89
+ print_message_sent(message_sent)
90
+
91
+ ######### Reply to a message
92
+ message_to_reply_id = message_sent.data.messages.first.id
93
+ reply = messages_api.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message: "GREAT WORK!!!! I'm a reply", message_id: "wamid.HBgLMTM0Mzc3NzI5MTAVAgARGBI3NzE5MjY4RTA0RDg1MDZFQTEA")
94
+ print_message_sent(reply)
95
+
96
+ ######### React to a message
97
+ message_id = message_sent.data.messages.first.id
98
+ messages_api.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: message_id, emoji: "\u{1f550}")
99
+ messages_api.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: message_id, emoji: "⛄️")
100
+
101
+ ######### Send location
102
+ location_sent = messages_api.send_location(
103
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,
104
+ longitude: -75.6898604, latitude: 45.4192206, name: "Ignacio", address: "My house"
105
+ )
106
+ print_message_sent(location_sent)
107
+
108
+ ######### READ A MESSAGE
109
+ # messages_api.read_message(sender_id: SENDER_ID, message_id: msg_id)
110
+
111
+ ######### SEND AN IMAGE
112
+ # Send an image with a link
113
+ image_sent = messages_api.send_image(
114
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: media.url, caption: "Ignacio Chiazzo Profile"
115
+ )
116
+ print_message_sent(image_sent)
117
+
118
+ # Send an image with an id
119
+ messages_api.send_image(
120
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, image_id: media.id, caption: "Ignacio Chiazzo Profile"
121
+ )
122
+
123
+ ######### SEND AUDIOS
124
+ ## with a link
125
+ messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "audio_link")
126
+
127
+ ## with an audio id
128
+ messages_api.send_audio(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, audio_id: "1234")
129
+
130
+ ######### SEND DOCUMENTS
131
+ ## with a link
132
+ messages_api.send_document(
133
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "document_link", caption: "Ignacio Chiazzo"
134
+ )
135
+
136
+ ## with a document id
137
+ messages_api.send_document(
138
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, document_id: "1234", caption: "Ignacio Chiazzo"
139
+ )
140
+
141
+ ######### SEND STICKERS
142
+ ## with a link
143
+ messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, link: "link")
144
+
145
+ ## with a sticker_id
146
+ messages_api.send_sticker(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, sticker_id: "1234")
147
+
148
+ ######### SEND A TEMPLATE
149
+ # Note: The template must have been created previously.
150
+
151
+ # Send a template with no component
152
+ response_with_object = messages_api.send_template(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,
153
+ name: "hello_world", language: "en_US", components: [])
154
+ puts response_with_object
155
+
156
+ # Send a template with components.Remember to create the template first.
157
+ header_component = WhatsappSdk::Resource::Component.new(
158
+ type: WhatsappSdk::Resource::Component::Type::Header
159
+ )
160
+
161
+ image = WhatsappSdk::Resource::Media.new(type: "image", link: "http(s)://URL", caption: "caption")
162
+ document = WhatsappSdk::Resource::Media.new(type: "document", link: "http(s)://URL", filename: "txt.rb")
163
+ video = WhatsappSdk::Resource::Media.new(type: "video", id: "123")
164
+
165
+ parameter_image = WhatsappSdk::Resource::ParameterObject.new(
166
+ type: "image",
167
+ image: image
168
+ )
169
+
170
+ parameter_document = WhatsappSdk::Resource::ParameterObject.new(
171
+ type: "document",
172
+ document: document
173
+ )
174
+
175
+ parameter_video = WhatsappSdk::Resource::ParameterObject.new(
176
+ type: "video",
177
+ video: video
178
+ )
179
+
180
+ parameter_text = WhatsappSdk::Resource::ParameterObject.new(
181
+ type: "text",
182
+ text: "I am a text"
183
+ )
184
+
185
+ header_component.add_parameter(parameter_text)
186
+ header_component.add_parameter(parameter_image)
187
+ header_component.add_parameter(parameter_video)
188
+ header_component.add_parameter(parameter_document)
189
+ header_component.to_json
190
+
191
+ body_component = WhatsappSdk::Resource::Component.new(
192
+ type: WhatsappSdk::Resource::Component::Type::Body
193
+ )
194
+ body_component.add_parameter(parameter_text)
195
+ body_component.add_parameter(parameter_image)
196
+ body_component.add_parameter(parameter_video)
197
+ body_component.add_parameter(parameter_document)
198
+ body_component.to_json
199
+
200
+ button_component_1 = WhatsappSdk::Resource::Component.new(
201
+ type: WhatsappSdk::Resource::Component::Type::Button,
202
+ index: 0,
203
+ sub_type: WhatsappSdk::Resource::Component::Subtype::QuickReply,
204
+ parameters: [WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::Payload,
205
+ payload: "payload")]
206
+ )
207
+
208
+ button_component_2 = WhatsappSdk::Resource::Component.new(
209
+ type: WhatsappSdk::Resource::Component::Type::Button,
210
+ index: 1,
211
+ sub_type: WhatsappSdk::Resource::Component::Subtype::QuickReply,
212
+ parameters: [WhatsappSdk::Resource::ButtonParameter.new(type: WhatsappSdk::Resource::ButtonParameter::Type::Payload,
213
+ payload: "payload")]
214
+ )
215
+
216
+ # Send a template with component_json
217
+ response_with_json = messages_api.send_template(
218
+ sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, name: "hello_world", language: "en_US",
219
+ components_json: [
220
+ {
221
+ "type" => "header",
222
+ "parameters" => [
223
+ {
224
+ "type" => "image",
225
+ "image" => {
226
+ "link" => "https://www.google.com/imgres?imgurl=https%3A%2F%2Fqph.cf2.quoracdn.net%2Fmain-qimg-6d977408fdd90a09a1fee7ba9e2f777c-lq&imgrefurl=https%3A%2F%2Fwww.quora.com%2FHow-can-I-find-my-WhatsApp-ID&tbnid=lDAx1vzXwqCakM&vet=12ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ..i&docid=s-DNQVCrZmhJYM&w=602&h=339&q=example%20whatsapp%20image%20id&ved=2ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ"
227
+ }
228
+ }
229
+ ]
230
+ }
231
+ ]
232
+ )
233
+ puts response_with_json
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  require:
2
2
  - rubocop-minitest
3
3
  - rubocop-performance
4
+ - rubocop-sorbet
4
5
 
5
6
  AllCops:
6
7
  NewCops: enable
data/CHANGELOG.md CHANGED
@@ -1,7 +1,15 @@
1
- # unreleased
2
-
1
+ # Unreleased
2
+
3
+ # v 0.7.3
4
+ - Added the ability to reply messages. @alienware [#77](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/77)
5
+
6
+ # v 0.7.2
7
+ - Added new fields to phone numbers API. @ignacio-chiazzo [#73](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/73)
8
+ - Upgraded API version to v16. @ignacio-chiazzo [#73](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/73)
9
+ - Make sorbet-runtime a runtime dependency. @ignacio-chiazzo [#70](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/70)
10
+
3
11
  # v 0.7.1
4
- Add Register API [#65](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/65)
12
+ Add Register API @andresyebra [#65](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/65)
5
13
 
6
14
  # v 0.7.0
7
15
  Add message reaction @sanchezpaco [#58](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/58)
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: true
2
+ # frozen_string_literal: true
3
3
 
4
4
  source "https://rubygems.org"
5
5
 
@@ -17,6 +17,7 @@ group(:test) do
17
17
  gem('rubocop', require: false)
18
18
  gem('rubocop-minitest', require: false)
19
19
  gem('rubocop-performance', require: false)
20
+ gem('rubocop-sorbet', require: false)
20
21
  gem('webmock')
21
22
  end
22
23
 
data/Gemfile.lock CHANGED
@@ -1,12 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whatsapp_sdk (0.7.0)
5
- faraday (>= 2.3.0)
4
+ whatsapp_sdk (0.7.3)
5
+ faraday (~> 2.3.0)
6
6
  faraday-multipart (~> 1.0.4)
7
7
  oj (~> 3.13.13)
8
- sorbet
9
- sorbet-runtime
8
+ sorbet-runtime (~> 0.5.1)
10
9
  zeitwerk (~> 2.6.0)
11
10
 
12
11
  GEM
@@ -19,12 +18,12 @@ GEM
19
18
  crack (0.4.5)
20
19
  rexml
21
20
  diff-lcs (1.5.0)
22
- faraday (2.5.2)
23
- faraday-net_http (>= 2.0, < 3.1)
21
+ faraday (2.3.0)
22
+ faraday-net_http (~> 2.0)
24
23
  ruby2_keywords (>= 0.0.4)
25
24
  faraday-multipart (1.0.4)
26
25
  multipart-post (~> 2)
27
- faraday-net_http (3.0.0)
26
+ faraday-net_http (2.1.0)
28
27
  hashdiff (1.0.1)
29
28
  method_source (1.0.0)
30
29
  minitest (5.16.1)
@@ -66,6 +65,8 @@ GEM
66
65
  rubocop-performance (1.14.2)
67
66
  rubocop (>= 1.7.0, < 2.0)
68
67
  rubocop-ast (>= 0.4.0)
68
+ rubocop-sorbet (0.7.0)
69
+ rubocop (>= 0.90.0)
69
70
  ruby-progressbar (1.11.0)
70
71
  ruby2_keywords (0.0.5)
71
72
  sorbet (0.5.10346)
@@ -125,6 +126,7 @@ DEPENDENCIES
125
126
  rubocop
126
127
  rubocop-minitest
127
128
  rubocop-performance
129
+ rubocop-sorbet
128
130
  sorbet
129
131
  sorbet-runtime
130
132
  spoom
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <a href="https://codeclimate.com/github/ignacio-chiazzo/ruby_whatsapp_sdk/maintainability"><img src="https://api.codeclimate.com/v1/badges/169cce95450272e4ad7d/maintainability" /></a>
5
5
 
6
6
  The SDK provides a set of operations and classes to use the Whatsapp API.
7
- Send stickers, messages, audio, videos, locations, react to messages or just ask for the phone numbers through this library in a few steps!
7
+ 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!
8
8
 
9
9
 
10
10
  ## Demo
@@ -218,6 +218,13 @@ messages_api.send_reaction(sender_id: 123_123, recipient_number: 56_789, message
218
218
  messages_api.send_reaction(sender_id: 123_123, recipient_number: 56_789, message_id: "12345", emoji: "⛄️")
219
219
  ```
220
220
 
221
+ **Reply to a message**
222
+ To reply to a message, just include the id of the message in the `messages_api` methods. For example, to reply to a text message include the following:
223
+
224
+ ```ruby
225
+ messages_api.send_text(sender_id: 123_123, recipient_number: 56_789, message: "I'm a reply", message_id: "wamid.1234")
226
+ ```
227
+
221
228
  **Send a location message**
222
229
 
223
230
  ```ruby
@@ -373,6 +380,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
373
380
  - **Sorbet Typecheck:** run `srb tc`
374
381
  - **Linters:** `bundle exec rubocop`
375
382
 
383
+
384
+ 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).
385
+
376
386
  ## Contributing
377
387
 
378
388
  Bug reports and pull requests are welcome on GitHub at [https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk) This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: true
2
+ # frozen_string_literal: true
3
3
 
4
4
  require "bundler/gem_tasks"
5
5
  require "rake/testtask"
data/bin/tapioca CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
2
  # typed: true
3
+ # frozen_string_literal: true
4
4
 
5
5
  #
6
6
  # This file was generated by Bundler.
data/example.rb CHANGED
@@ -92,6 +92,11 @@ message_id = message_sent.data.messages.first.id
92
92
  messages_api.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: message_id, emoji: "\u{1f550}")
93
93
  messages_api.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: message_id, emoji: "⛄️")
94
94
 
95
+ ######### Reply to a message
96
+ message_to_reply_id = message_sent.data.messages.first.id
97
+ reply = messages_api.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message: "GREAT WORK!!!! I'm a reply", message_id: message_to_reply_id)
98
+ print_message_sent(reply)
99
+
95
100
  ######### Send location
96
101
  location_sent = messages_api.send_location(
97
102
  sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,
@@ -0,0 +1,13 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module WhatsappSdk
5
+ module Api
6
+ module ApiConfiguration
7
+ extend T::Sig
8
+
9
+ API_VERSION = T.let("v16.0", String)
10
+ API_URL = T.let("https://graph.facebook.com/#{API_VERSION}/", String)
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "request"
5
5
  require_relative "response"
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require "faraday"
5
5
  require "faraday/multipart"
@@ -10,9 +10,6 @@ module WhatsappSdk
10
10
  class Client
11
11
  extend T::Sig
12
12
 
13
- API_VERSION = T.let("v14.0", String)
14
- API_CLIENT = T.let("https://graph.facebook.com/#{API_VERSION}/", String)
15
-
16
13
  sig { params(access_token: String).void }
17
14
  def initialize(access_token)
18
15
  @access_token = access_token
@@ -28,7 +25,7 @@ module WhatsappSdk
28
25
  ).returns(T.nilable(T::Hash[T.untyped, T.untyped]))
29
26
  end
30
27
  def send_request(endpoint: "", full_url: nil, http_method: "post", params: {}, headers: {})
31
- url = full_url || API_CLIENT
28
+ url = full_url || ApiConfiguration::API_URL
32
29
 
33
30
  faraday_request = T.unsafe(faraday(url))
34
31
 
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require "faraday"
5
5
  require "faraday/multipart"
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "request"
5
5
  require_relative "response"
@@ -9,7 +9,7 @@ module WhatsappSdk
9
9
  class Messages < Request
10
10
  extend T::Sig
11
11
 
12
- DEFAULT_HEADERS = T.let({ 'Content-Type' => 'application/json' }, Hash)
12
+ DEFAULT_HEADERS = T.let({ 'Content-Type' => 'application/json' }.freeze, Hash)
13
13
 
14
14
  class MissingArgumentError < StandardError
15
15
  extend T::Sig
@@ -29,9 +29,15 @@ module WhatsappSdk
29
29
  # @param sender_id [Integer] Sender' phone number.
30
30
  # @param recipient_number [Integer] Recipient' Phone number.
31
31
  # @param message [String] Text to send.
32
+ # @param message_id [String] The id of the message to reply to.
32
33
  # @return [WhatsappSdk::Api::Response] Response object.
33
- sig { params(sender_id: Integer, recipient_number: Integer, message: String).returns(WhatsappSdk::Api::Response) }
34
- def send_text(sender_id:, recipient_number:, message:)
34
+ sig do
35
+ params(
36
+ sender_id: Integer, recipient_number: Integer, message: String,
37
+ message_id: T.nilable(String)
38
+ ).returns(WhatsappSdk::Api::Response)
39
+ end
40
+ def send_text(sender_id:, recipient_number:, message:, message_id: nil)
35
41
  params = {
36
42
  messaging_product: "whatsapp",
37
43
  to: recipient_number,
@@ -39,6 +45,7 @@ module WhatsappSdk
39
45
  type: "text",
40
46
  text: { body: message }
41
47
  }
48
+ params[:context] = { message_id: message_id } if message_id
42
49
 
43
50
  response = send_request(
44
51
  endpoint: endpoint(sender_id),
@@ -60,14 +67,18 @@ module WhatsappSdk
60
67
  # @param latitude [Float] Location latitude.
61
68
  # @param name [String] Location name.
62
69
  # @param address [String] Location address.
70
+ # @param message_id [String] The id of the message to reply to.
63
71
  # @return [WhatsappSdk::Api::Response] Response object.
64
72
  sig do
65
73
  params(
66
74
  sender_id: Integer, recipient_number: Integer,
67
- longitude: Float, latitude: Float, name: String, address: String
75
+ longitude: Float, latitude: Float, name: String, address: String,
76
+ message_id: T.nilable(String)
68
77
  ).returns(WhatsappSdk::Api::Response)
69
78
  end
70
- def send_location(sender_id:, recipient_number:, longitude:, latitude:, name:, address:)
79
+ def send_location(
80
+ sender_id:, recipient_number:, longitude:, latitude:, name:, address:, message_id: nil
81
+ )
71
82
  params = {
72
83
  messaging_product: "whatsapp",
73
84
  to: recipient_number,
@@ -80,6 +91,7 @@ module WhatsappSdk
80
91
  address: address
81
92
  }
82
93
  }
94
+ params[:context] = { message_id: message_id } if message_id
83
95
 
84
96
  response = send_request(
85
97
  endpoint: endpoint(sender_id),
@@ -100,14 +112,18 @@ module WhatsappSdk
100
112
  # @param image_id [String] Image ID.
101
113
  # @param link [String] Image link.
102
114
  # @param caption [String] Image caption.
115
+ # @param message_id [String] The id of the message to reply to.
103
116
  # @return [WhatsappSdk::Api::Response] Response object.
104
117
  sig do
105
118
  params(
106
119
  sender_id: Integer, recipient_number: Integer, image_id: T.nilable(String),
107
- link: T.nilable(String), caption: T.nilable(String)
120
+ link: T.nilable(String), caption: T.nilable(String),
121
+ message_id: T.nilable(String)
108
122
  ).returns(WhatsappSdk::Api::Response)
109
123
  end
110
- def send_image(sender_id:, recipient_number:, image_id: nil, link: nil, caption: "")
124
+ def send_image(
125
+ sender_id:, recipient_number:, image_id: nil, link: nil, caption: "", message_id: nil
126
+ )
111
127
  raise MissingArgumentError, "image_id or link is required" if !image_id && !link
112
128
 
113
129
  params = {
@@ -121,6 +137,7 @@ module WhatsappSdk
121
137
  else
122
138
  { id: image_id, caption: caption }
123
139
  end
140
+ params[:context] = { message_id: message_id } if message_id
124
141
 
125
142
  response = send_request(
126
143
  endpoint: endpoint(sender_id),
@@ -140,13 +157,15 @@ module WhatsappSdk
140
157
  # @param recipient_number [Integer] Recipient' Phone number.
141
158
  # @param audio_id [String] Audio ID.
142
159
  # @param link [String] Audio link.
160
+ # @param message_id [String] The id of the message to reply to.
143
161
  # @return [WhatsappSdk::Api::Response] Response object.
144
162
  sig do
145
163
  params(
146
- sender_id: Integer, recipient_number: Integer, audio_id: T.nilable(String), link: T.nilable(String)
164
+ sender_id: Integer, recipient_number: Integer, audio_id: T.nilable(String),
165
+ link: T.nilable(String), message_id: T.nilable(String)
147
166
  ).returns(WhatsappSdk::Api::Response)
148
167
  end
149
- def send_audio(sender_id:, recipient_number:, audio_id: nil, link: nil)
168
+ def send_audio(sender_id:, recipient_number:, audio_id: nil, link: nil, message_id: nil)
150
169
  raise MissingArgumentError, "audio_id or link is required" if !audio_id && !link
151
170
 
152
171
  params = {
@@ -156,6 +175,7 @@ module WhatsappSdk
156
175
  type: "audio"
157
176
  }
158
177
  params[:audio] = link ? { link: link } : { id: audio_id }
178
+ params[:context] = { message_id: message_id } if message_id
159
179
 
160
180
  response = send_request(
161
181
  endpoint: endpoint(sender_id),
@@ -176,14 +196,18 @@ module WhatsappSdk
176
196
  # @param video_id [String] Video ID.
177
197
  # @param link [String] Image link.
178
198
  # @param caption [String] Image caption.
199
+ # @param message_id [String] The id of the message to reply to.
179
200
  # @return [WhatsappSdk::Api::Response] Response object.
180
201
  sig do
181
202
  params(
182
203
  sender_id: Integer, recipient_number: Integer,
183
- video_id: T.nilable(String), link: T.nilable(String), caption: String
204
+ video_id: T.nilable(String), link: T.nilable(String), caption: String,
205
+ message_id: T.nilable(String)
184
206
  ).returns(WhatsappSdk::Api::Response)
185
207
  end
186
- def send_video(sender_id:, recipient_number:, video_id: nil, link: nil, caption: "")
208
+ def send_video(
209
+ sender_id:, recipient_number:, video_id: nil, link: nil, caption: "", message_id: nil
210
+ )
187
211
  raise MissingArgumentError, "video_id or link is required" if !video_id && !link
188
212
 
189
213
  params = {
@@ -197,6 +221,7 @@ module WhatsappSdk
197
221
  else
198
222
  { id: video_id, caption: caption }
199
223
  end
224
+ params[:context] = { message_id: message_id } if message_id
200
225
 
201
226
  response = send_request(
202
227
  endpoint: endpoint(sender_id),
@@ -217,14 +242,18 @@ module WhatsappSdk
217
242
  # @param document_id [String] document ID.
218
243
  # @param link [String] Image link.
219
244
  # @param caption [String] Image caption.
245
+ # @param message_id [String] The id of the message to reply to.
220
246
  # @return [WhatsappSdk::Api::Response] Response object.
221
247
  sig do
222
248
  params(
223
249
  sender_id: Integer, recipient_number: Integer,
224
- document_id: T.nilable(String), link: T.nilable(String), caption: String
250
+ document_id: T.nilable(String), link: T.nilable(String), caption: String,
251
+ message_id: T.nilable(String)
225
252
  ).returns(WhatsappSdk::Api::Response)
226
253
  end
227
- def send_document(sender_id:, recipient_number:, document_id: nil, link: nil, caption: "")
254
+ def send_document(
255
+ sender_id:, recipient_number:, document_id: nil, link: nil, caption: "", message_id: nil
256
+ )
228
257
  raise MissingArgumentError, "document or link is required" if !document_id && !link
229
258
 
230
259
  params = {
@@ -238,6 +267,7 @@ module WhatsappSdk
238
267
  else
239
268
  { id: document_id, caption: caption }
240
269
  end
270
+ params[:context] = { message_id: message_id } if message_id
241
271
 
242
272
  response = send_request(
243
273
  endpoint: endpoint(sender_id),
@@ -257,13 +287,15 @@ module WhatsappSdk
257
287
  # @param recipient_number [Integer] Recipient' Phone number.
258
288
  # @param sticker_id [String] The sticker ID.
259
289
  # @param link [String] Image link.
290
+ # @param message_id [String] The id of the message to reply to.
260
291
  # @return [WhatsappSdk::Api::Response] Response object.
261
292
  sig do
262
293
  params(
263
- sender_id: Integer, recipient_number: Integer, sticker_id: T.nilable(String), link: T.nilable(String)
294
+ sender_id: Integer, recipient_number: Integer, sticker_id: T.nilable(String),
295
+ link: T.nilable(String), message_id: T.nilable(String)
264
296
  ).returns(WhatsappSdk::Api::Response)
265
297
  end
266
- def send_sticker(sender_id:, recipient_number:, sticker_id: nil, link: nil)
298
+ def send_sticker(sender_id:, recipient_number:, sticker_id: nil, link: nil, message_id: nil)
267
299
  raise MissingArgumentError, "sticker or link is required" if !sticker_id && !link
268
300
 
269
301
  params = {
@@ -273,6 +305,7 @@ module WhatsappSdk
273
305
  type: Resource::Media::Type::Sticker
274
306
  }
275
307
  params[:sticker] = link ? { link: link } : { id: sticker_id }
308
+ params[:context] = { message_id: message_id } if message_id
276
309
 
277
310
  response = send_request(
278
311
  endpoint: endpoint(sender_id),
@@ -293,14 +326,18 @@ module WhatsappSdk
293
326
  # @param recipient_number [Integer] Recipient' Phone number.
294
327
  # @param contacts [Array<Contact>] Contacts.
295
328
  # @param contacts_json [Json] Contacts.
329
+ # @param message_id [String] The id of the message to reply to.
296
330
  # @return [WhatsappSdk::Api::Response] Response object.
297
331
  sig do
298
332
  params(
299
333
  sender_id: Integer, recipient_number: Integer,
300
- contacts: T.nilable(T::Array[WhatsappSdk::Resource::Contact]), contacts_json: T::Hash[T.untyped, T.untyped]
334
+ contacts: T.nilable(T::Array[WhatsappSdk::Resource::Contact]),
335
+ contacts_json: T::Hash[T.untyped, T.untyped], message_id: T.nilable(String)
301
336
  ).returns(WhatsappSdk::Api::Response)
302
337
  end
303
- def send_contacts(sender_id:, recipient_number:, contacts: nil, contacts_json: {})
338
+ def send_contacts(
339
+ sender_id:, recipient_number:, contacts: nil, contacts_json: {}, message_id: nil
340
+ )
304
341
  params = {
305
342
  messaging_product: "whatsapp",
306
343
  to: recipient_number,
@@ -308,6 +345,7 @@ module WhatsappSdk
308
345
  type: "contacts"
309
346
  }
310
347
  params[:contacts] = contacts ? contacts.map(&:to_h) : contacts_json
348
+ params[:context] = { message_id: message_id } if message_id
311
349
 
312
350
  response = send_request(
313
351
  endpoint: endpoint(sender_id),
@@ -374,7 +412,9 @@ module WhatsappSdk
374
412
  components_json: T.nilable(T::Array[T::Hash[T.untyped, T.untyped]])
375
413
  ).returns(WhatsappSdk::Api::Response)
376
414
  end
377
- def send_template(sender_id:, recipient_number:, name:, language:, components: nil, components_json: nil)
415
+ def send_template(
416
+ sender_id:, recipient_number:, name:, language:, components: nil, components_json: nil
417
+ )
378
418
  raise MissingArgumentError, "components or components_json is required" if !components && !components_json
379
419
 
380
420
  params = {
@@ -415,7 +455,8 @@ module WhatsappSdk
415
455
  # @return [WhatsappSdk::Api::Response] Response object.
416
456
  sig do
417
457
  params(
418
- sender_id: Integer, recipient_number: Integer, message_id: String, emoji: T.any(String, Integer)
458
+ sender_id: Integer, recipient_number: Integer, message_id: String,
459
+ emoji: T.any(String, Integer)
419
460
  ).returns(WhatsappSdk::Api::Response)
420
461
  end
421
462
  def send_reaction(sender_id:, recipient_number:, message_id:, emoji:)
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "request"
5
5
  require_relative "response"
@@ -7,6 +7,12 @@ require_relative "response"
7
7
  module WhatsappSdk
8
8
  module Api
9
9
  class PhoneNumbers < Request
10
+ DEFAULT_FIELDS = %i[
11
+ id is_official_business_account display_phone_number verified_name account_mode quality_rating
12
+ certificate code_verification_status eligibility_for_api_business_global_search is_pin_enabled
13
+ name_status new_name_status status search_visibility messaging_limit_tier
14
+ ].join(",").freeze
15
+
10
16
  # Get list of registered numbers.
11
17
  #
12
18
  # @param business_id [Integer] Business Id.
@@ -15,7 +21,7 @@ module WhatsappSdk
15
21
  def registered_numbers(business_id)
16
22
  response = send_request(
17
23
  http_method: "get",
18
- endpoint: "#{business_id}/phone_numbers"
24
+ endpoint: "#{business_id}/phone_numbers?fields=#{DEFAULT_FIELDS}"
19
25
  )
20
26
 
21
27
  WhatsappSdk::Api::Response.new(
@@ -32,7 +38,7 @@ module WhatsappSdk
32
38
  def registered_number(phone_number_id)
33
39
  response = send_request(
34
40
  http_method: "get",
35
- endpoint: phone_number_id.to_s
41
+ endpoint: "#{phone_number_id}?fields=#{DEFAULT_FIELDS}"
36
42
  )
37
43
 
38
44
  WhatsappSdk::Api::Response.new(
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: true
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Api
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "responses/message_data_response"
5
5
  require_relative "responses/phone_number_data_response"
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "data_response"
5
5
 
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Api
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "data_response"
5
5
 
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "data_response"
5
5
 
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "../request"
5
5
  require_relative "data_response"
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "error_response"
5
5
 
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "data_response"
5
5
 
@@ -19,12 +19,32 @@ module WhatsappSdk
19
19
  sig { returns(String) }
20
20
  attr_accessor :quality_rating
21
21
 
22
+ sig { returns(T::Boolean) }
23
+ attr_accessor :is_pin_enabled, :is_official_business_account
24
+
25
+ sig { returns(T.nilable(String)) }
26
+ attr_accessor :account_mode, :code_verification_status, :eligibility_for_api_business_global_search,
27
+ :certificate, :name_status, :new_name_status, :status, :search_visibility
28
+
22
29
  sig { params(response: T::Hash[T.untyped, T.untyped]).void }
23
30
  def initialize(response)
24
31
  @id = T.let(response["id"], String)
25
32
  @verified_name = T.let(response["verified_name"], String)
26
33
  @display_phone_number = T.let(response["display_phone_number"], String)
27
34
  @quality_rating = T.let(response["quality_rating"], String)
35
+ @is_pin_enabled = T.let(response["is_pin_enabled"], T::Boolean)
36
+ @is_official_business_account = T.let(response["is_official_business_account"], T.nilable(T::Boolean))
37
+ @account_mode = T.let(response["account_mode"], T.nilable(String))
38
+ @certificate = T.let(response["certificate"], T.nilable(String))
39
+ @code_verification_status = T.let(response["code_verification_status"], T.nilable(String))
40
+ @eligibility_for_api_business_global_search = T.let(response["eligibility_for_api_business_global_search"],
41
+ T.nilable(String))
42
+ @name_status = T.let(response["name_status"], T.nilable(String))
43
+ @new_name_status = T.let(response["new_name_status"], T.nilable(String))
44
+ @status = T.let(response["status"], T.nilable(String))
45
+ @search_visibility = T.let(response["search_visibility"], T.nilable(String))
46
+ @messaging_limit_tier = T.let(response["messaging_limit_tier"], T.nilable(String))
47
+
28
48
  super(response)
29
49
  end
30
50
 
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "data_response"
5
5
  require_relative "phone_number_data_response"
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "../request"
5
5
  require_relative "data_response"
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative "data_response"
5
5
 
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  # This module allows client instantiating the client as a singleton like the following example:
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  class Error < StandardError; end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -100,16 +100,24 @@ module WhatsappSdk
100
100
 
101
101
  sig { returns(T::Boolean) }
102
102
  def validate_media
103
- if filename && (type != Type::Document)
104
- raise InvalidMedia.new(:filename, "filename can only be used with document")
105
- end
103
+ raise InvalidMedia.new(:filename, "filename can only be used with document") if filename && !supports_filename?
106
104
 
107
- if caption && !(type == Type::Document || type == Type::Image)
105
+ if caption && !supports_caption?
108
106
  raise InvalidMedia.new(:caption, "caption can only be used with document or image")
109
107
  end
110
108
 
111
109
  true
112
110
  end
111
+
112
+ sig { returns(T::Boolean) }
113
+ def supports_filename?
114
+ type == Type::Document
115
+ end
116
+
117
+ sig { returns(T::Boolean) }
118
+ def supports_caption?
119
+ type == Type::Document || type == Type::Image
120
+ end
113
121
  end
114
122
  end
115
123
  end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
5
  module Resource
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
1
  # typed: strict
2
+ # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
- VERSION = "0.7.1"
5
+ VERSION = "0.7.3"
6
6
  end
data/lib/whatsapp_sdk.rb CHANGED
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: true
2
+ # frozen_string_literal: true
3
3
 
4
4
  require "zeitwerk"
5
5
  require "faraday"
@@ -1,5 +1,4 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
- # typed: true
4
3
 
5
4
  # Add your extra requires here (`bin/tapioca require` can be used to boostrap this list)
data/whatsapp_sdk.gemspec CHANGED
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
1
  # typed: true
2
+ # frozen_string_literal: true
3
3
 
4
4
  require_relative 'lib/whatsapp_sdk/version'
5
5
 
@@ -43,10 +43,11 @@ Gem::Specification.new do |spec|
43
43
  spec.add_development_dependency "bundler", "~> 2.3"
44
44
  spec.add_development_dependency "minitest", "~> 5.0"
45
45
  spec.add_development_dependency "rake", "~> 12.3.3"
46
- spec.add_dependency('sorbet')
47
- spec.add_dependency('sorbet-runtime')
46
+ spec.add_development_dependency('sorbet', "~>0.5.1")
47
+
48
+ spec.add_runtime_dependency('sorbet-runtime', "~>0.5.1")
48
49
 
49
- spec.add_dependency("faraday", ">= 2.3.0")
50
+ spec.add_dependency("faraday", "~> 2.3.0")
50
51
  spec.add_dependency("faraday-multipart", "~> 1.0.4")
51
52
  spec.add_dependency("oj", "~> 3.13.13")
52
53
  spec.add_dependency("zeitwerk", "~> 2.6.0")
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: 0.7.1
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ignacio-chiazzo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-11 00:00:00.000000000 Z
11
+ date: 2023-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,42 +56,42 @@ dependencies:
56
56
  name: sorbet
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
61
+ version: 0.5.1
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.5.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sorbet-runtime
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.5.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.5.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: faraday
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 2.3.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.3.0
97
97
  - !ruby/object:Gem::Dependency
@@ -166,6 +166,7 @@ files:
166
166
  - bin/tapioca
167
167
  - example.rb
168
168
  - lib/whatsapp_sdk.rb
169
+ - lib/whatsapp_sdk/api/api_configuration.rb
169
170
  - lib/whatsapp_sdk/api/business_profile.rb
170
171
  - lib/whatsapp_sdk/api/client.rb
171
172
  - lib/whatsapp_sdk/api/medias.rb