whatsapp_sdk 0.7.2 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78aea6934c0189c059dbce4818236b2299319a19b41e8c5ca7d0eca21e8facd3
4
- data.tar.gz: 1afd90036deb2f2f2010e2925c09f440215f5bad874d1b0038f4f65f110e1002
3
+ metadata.gz: d38079d66c6380bef5439626decde3a7051629f303308bbdb9d504b7608444c6
4
+ data.tar.gz: c7eaa83b9edc41a6044f5ddd119e381936edcd1f6c6c5430dd7de29624bb2048
5
5
  SHA512:
6
- metadata.gz: fcf1df484e0246c5d78110089208391bda6ffcaca8914b518d7b95f38b0f7ea5fb8be9c251b0cf24cb7276122b1c8ead1031b612c351697bb0cf22e0996f1c97
7
- data.tar.gz: b39fb20cc9af081b217e4478432190a3941e2d87f6abe85e69626e6891293d6065b180075160e6cf8c84a1a61442cb585a186740a984bfcefd5d650fce903627
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/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Unreleased
2
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
+
3
6
  # v 0.7.2
4
7
  - Added new fields to phone numbers API. @ignacio-chiazzo [#73](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/73)
5
8
  - Upgraded API version to v16. @ignacio-chiazzo [#73](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/73)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whatsapp_sdk (0.7.2)
4
+ whatsapp_sdk (0.7.3)
5
5
  faraday (~> 2.3.0)
6
6
  faraday-multipart (~> 1.0.4)
7
7
  oj (~> 3.13.13)
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
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,
@@ -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:)
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module WhatsappSdk
5
- VERSION = "0.7.2"
5
+ VERSION = "0.7.3"
6
6
  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: 0.7.2
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-12 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