whatsapp_sdk 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/Gemfile.lock +2 -1
- data/README.md +24 -1
- data/example.rb +22 -8
- data/lib/whatsapp_sdk/api/business_profile.rb +27 -1
- data/lib/whatsapp_sdk/api/messages.rb +36 -0
- data/lib/whatsapp_sdk/api/responses/business_profile_data_response.rb +14 -6
- data/lib/whatsapp_sdk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7cfa077303348e47c90cfcbda06cd977a1ccbd60680cc3dcbdfe609109b4570
|
4
|
+
data.tar.gz: 9a9d46ee397b70538e41f6489f5b0a72fc44054e154164d3fa383cccba5acdfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b08d94c4c773906cac506abb473f46281bfa233a9d56b5d6eaf294dfd53afca2c0cf4f70fb7f4019f6d1581697c43b54ff6556c1c50bfd95854cda54cf682952
|
7
|
+
data.tar.gz: 19ab26c648687e6ef2f7872ce0fa85b259b0fe2a91d6a41e2686d0b6cfe6bd6bf2e1727dd3daa84abd36de8b1d6dc19d1abaaaab7b5046f7af6ad06c80357f85
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
+
# unreleased
|
2
|
+
|
3
|
+
# v 0.7.0
|
4
|
+
Add message reaction @sanchezpaco [#58](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/58)
|
5
|
+
Add Business update API @sahilbansal17 [#56](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/56)
|
6
|
+
Fix Sorbet bug BusinessAPI [#60](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/60)
|
7
|
+
|
1
8
|
# v 0.6.2
|
2
|
-
Add Business Profiles API [#53](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/53)
|
9
|
+
Add Business Profiles API @sahilbansal17 [#53](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/53)
|
3
10
|
|
4
11
|
# v 0.6.1
|
5
12
|
Add raw_response to response [#47](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/46)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
whatsapp_sdk (0.
|
4
|
+
whatsapp_sdk (0.7.0)
|
5
5
|
faraday (>= 2.3.0)
|
6
6
|
faraday-multipart (~> 1.0.4)
|
7
7
|
oj (~> 3.13.13)
|
@@ -108,6 +108,7 @@ GEM
|
|
108
108
|
zeitwerk (2.6.0)
|
109
109
|
|
110
110
|
PLATFORMS
|
111
|
+
arm64-darwin-21
|
111
112
|
x86_64-darwin-21
|
112
113
|
x86_64-linux
|
113
114
|
|
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,
|
7
|
+
Send stickers, messages, audio, videos, locations, react to messages or just ask for the phone numbers through this library in a few steps!
|
8
8
|
|
9
9
|
|
10
10
|
## Demo
|
@@ -122,12 +122,27 @@ First, create the client and then create an instance `WhatsappSdk::Api::Messages
|
|
122
122
|
messages_api = WhatsappSdk::Api::Messages.new
|
123
123
|
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
|
124
124
|
medias_api = WhatsappSdk::Api::Medias.new
|
125
|
+
business_profile_api = WhatsappSdk::Api::BusinessProfile.new
|
125
126
|
```
|
126
127
|
|
127
128
|
Note: Remember to initialize the client first!
|
128
129
|
|
129
130
|
## APIs
|
130
131
|
|
132
|
+
### Business Profile API
|
133
|
+
<details>
|
134
|
+
|
135
|
+
Get the details of your business
|
136
|
+
```ruby
|
137
|
+
business_profile = business_profile_api.details(123456)
|
138
|
+
```
|
139
|
+
|
140
|
+
Update the details of your business
|
141
|
+
```ruby
|
142
|
+
business_profile_api.update(phone_number_id: SENDER_ID, params: { about: "A very cool business" } )
|
143
|
+
```
|
144
|
+
</details>
|
145
|
+
|
131
146
|
### Phone numbers API
|
132
147
|
|
133
148
|
<details>
|
@@ -184,6 +199,14 @@ messages_api.read_message(sender_id: 1234, message_id: "wamid.HBgLMTM0M123456789
|
|
184
199
|
|
185
200
|
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.
|
186
201
|
|
202
|
+
**Send a reaction to message**
|
203
|
+
To send a reaction to a message, you need to obtain the mssage id and look for the emoji's unicode you want to use.
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
messages_api.send_reaction(sender_id: 123_123, recipient_number: 56_789, message_id: "12345", emoji: "\u{1f550}")
|
207
|
+
|
208
|
+
messages_api.send_reaction(sender_id: 123_123, recipient_number: 56_789, message_id: "12345", emoji: "⛄️")
|
209
|
+
```
|
187
210
|
|
188
211
|
**Send a location message**
|
189
212
|
|
data/example.rb
CHANGED
@@ -11,7 +11,7 @@ gemfile(true) do
|
|
11
11
|
|
12
12
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
13
13
|
|
14
|
-
gem "whatsapp_sdk"
|
14
|
+
gem "whatsapp_sdk"
|
15
15
|
gem "pry"
|
16
16
|
gem "pry-nav"
|
17
17
|
end
|
@@ -22,11 +22,16 @@ require "pry-nav"
|
|
22
22
|
|
23
23
|
################# UPDATE CONSTANTS #################
|
24
24
|
|
25
|
-
ACCESS_TOKEN = "
|
26
|
-
SENDER_ID =
|
27
|
-
RECIPIENT_NUMBER =
|
28
|
-
BUSINESS_ID =
|
29
|
-
IMAGE_LINK = "
|
25
|
+
ACCESS_TOKEN = "<TODO replace>"
|
26
|
+
SENDER_ID = "<TODO replace>"
|
27
|
+
RECIPIENT_NUMBER = "<TODO replace>"
|
28
|
+
BUSINESS_ID = "<TODO replace>"
|
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
|
30
35
|
|
31
36
|
################# Initialize Client #################
|
32
37
|
WhatsappSdk.configure do |config|
|
@@ -46,13 +51,16 @@ end
|
|
46
51
|
medias_api = WhatsappSdk::Api::Medias.new
|
47
52
|
messages_api = WhatsappSdk::Api::Messages.new
|
48
53
|
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
|
49
|
-
|
54
|
+
business_profile_api = WhatsappSdk::Api::BusinessProfile.new
|
50
55
|
|
51
|
-
|
56
|
+
############################## Business API ##############################
|
57
|
+
business_profile = business_profile_api.details(SENDER_ID)
|
58
|
+
business_profile_api.update(phone_number_id: SENDER_ID, params: { about: "A very cool business" } )
|
52
59
|
|
53
60
|
############################## Phone Numbers API ##############################
|
54
61
|
registered_number = phone_numbers_api.registered_number(SENDER_ID)
|
55
62
|
registered_numbers = phone_numbers_api.registered_numbers(BUSINESS_ID)
|
63
|
+
|
56
64
|
############################## Media API ##############################
|
57
65
|
|
58
66
|
# upload a media
|
@@ -79,6 +87,12 @@ message_sent = messages_api.send_text(sender_id: SENDER_ID, recipient_number: RE
|
|
79
87
|
message: "Hey there! it's Whatsapp Ruby SDK")
|
80
88
|
print_message_sent(message_sent)
|
81
89
|
|
90
|
+
######### React to a message
|
91
|
+
message_id = message_sent.data.messages.first.id
|
92
|
+
messages_api.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: message_id, emoji: "\u{1f550}")
|
93
|
+
messages_api.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: message_id, emoji: "⛄️")
|
94
|
+
|
95
|
+
######### Send location
|
82
96
|
location_sent = messages_api.send_location(
|
83
97
|
sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER,
|
84
98
|
longitude: -75.6898604, latitude: 45.4192206, name: "Ignacio", address: "My house"
|
@@ -7,7 +7,7 @@ require_relative "response"
|
|
7
7
|
module WhatsappSdk
|
8
8
|
module Api
|
9
9
|
class BusinessProfile < Request
|
10
|
-
DEFAULT_FIELDS = 'about,address,description,email,profile_picture_url,websites,vertical'
|
10
|
+
DEFAULT_FIELDS = 'about,address,description,email,profile_picture_url,websites,vertical'
|
11
11
|
|
12
12
|
# Get the details of business profile.
|
13
13
|
#
|
@@ -25,6 +25,32 @@ module WhatsappSdk
|
|
25
25
|
data_class_type: WhatsappSdk::Api::Responses::BusinessProfileDataResponse
|
26
26
|
)
|
27
27
|
end
|
28
|
+
|
29
|
+
# Update the details of business profile.
|
30
|
+
#
|
31
|
+
# @param phone_number_id [Integer] Phone Number Id.
|
32
|
+
# @param params [Hash] Params to update.
|
33
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
34
|
+
sig do
|
35
|
+
params(
|
36
|
+
phone_number_id: Integer, params: T::Hash[T.untyped, T.untyped]
|
37
|
+
).returns(WhatsappSdk::Api::Response)
|
38
|
+
end
|
39
|
+
def update(phone_number_id:, params:)
|
40
|
+
# this is a required field
|
41
|
+
params[:messaging_product] = 'whatsapp'
|
42
|
+
|
43
|
+
response = send_request(
|
44
|
+
http_method: "post",
|
45
|
+
endpoint: "#{phone_number_id}/whatsapp_business_profile",
|
46
|
+
params: params
|
47
|
+
)
|
48
|
+
|
49
|
+
WhatsappSdk::Api::Response.new(
|
50
|
+
response: response,
|
51
|
+
data_class_type: WhatsappSdk::Api::Responses::SuccessResponse
|
52
|
+
)
|
53
|
+
end
|
28
54
|
end
|
29
55
|
end
|
30
56
|
end
|
@@ -406,6 +406,42 @@ module WhatsappSdk
|
|
406
406
|
)
|
407
407
|
end
|
408
408
|
|
409
|
+
# Send reaction
|
410
|
+
#
|
411
|
+
# @param sender_id [Integer] Sender' phone number.
|
412
|
+
# @param recipient_number [Integer] Recipient' Phone number.
|
413
|
+
# @param message_id [String] the id of the message to reaction.
|
414
|
+
# @param emoji [String] unicode of the emoji to send.
|
415
|
+
# @return [WhatsappSdk::Api::Response] Response object.
|
416
|
+
sig do
|
417
|
+
params(
|
418
|
+
sender_id: Integer, recipient_number: Integer, message_id: String, emoji: T.any(String, Integer)
|
419
|
+
).returns(WhatsappSdk::Api::Response)
|
420
|
+
end
|
421
|
+
def send_reaction(sender_id:, recipient_number:, message_id:, emoji:)
|
422
|
+
params = {
|
423
|
+
messaging_product: "whatsapp",
|
424
|
+
recipient_type: "individual",
|
425
|
+
to: recipient_number,
|
426
|
+
type: "reaction",
|
427
|
+
reaction: {
|
428
|
+
message_id: message_id,
|
429
|
+
emoji: emoji
|
430
|
+
}
|
431
|
+
}
|
432
|
+
|
433
|
+
response = send_request(
|
434
|
+
endpoint: endpoint(sender_id),
|
435
|
+
params: params,
|
436
|
+
headers: DEFAULT_HEADERS
|
437
|
+
)
|
438
|
+
|
439
|
+
WhatsappSdk::Api::Response.new(
|
440
|
+
response: response,
|
441
|
+
data_class_type: WhatsappSdk::Api::Responses::MessageDataResponse
|
442
|
+
)
|
443
|
+
end
|
444
|
+
|
409
445
|
private
|
410
446
|
|
411
447
|
sig { params(sender_id: Integer).returns(String) }
|
@@ -7,24 +7,30 @@ module WhatsappSdk
|
|
7
7
|
module Api
|
8
8
|
module Responses
|
9
9
|
class BusinessProfileDataResponse < DataResponse
|
10
|
-
sig { returns(String) }
|
10
|
+
sig { returns(T.nilable(String)) }
|
11
11
|
attr_accessor :about
|
12
12
|
|
13
|
-
sig { returns(String) }
|
13
|
+
sig { returns(T.nilable(String)) }
|
14
14
|
attr_accessor :address
|
15
15
|
|
16
|
-
sig { returns(String) }
|
16
|
+
sig { returns(T.nilable(String)) }
|
17
17
|
attr_accessor :description
|
18
18
|
|
19
|
-
sig { returns(String) }
|
19
|
+
sig { returns(T.nilable(String)) }
|
20
20
|
attr_accessor :email
|
21
21
|
|
22
|
-
sig { returns(String) }
|
22
|
+
sig { returns(T.nilable(String)) }
|
23
23
|
attr_accessor :messaging_product
|
24
24
|
|
25
|
-
sig { returns(String) }
|
25
|
+
sig { returns(T.nilable(String)) }
|
26
26
|
attr_accessor :profile_picture_url
|
27
27
|
|
28
|
+
sig { returns(T.nilable(String)) }
|
29
|
+
attr_accessor :vertical
|
30
|
+
|
31
|
+
sig { returns(T::Array[String]) }
|
32
|
+
attr_accessor :websites
|
33
|
+
|
28
34
|
sig { params(response: T::Hash[T.untyped, T.untyped]).void }
|
29
35
|
def initialize(response)
|
30
36
|
@about = T.let(response["data"][0]["about"], T.nilable(String))
|
@@ -33,6 +39,8 @@ module WhatsappSdk
|
|
33
39
|
@email = T.let(response["data"][0]["email"], T.nilable(String))
|
34
40
|
@messaging_product = T.let(response["data"][0]["messaging_product"], T.nilable(String))
|
35
41
|
@profile_picture_url = T.let(response["data"][0]["profile_picture_url"], T.nilable(String))
|
42
|
+
@vertical = T.let(response["data"][0]["vertical"], T.nilable(String))
|
43
|
+
@websites = T.let(response["data"][0]["websites"], T.nilable(T::Array[String]))
|
36
44
|
super(response)
|
37
45
|
end
|
38
46
|
|
data/lib/whatsapp_sdk/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.0
|
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-10-
|
11
|
+
date: 2022-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|