whatsapp_sdk 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +8 -3
- data/lib/version.rb +1 -1
- data/lib/whatsapp_sdk/api/messages.rb +80 -0
- data/lib/whatsapp_sdk/api/phone_numbers.rb +8 -0
- data/lib/whatsapp_sdk/api/response.rb +4 -1
- data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +27 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 789c30c096735aa557c643a11a810990c8bc2c207360bee7d0b0e9710f2de60c
|
4
|
+
data.tar.gz: 66bf61944f214767a8feae139e62d544be51c10e32895b33ca5239b3b1582009
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc2eef92ce66f87374e1f2fb0f5cfb01f9bbf5814ae80d625403660fd1fc9d834680fb72a06941c8d66f0fb30e9dabe5561231c4547cc2fd1daf651300b93193
|
7
|
+
data.tar.gz: fe548e9bfee0913a4eca4b1675342c565d35821e5d7b384908eebc0073b03616d7bc762ca8afefd1284dd6bd6ddffe88904b339e6448622b7675f09e68ed62e9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Send stickers, messages, audio, videos, locations or just ask for the phone numb
|
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem '
|
11
|
+
gem 'whatsapp_sdk'
|
12
12
|
```
|
13
13
|
|
14
14
|
And then execute:
|
@@ -17,7 +17,7 @@ And then execute:
|
|
17
17
|
|
18
18
|
Or install it yourself as:
|
19
19
|
|
20
|
-
$ gem install
|
20
|
+
$ gem install whatsapp_sdk
|
21
21
|
|
22
22
|
## Quick Start
|
23
23
|
|
@@ -143,7 +143,7 @@ gemfile(true) do
|
|
143
143
|
|
144
144
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
145
145
|
|
146
|
-
gem "whatsapp_sdk"
|
146
|
+
gem "whatsapp_sdk"
|
147
147
|
gem "pry"
|
148
148
|
gem "pry-nav"
|
149
149
|
end
|
@@ -210,6 +210,11 @@ binding.pry
|
|
210
210
|
```
|
211
211
|
</details>
|
212
212
|
|
213
|
+
## Whatsapp Cloud API
|
214
|
+
|
215
|
+
- See the [official documentation](https://developers.facebook.com/docs/whatsapp/cloud-api) for the Whatsapp Cloud API.
|
216
|
+
- For pricing, refer to the [official documentation](https://developers.facebook.com/docs/whatsapp/pricing/). As of today, Whatsapp offers have 1000 conversations free per month.
|
217
|
+
|
213
218
|
## Development
|
214
219
|
|
215
220
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
|
data/lib/version.rb
CHANGED
@@ -15,6 +15,12 @@ module WhatsappSdk
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
# Send a text message.
|
19
|
+
#
|
20
|
+
# @param sender_id [Integer] Sender' phone number.
|
21
|
+
# @param recipient_number [Integer] Recipient' Phone number.
|
22
|
+
# @param message [String] Text to send.
|
23
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
18
24
|
def send_text(sender_id:, recipient_number:, message:)
|
19
25
|
params = {
|
20
26
|
messaging_product: "whatsapp",
|
@@ -32,6 +38,15 @@ module WhatsappSdk
|
|
32
38
|
WhatsappSdk::Api::Response.new(response: response, class_type: WhatsappSdk::Api::Responses::MessageDataResponse)
|
33
39
|
end
|
34
40
|
|
41
|
+
# Send location.
|
42
|
+
#
|
43
|
+
# @param sender_id [Integer] Sender' phone number.
|
44
|
+
# @param recipient_number [Integer] Recipient' Phone number.
|
45
|
+
# @param longitude [Float] Location longitude.
|
46
|
+
# @param latitude [Float] Location latitude.
|
47
|
+
# @param name [String] Location name.
|
48
|
+
# @param address [String] Location address.
|
49
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
35
50
|
def send_location(sender_id:, recipient_number:, longitude:, latitude:, name:, address:)
|
36
51
|
params = {
|
37
52
|
messaging_product: "whatsapp",
|
@@ -54,6 +69,14 @@ module WhatsappSdk
|
|
54
69
|
WhatsappSdk::Api::Response.new(response: response, class_type: WhatsappSdk::Api::Responses::MessageDataResponse)
|
55
70
|
end
|
56
71
|
|
72
|
+
# Send an image.
|
73
|
+
#
|
74
|
+
# @param sender_id [Integer] Sender' phone number.
|
75
|
+
# @param recipient_number [Integer] Recipient' Phone number.
|
76
|
+
# @param image_id [Integer] Image ID.
|
77
|
+
# @param link [String] Image link.
|
78
|
+
# @param caption [String] Image caption.
|
79
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
57
80
|
def send_image(sender_id:, recipient_number:, image_id: nil, link: nil, caption: "")
|
58
81
|
raise MissingArgumentError, "image_id or link is required" if !image_id && !link
|
59
82
|
|
@@ -77,6 +100,13 @@ module WhatsappSdk
|
|
77
100
|
WhatsappSdk::Api::Response.new(response: response, class_type: WhatsappSdk::Api::Responses::MessageDataResponse)
|
78
101
|
end
|
79
102
|
|
103
|
+
# Send an audio.
|
104
|
+
#
|
105
|
+
# @param sender_id [Integer] Sender' phone number.
|
106
|
+
# @param recipient_number [Integer] Recipient' Phone number.
|
107
|
+
# @param audio_id [Integer] Audio ID.
|
108
|
+
# @param link [String] Audio link.
|
109
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
80
110
|
def send_audio(sender_id:, recipient_number:, audio_id: nil, link: nil)
|
81
111
|
raise MissingArgumentError, "audio_id or link is required" if !audio_id && !link
|
82
112
|
|
@@ -96,6 +126,14 @@ module WhatsappSdk
|
|
96
126
|
WhatsappSdk::Api::Response.new(response: response, class_type: WhatsappSdk::Api::Responses::MessageDataResponse)
|
97
127
|
end
|
98
128
|
|
129
|
+
# Send a video.
|
130
|
+
#
|
131
|
+
# @param sender_id [Integer] Sender' phone number.
|
132
|
+
# @param recipient_number [Integer] Recipient' Phone number.
|
133
|
+
# @param video_id [Integer] Video ID.
|
134
|
+
# @param link [String] Image link.
|
135
|
+
# @param caption [String] Image caption.
|
136
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
99
137
|
def send_video(sender_id:, recipient_number:, video_id: nil, link: nil, caption: "")
|
100
138
|
raise MissingArgumentError, "video_id or link is required" if !video_id && !link
|
101
139
|
|
@@ -119,6 +157,14 @@ module WhatsappSdk
|
|
119
157
|
WhatsappSdk::Api::Response.new(response: response, class_type: WhatsappSdk::Api::Responses::MessageDataResponse)
|
120
158
|
end
|
121
159
|
|
160
|
+
# Send a document.
|
161
|
+
#
|
162
|
+
# @param sender_id [Integer] Sender' phone number.
|
163
|
+
# @param recipient_number [Integer] Recipient' Phone number.
|
164
|
+
# @param document_id [Integer] document ID.
|
165
|
+
# @param link [String] Image link.
|
166
|
+
# @param caption [String] Image caption.
|
167
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
122
168
|
def send_document(sender_id:, recipient_number:, document_id: nil, link: nil, caption: "")
|
123
169
|
raise MissingArgumentError, "document or link is required" if !document_id && !link
|
124
170
|
|
@@ -142,6 +188,12 @@ module WhatsappSdk
|
|
142
188
|
WhatsappSdk::Api::Response.new(response: response, class_type: WhatsappSdk::Api::Responses::MessageDataResponse)
|
143
189
|
end
|
144
190
|
|
191
|
+
# Send a document.
|
192
|
+
#
|
193
|
+
# @param sender_id [Integer] Sender' phone number.
|
194
|
+
# @param recipient_number [Integer] Recipient' Phone number.
|
195
|
+
# @param link [String] Image link.
|
196
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
145
197
|
def send_sticker(sender_id:, recipient_number:, sticker_id: nil, link: nil)
|
146
198
|
raise MissingArgumentError, "sticker or link is required" if !sticker_id && !link
|
147
199
|
|
@@ -161,6 +213,14 @@ module WhatsappSdk
|
|
161
213
|
WhatsappSdk::Api::Response.new(response: response, class_type: WhatsappSdk::Api::Responses::MessageDataResponse)
|
162
214
|
end
|
163
215
|
|
216
|
+
# Send contacts.
|
217
|
+
# You can either send contacts objects or contacts as JSON.
|
218
|
+
#
|
219
|
+
# @param sender_id [Integer] Sender' phone number.
|
220
|
+
# @param recipient_number [Integer] Recipient' Phone number.
|
221
|
+
# @param contacts [Array<Contact>] Contacts.
|
222
|
+
# @param contacts_json [Json] Contacts.
|
223
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
164
224
|
def send_contacts(sender_id:, recipient_number:, contacts: nil, contacts_json: {})
|
165
225
|
params = {
|
166
226
|
messaging_product: "whatsapp",
|
@@ -190,6 +250,26 @@ module WhatsappSdk
|
|
190
250
|
# TODO: https://developers.facebook.com/docs/whatsapp_sdk/cloud-api/reference/messages#contacts-object
|
191
251
|
end
|
192
252
|
|
253
|
+
# Mark a message as read.
|
254
|
+
#
|
255
|
+
# @param sender_id [Integer] Sender' phone number.
|
256
|
+
# @param message_id [Integer] Message ID.
|
257
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
258
|
+
def read_message(sender_id:, message_id:)
|
259
|
+
params = {
|
260
|
+
messaging_product: "whatsapp",
|
261
|
+
status: "read",
|
262
|
+
message_id: message_id
|
263
|
+
}
|
264
|
+
|
265
|
+
response = send_request(
|
266
|
+
endpoint: endpoint(sender_id),
|
267
|
+
params: params
|
268
|
+
)
|
269
|
+
|
270
|
+
WhatsappSdk::Api::Response.new(response: response, class_type: WhatsappSdk::Api::Responses::MessageDataResponse)
|
271
|
+
end
|
272
|
+
|
193
273
|
private
|
194
274
|
|
195
275
|
def endpoint(sender_id)
|
@@ -6,6 +6,10 @@ require_relative "response"
|
|
6
6
|
module WhatsappSdk
|
7
7
|
module Api
|
8
8
|
class PhoneNumbers < Request
|
9
|
+
# Get list of registered numbers.
|
10
|
+
#
|
11
|
+
# @param business_id [Integer] Business Id.
|
12
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
9
13
|
def registered_numbers(business_id)
|
10
14
|
response = send_request(
|
11
15
|
http_method: "get",
|
@@ -16,6 +20,10 @@ module WhatsappSdk
|
|
16
20
|
class_type: WhatsappSdk::Api::Responses::PhoneNumbersDataResponse)
|
17
21
|
end
|
18
22
|
|
23
|
+
# Get the registered number id.
|
24
|
+
#
|
25
|
+
# @param phone_number_id [Integer] The registered number we want to retrieve.
|
26
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
19
27
|
def registered_number(phone_number_id)
|
20
28
|
response = send_request(
|
21
29
|
http_method: "get",
|
@@ -13,7 +13,8 @@ module WhatsappSdk
|
|
13
13
|
CLASS_TYPE = {
|
14
14
|
message_data_response: Responses::MessageDataResponse,
|
15
15
|
phone_number_data_response: Responses::PhoneNumberDataResponse,
|
16
|
-
phone_numbers_data_response: Responses::PhoneNumbersDataResponse
|
16
|
+
phone_numbers_data_response: Responses::PhoneNumbersDataResponse,
|
17
|
+
read_message_data_response: ReadMessageDataResponse
|
17
18
|
}.freeze
|
18
19
|
|
19
20
|
def initialize(response:, class_type:)
|
@@ -21,10 +22,12 @@ module WhatsappSdk
|
|
21
22
|
@error = Responses::ErrorResponse.build_from_response(response: response)
|
22
23
|
end
|
23
24
|
|
25
|
+
# Whether or not the response is successful.
|
24
26
|
def ok?
|
25
27
|
@error.nil?
|
26
28
|
end
|
27
29
|
|
30
|
+
# Whether or not the response has an error.
|
28
31
|
def error?
|
29
32
|
!!@error
|
30
33
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../request"
|
4
|
+
require_relative "data_response"
|
5
|
+
require_relative "../../resource/message"
|
6
|
+
require_relative "../../resource/contact_response"
|
7
|
+
|
8
|
+
module WhatsappSdk
|
9
|
+
module Api
|
10
|
+
module Responses
|
11
|
+
class MessageDataResponse < DataResponse
|
12
|
+
attr_reader :sucess
|
13
|
+
|
14
|
+
def initialize(response:)
|
15
|
+
@sucess = response["sucess"]
|
16
|
+
super(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.build_from_response(response:)
|
20
|
+
return if response["error"]
|
21
|
+
|
22
|
+
new(response: response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ignacio-chiazzo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/whatsapp_sdk/api/responses/message_data_response.rb
|
115
115
|
- lib/whatsapp_sdk/api/responses/phone_number_data_response.rb
|
116
116
|
- lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb
|
117
|
+
- lib/whatsapp_sdk/api/responses/read_message_data_response.rb
|
117
118
|
- lib/whatsapp_sdk/error.rb
|
118
119
|
- lib/whatsapp_sdk/resource/address.rb
|
119
120
|
- lib/whatsapp_sdk/resource/contact.rb
|