whatsapp_sdk 0.6.2 → 0.7.1

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: 50d31bd48fd780c01049dfb4057424ce55cc6bc5092a5b250900482044bd8622
4
- data.tar.gz: 0a76d504966100b86add6394bd69af61863575c05d3c67db74eab934a199fb5a
3
+ metadata.gz: 1f391a609a7230a7772cf0328b570c84be187ce2c94d5f9858cb7fe3776798e4
4
+ data.tar.gz: 393eebc7cbb96780d02329f9f167b4c1c904bf1e900b9bf31baef72ef2ea4de8
5
5
  SHA512:
6
- metadata.gz: 66dc2b2cad95e2b230203613be97fef11ea32bcaaba1f9a157a9e7d1336060690462a1e4b4202b31d9b4494158ea55a29b88e2b26b45ec16e67817054b653bc5
7
- data.tar.gz: e9a7602a3f6f74a1ee043b21b4beee11160db4286eb28b4addbe5867c9b088bc796e612f62f8b1cd48200677b018f7b6c51c6bd99d456d9f3d2277d5479b55f6
6
+ metadata.gz: 96005fff84e2b54ae069ebc7dd49e3dcce72ce58f7269a5d20f8a9f25b29ba6fab6e42d2a1fbf33b0c8eb02b9e66663fcf8d441d86557cf5a21032906936e80c
7
+ data.tar.gz: c17e00d76ca9a9bd3d9348ae95bea014241dccd101c4f224a0844f85b28c8f7d80223aac542997b006515fb8bfb90a00aa4d4ca4a6479ac74253b28cff46ed01
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
+ # unreleased
2
+
3
+ # v 0.7.1
4
+ Add Register API [#65](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/65)
5
+
6
+ # v 0.7.0
7
+ Add message reaction @sanchezpaco [#58](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/58)
8
+ Add Business update API @sahilbansal17 [#56](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/56)
9
+ Fix Sorbet bug BusinessAPI [#60](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/60)
10
+
1
11
  # v 0.6.2
2
- Add Business Profiles API [#53](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/53)
12
+ Add Business Profiles API @sahilbansal17 [#53](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/53)
3
13
 
4
14
  # v 0.6.1
5
15
  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.6.2)
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, and locations or just ask for the phone numbers through this library in a few steps!
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
@@ -96,9 +96,9 @@ WhatsappSdk.configure do |config|
96
96
  end
97
97
  ```
98
98
 
99
- 6) Try the Medias or Messages API
99
+ 6) Try the Phone Numbers API or Messages API
100
100
 
101
- Medias API
101
+ Phone Numbers API
102
102
  ```ruby
103
103
  phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
104
104
  registered_number = phone_numbers_api.registered_number(SENDER_ID)
@@ -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>
@@ -141,6 +156,16 @@ Get the a phone number by id
141
156
  ```ruby
142
157
  phone_numbers_api.registered_numbers(123456) # accepts a phone_number_id
143
158
  ```
159
+
160
+ Register a phone number
161
+ ```ruby
162
+ phone_numbers_api.register_number(phone_number_id, pin)
163
+ ```
164
+
165
+ Deregister a phone number
166
+ ```ruby
167
+ phone_numbers_api.deregister_number(phone_number_id)
168
+ ```
144
169
  </details>
145
170
 
146
171
  ### Media API
@@ -184,6 +209,14 @@ messages_api.read_message(sender_id: 1234, message_id: "wamid.HBgLMTM0M123456789
184
209
 
185
210
  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
211
 
212
+ **Send a reaction to message**
213
+ 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.
214
+
215
+ ```ruby
216
+ messages_api.send_reaction(sender_id: 123_123, recipient_number: 56_789, message_id: "12345", emoji: "\u{1f550}")
217
+
218
+ messages_api.send_reaction(sender_id: 123_123, recipient_number: 56_789, message_id: "12345", emoji: "⛄️")
219
+ ```
187
220
 
188
221
  **Send a location message**
189
222
 
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", path: "."
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 = "EAAZAvvr0DZBs0BAFe8yjwJujpg5JZBX5DvzQ5Mv1oUBxuOefZAmi1TuRTkYmd9AqNqyTt2TtGict94yDWMmxb4fVQ3gZANjIb0IXXptezSad0xTHIZBpCNqZB8SBeBGL0eajPEjP1tZBwY3oyuOMwRU1ZAQuKMFkIV7Sw01AA3nX32plODm7LObsLp04C3aL7Pb1UF6OYKS0vPcqtFl21E9sf" # replace this with a valid access_token # TODO replace
26
- SENDER_ID = 111591145018464
27
- RECIPIENT_NUMBER = 13_437_772_910
28
- BUSINESS_ID = 102261539298487
29
- IMAGE_LINK = "https://ignaciochiazzo.com/static/4c403819b9750c8ad8b20a75308f2a8a/876d5/profile-pic.avif"
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
- business_profile = WhatsappSdk::Api::BusinessProfile.new
54
+ business_profile_api = WhatsappSdk::Api::BusinessProfile.new
50
55
 
51
- binding.pry
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'.freeze
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) }
@@ -40,6 +40,52 @@ module WhatsappSdk
40
40
  data_class_type: WhatsappSdk::Api::Responses::PhoneNumberDataResponse
41
41
  )
42
42
  end
43
+
44
+ # Register a phone number.
45
+ #
46
+ # @param phone_number_id [Integer] The registered number we want to retrieve.
47
+ # @param pin [Integer] Pin of 6 digits.
48
+ # @return [WhatsappSdk::Api::Response] Response object.
49
+ sig do
50
+ params(
51
+ phone_number_id: Integer,
52
+ pin: Integer
53
+ ).returns(WhatsappSdk::Api::Response)
54
+ end
55
+ def register_number(phone_number_id, pin)
56
+ response = send_request(
57
+ http_method: "post",
58
+ endpoint: "#{phone_number_id}/register",
59
+ params: { messaging_product: 'whatsapp', pin: pin }
60
+ )
61
+
62
+ WhatsappSdk::Api::Response.new(
63
+ response: response,
64
+ data_class_type: WhatsappSdk::Api::Responses::PhoneNumberDataResponse
65
+ )
66
+ end
67
+
68
+ # Deregister a phone number.
69
+ #
70
+ # @param phone_number_id [Integer] The registered number we want to retrieve.
71
+ # @return [WhatsappSdk::Api::Response] Response object.
72
+ sig do
73
+ params(
74
+ phone_number_id: Integer
75
+ ).returns(WhatsappSdk::Api::Response)
76
+ end
77
+ def deregister_number(phone_number_id)
78
+ response = send_request(
79
+ http_method: "post",
80
+ endpoint: "#{phone_number_id}/deregister",
81
+ params: {}
82
+ )
83
+
84
+ WhatsappSdk::Api::Response.new(
85
+ response: response,
86
+ data_class_type: WhatsappSdk::Api::Responses::PhoneNumberDataResponse
87
+ )
88
+ end
43
89
  end
44
90
  end
45
91
  end
@@ -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
 
@@ -2,5 +2,5 @@
2
2
  # typed: strict
3
3
 
4
4
  module WhatsappSdk
5
- VERSION = "0.6.2"
5
+ VERSION = "0.7.1"
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.6.2
4
+ version: 0.7.1
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-23 00:00:00.000000000 Z
11
+ date: 2023-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler