whatsapp_sdk 0.3.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +14 -0
- data/CHANGELOG.md +3 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +45 -1
- data/README.md +102 -28
- data/Rakefile +1 -0
- data/bin/tapioca +30 -0
- data/example.rb +30 -34
- data/lib/version.rb +2 -1
- data/lib/whatsapp_sdk/api/client.rb +14 -3
- data/lib/whatsapp_sdk/api/medias.rb +12 -3
- data/lib/whatsapp_sdk/api/messages.rb +72 -14
- data/lib/whatsapp_sdk/api/phone_numbers.rb +3 -0
- data/lib/whatsapp_sdk/api/request.rb +2 -2
- data/lib/whatsapp_sdk/api/response.rb +17 -1
- data/lib/whatsapp_sdk/api/responses/data_response.rb +10 -3
- data/lib/whatsapp_sdk/api/responses/error_response.rb +8 -1
- data/lib/whatsapp_sdk/api/responses/media_data_response.rb +26 -7
- data/lib/whatsapp_sdk/api/responses/message_data_response.rb +20 -3
- data/lib/whatsapp_sdk/api/responses/message_error_response.rb +26 -7
- data/lib/whatsapp_sdk/api/responses/phone_number_data_response.rb +18 -5
- data/lib/whatsapp_sdk/api/responses/phone_numbers_data_response.rb +9 -1
- data/lib/whatsapp_sdk/api/responses/read_message_data_response.rb +10 -3
- data/lib/whatsapp_sdk/api/responses/success_response.rb +5 -1
- data/lib/whatsapp_sdk/configuration.rb +7 -3
- data/lib/whatsapp_sdk/error.rb +1 -0
- data/lib/whatsapp_sdk/resource/address.rb +30 -6
- data/lib/whatsapp_sdk/resource/address_type.rb +15 -0
- data/lib/whatsapp_sdk/resource/button_parameter.rb +19 -23
- data/lib/whatsapp_sdk/resource/component.rb +45 -13
- data/lib/whatsapp_sdk/resource/contact.rb +30 -1
- data/lib/whatsapp_sdk/resource/contact_response.rb +9 -1
- data/lib/whatsapp_sdk/resource/currency.rb +9 -1
- data/lib/whatsapp_sdk/resource/date_time.rb +7 -1
- data/lib/whatsapp_sdk/resource/email.rb +9 -5
- data/lib/whatsapp_sdk/resource/media.rb +44 -15
- data/lib/whatsapp_sdk/resource/message.rb +5 -0
- data/lib/whatsapp_sdk/resource/name.rb +28 -1
- data/lib/whatsapp_sdk/resource/org.rb +13 -1
- data/lib/whatsapp_sdk/resource/parameter_object.rb +82 -39
- data/lib/whatsapp_sdk/resource/phone_number.rb +12 -5
- data/lib/whatsapp_sdk/resource/url.rb +9 -5
- data/lib/whatsapp_sdk.rb +8 -0
- data/sorbet/config +6 -0
- data/sorbet/rbi/annotations/faraday.rbi +17 -0
- data/sorbet/rbi/annotations/mocha.rbi +34 -0
- data/sorbet/rbi/annotations/rainbow.rbi +269 -0
- data/sorbet/rbi/gems/faraday-multipart@1.0.4.rbi +270 -0
- data/sorbet/rbi/gems/faraday-net_http@2.0.3.rbi +182 -0
- data/sorbet/rbi/gems/faraday@2.3.0.rbi +2494 -0
- data/sorbet/rbi/gems/method_source@1.0.0.rbi +272 -0
- data/sorbet/rbi/gems/minitest@5.16.1.rbi +1459 -0
- data/sorbet/rbi/gems/mocha@1.14.0.rbi +60 -0
- data/sorbet/rbi/gems/multipart-post@2.2.3.rbi +239 -0
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +150 -0
- data/sorbet/rbi/gems/oj@3.13.14.rbi +589 -0
- data/sorbet/rbi/gems/zeitwerk@2.6.0.rbi +867 -0
- data/sorbet/rbi/todo.rbi +8 -0
- data/sorbet/shims/request.rbi +10 -0
- data/sorbet/tapioca/config.yml +13 -0
- data/sorbet/tapioca/require.rb +5 -0
- data/whatsapp_sdk.gemspec +4 -1
- metadata +50 -2
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require "faraday"
|
4
5
|
require "faraday/multipart"
|
@@ -12,8 +13,12 @@ module WhatsappSdk
|
|
12
13
|
module Api
|
13
14
|
class Medias < Request
|
14
15
|
class FileNotFoundError < StandardError
|
16
|
+
extend T::Sig
|
17
|
+
|
18
|
+
sig { returns(String) }
|
15
19
|
attr_reader :file_path
|
16
20
|
|
21
|
+
sig { params(file_path: String).void }
|
17
22
|
def initialize(file_path)
|
18
23
|
@file_path = file_path
|
19
24
|
super("Couldn't find file_path: #{file_path}")
|
@@ -22,8 +27,9 @@ module WhatsappSdk
|
|
22
27
|
|
23
28
|
# Get Media by ID.
|
24
29
|
#
|
25
|
-
# @param media_id [
|
30
|
+
# @param media_id [String] Media Id.
|
26
31
|
# @return [WhatsappSdk::Api::Response] Response object.
|
32
|
+
sig { params(media_id: String).returns(WhatsappSdk::Api::Response) }
|
27
33
|
def media(media_id:)
|
28
34
|
response = send_request(
|
29
35
|
http_method: "get",
|
@@ -38,9 +44,10 @@ module WhatsappSdk
|
|
38
44
|
|
39
45
|
# Download Media by URL.
|
40
46
|
#
|
41
|
-
# @param
|
47
|
+
# @param url URL.
|
42
48
|
# @param file_path [String] The file_path to download the media e.g. "tmp/downloaded_image.png".
|
43
49
|
# @return [WhatsappSdk::Api::Response] Response object.
|
50
|
+
sig { params(url: String, file_path: String).returns(WhatsappSdk::Api::Response) }
|
44
51
|
def download(url:, file_path:)
|
45
52
|
response = download_file(url, file_path)
|
46
53
|
|
@@ -64,6 +71,7 @@ module WhatsappSdk
|
|
64
71
|
# see the official documentation https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types.
|
65
72
|
#
|
66
73
|
# @return [WhatsappSdk::Api::Response] Response object.
|
74
|
+
sig { params(sender_id: Integer, file_path: String, type: String).returns(WhatsappSdk::Api::Response) }
|
67
75
|
def upload(sender_id:, file_path:, type:)
|
68
76
|
raise FileNotFoundError, file_path unless File.file?(file_path)
|
69
77
|
|
@@ -83,8 +91,9 @@ module WhatsappSdk
|
|
83
91
|
|
84
92
|
# Delete a Media by ID.
|
85
93
|
#
|
86
|
-
# @param media_id [
|
94
|
+
# @param media_id [String] Media Id.
|
87
95
|
# @return [WhatsappSdk::Api::Response] Response object.
|
96
|
+
sig { params(media_id: String).returns(WhatsappSdk::Api::Response) }
|
88
97
|
def delete(media_id:)
|
89
98
|
response = send_request(
|
90
99
|
http_method: "delete",
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "request"
|
4
5
|
require_relative "response"
|
@@ -6,9 +7,15 @@ require_relative "response"
|
|
6
7
|
module WhatsappSdk
|
7
8
|
module Api
|
8
9
|
class Messages < Request
|
10
|
+
extend T::Sig
|
11
|
+
|
9
12
|
class MissingArgumentError < StandardError
|
13
|
+
extend T::Sig
|
14
|
+
|
15
|
+
sig { returns(String) }
|
10
16
|
attr_reader :message
|
11
17
|
|
18
|
+
sig { params(message: String).void }
|
12
19
|
def initialize(message)
|
13
20
|
@message = message
|
14
21
|
super(message)
|
@@ -21,6 +28,7 @@ module WhatsappSdk
|
|
21
28
|
# @param recipient_number [Integer] Recipient' Phone number.
|
22
29
|
# @param message [String] Text to send.
|
23
30
|
# @return [WhatsappSdk::Api::Response] Response object.
|
31
|
+
sig { params(sender_id: Integer, recipient_number: Integer, message: String).returns(WhatsappSdk::Api::Response) }
|
24
32
|
def send_text(sender_id:, recipient_number:, message:)
|
25
33
|
params = {
|
26
34
|
messaging_product: "whatsapp",
|
@@ -50,6 +58,12 @@ module WhatsappSdk
|
|
50
58
|
# @param name [String] Location name.
|
51
59
|
# @param address [String] Location address.
|
52
60
|
# @return [WhatsappSdk::Api::Response] Response object.
|
61
|
+
sig do
|
62
|
+
params(
|
63
|
+
sender_id: Integer, recipient_number: Integer,
|
64
|
+
longitude: Float, latitude: Float, name: String, address: String
|
65
|
+
).returns(WhatsappSdk::Api::Response)
|
66
|
+
end
|
53
67
|
def send_location(sender_id:, recipient_number:, longitude:, latitude:, name:, address:)
|
54
68
|
params = {
|
55
69
|
messaging_product: "whatsapp",
|
@@ -79,10 +93,16 @@ module WhatsappSdk
|
|
79
93
|
#
|
80
94
|
# @param sender_id [Integer] Sender' phone number.
|
81
95
|
# @param recipient_number [Integer] Recipient' Phone number.
|
82
|
-
# @param image_id [
|
96
|
+
# @param image_id [String] Image ID.
|
83
97
|
# @param link [String] Image link.
|
84
98
|
# @param caption [String] Image caption.
|
85
99
|
# @return [WhatsappSdk::Api::Response] Response object.
|
100
|
+
sig do
|
101
|
+
params(
|
102
|
+
sender_id: Integer, recipient_number: Integer, image_id: T.nilable(String),
|
103
|
+
link: T.nilable(String), caption: T.nilable(String)
|
104
|
+
).returns(WhatsappSdk::Api::Response)
|
105
|
+
end
|
86
106
|
def send_image(sender_id:, recipient_number:, image_id: nil, link: nil, caption: "")
|
87
107
|
raise MissingArgumentError, "image_id or link is required" if !image_id && !link
|
88
108
|
|
@@ -113,9 +133,14 @@ module WhatsappSdk
|
|
113
133
|
#
|
114
134
|
# @param sender_id [Integer] Sender' phone number.
|
115
135
|
# @param recipient_number [Integer] Recipient' Phone number.
|
116
|
-
# @param audio_id [
|
136
|
+
# @param audio_id [String] Audio ID.
|
117
137
|
# @param link [String] Audio link.
|
118
138
|
# @return [WhatsappSdk::Api::Response] Response object.
|
139
|
+
sig do
|
140
|
+
params(
|
141
|
+
sender_id: Integer, recipient_number: Integer, audio_id: T.nilable(String), link: T.nilable(String)
|
142
|
+
).returns(WhatsappSdk::Api::Response)
|
143
|
+
end
|
119
144
|
def send_audio(sender_id:, recipient_number:, audio_id: nil, link: nil)
|
120
145
|
raise MissingArgumentError, "audio_id or link is required" if !audio_id && !link
|
121
146
|
|
@@ -142,10 +167,16 @@ module WhatsappSdk
|
|
142
167
|
#
|
143
168
|
# @param sender_id [Integer] Sender' phone number.
|
144
169
|
# @param recipient_number [Integer] Recipient' Phone number.
|
145
|
-
# @param video_id [
|
170
|
+
# @param video_id [String] Video ID.
|
146
171
|
# @param link [String] Image link.
|
147
172
|
# @param caption [String] Image caption.
|
148
173
|
# @return [WhatsappSdk::Api::Response] Response object.
|
174
|
+
sig do
|
175
|
+
params(
|
176
|
+
sender_id: Integer, recipient_number: Integer,
|
177
|
+
video_id: T.nilable(String), link: T.nilable(String), caption: String
|
178
|
+
).returns(WhatsappSdk::Api::Response)
|
179
|
+
end
|
149
180
|
def send_video(sender_id:, recipient_number:, video_id: nil, link: nil, caption: "")
|
150
181
|
raise MissingArgumentError, "video_id or link is required" if !video_id && !link
|
151
182
|
|
@@ -176,10 +207,16 @@ module WhatsappSdk
|
|
176
207
|
#
|
177
208
|
# @param sender_id [Integer] Sender' phone number.
|
178
209
|
# @param recipient_number [Integer] Recipient' Phone number.
|
179
|
-
# @param document_id [
|
210
|
+
# @param document_id [String] document ID.
|
180
211
|
# @param link [String] Image link.
|
181
212
|
# @param caption [String] Image caption.
|
182
213
|
# @return [WhatsappSdk::Api::Response] Response object.
|
214
|
+
sig do
|
215
|
+
params(
|
216
|
+
sender_id: Integer, recipient_number: Integer,
|
217
|
+
document_id: T.nilable(String), link: T.nilable(String), caption: String
|
218
|
+
).returns(WhatsappSdk::Api::Response)
|
219
|
+
end
|
183
220
|
def send_document(sender_id:, recipient_number:, document_id: nil, link: nil, caption: "")
|
184
221
|
raise MissingArgumentError, "document or link is required" if !document_id && !link
|
185
222
|
|
@@ -210,8 +247,14 @@ module WhatsappSdk
|
|
210
247
|
#
|
211
248
|
# @param sender_id [Integer] Sender' phone number.
|
212
249
|
# @param recipient_number [Integer] Recipient' Phone number.
|
250
|
+
# @param sticker_id [String] The sticker ID.
|
213
251
|
# @param link [String] Image link.
|
214
252
|
# @return [WhatsappSdk::Api::Response] Response object.
|
253
|
+
sig do
|
254
|
+
params(
|
255
|
+
sender_id: Integer, recipient_number: Integer, sticker_id: T.nilable(String), link: T.nilable(String)
|
256
|
+
).returns(WhatsappSdk::Api::Response)
|
257
|
+
end
|
215
258
|
def send_sticker(sender_id:, recipient_number:, sticker_id: nil, link: nil)
|
216
259
|
raise MissingArgumentError, "sticker or link is required" if !sticker_id && !link
|
217
260
|
|
@@ -219,7 +262,7 @@ module WhatsappSdk
|
|
219
262
|
messaging_product: "whatsapp",
|
220
263
|
to: recipient_number,
|
221
264
|
recipient_type: "individual",
|
222
|
-
type:
|
265
|
+
type: Resource::Media::Type::Sticker
|
223
266
|
}
|
224
267
|
params[:sticker] = link ? { link: link } : { id: sticker_id }
|
225
268
|
|
@@ -242,6 +285,12 @@ module WhatsappSdk
|
|
242
285
|
# @param contacts [Array<Contact>] Contacts.
|
243
286
|
# @param contacts_json [Json] Contacts.
|
244
287
|
# @return [WhatsappSdk::Api::Response] Response object.
|
288
|
+
sig do
|
289
|
+
params(
|
290
|
+
sender_id: Integer, recipient_number: Integer,
|
291
|
+
contacts: T.nilable(T::Array[WhatsappSdk::Resource::Contact]), contacts_json: T::Hash[T.untyped, T.untyped]
|
292
|
+
).returns(WhatsappSdk::Api::Response)
|
293
|
+
end
|
245
294
|
def send_contacts(sender_id:, recipient_number:, contacts: nil, contacts_json: {})
|
246
295
|
params = {
|
247
296
|
messaging_product: "whatsapp",
|
@@ -262,23 +311,24 @@ module WhatsappSdk
|
|
262
311
|
)
|
263
312
|
end
|
264
313
|
|
265
|
-
def send_interactive_button
|
266
|
-
|
267
|
-
end
|
314
|
+
# def send_interactive_button
|
315
|
+
# # TODO: https://developers.facebook.com/docs/whatsapp_sdk/cloud-api/reference/messages#contacts-object
|
316
|
+
# end
|
268
317
|
|
269
|
-
def send_interactive_reply_buttons
|
270
|
-
|
271
|
-
end
|
318
|
+
# def send_interactive_reply_buttons
|
319
|
+
# # TODO: https://developers.facebook.com/docs/whatsapp_sdk/cloud-api/reference/messages#contacts-object
|
320
|
+
# end
|
272
321
|
|
273
|
-
def send_interactive_section
|
274
|
-
|
275
|
-
end
|
322
|
+
# def send_interactive_section
|
323
|
+
# # TODO: https://developers.facebook.com/docs/whatsapp_sdk/cloud-api/reference/messages#contacts-object
|
324
|
+
# end
|
276
325
|
|
277
326
|
# Mark a message as read.
|
278
327
|
#
|
279
328
|
# @param sender_id [Integer] Sender' phone number.
|
280
329
|
# @param message_id [Integer] Message ID.
|
281
330
|
# @return [WhatsappSdk::Api::Response] Response object.
|
331
|
+
sig { params(sender_id: Integer, message_id: String).returns(WhatsappSdk::Api::Response) }
|
282
332
|
def read_message(sender_id:, message_id:)
|
283
333
|
params = {
|
284
334
|
messaging_product: "whatsapp",
|
@@ -306,6 +356,13 @@ module WhatsappSdk
|
|
306
356
|
# @param components [Component] Component.
|
307
357
|
# @param components_json [Json] The component as a Json. If you pass components_json, you can't pass components.
|
308
358
|
# @return [WhatsappSdk::Api::Response] Response object.
|
359
|
+
sig do
|
360
|
+
params(
|
361
|
+
sender_id: Integer, recipient_number: Integer, name: String, language: String,
|
362
|
+
components: T.nilable(T::Array[WhatsappSdk::Resource::Component]),
|
363
|
+
components_json: T.nilable(T::Array[T::Hash[T.untyped, T.untyped]])
|
364
|
+
).returns(WhatsappSdk::Api::Response)
|
365
|
+
end
|
309
366
|
def send_template(sender_id:, recipient_number:, name:, language:, components: nil, components_json: nil)
|
310
367
|
raise MissingArgumentError, "components or components_json is required" if !components && !components_json
|
311
368
|
|
@@ -339,6 +396,7 @@ module WhatsappSdk
|
|
339
396
|
|
340
397
|
private
|
341
398
|
|
399
|
+
sig { params(sender_id: Integer).returns(String) }
|
342
400
|
def endpoint(sender_id)
|
343
401
|
"#{sender_id}/messages"
|
344
402
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "request"
|
4
5
|
require_relative "response"
|
@@ -10,6 +11,7 @@ module WhatsappSdk
|
|
10
11
|
#
|
11
12
|
# @param business_id [Integer] Business Id.
|
12
13
|
# @return [WhatsappSdk::Api::Response] Response object.
|
14
|
+
sig { params(business_id: Integer).returns(WhatsappSdk::Api::Response) }
|
13
15
|
def registered_numbers(business_id)
|
14
16
|
response = send_request(
|
15
17
|
http_method: "get",
|
@@ -26,6 +28,7 @@ module WhatsappSdk
|
|
26
28
|
#
|
27
29
|
# @param phone_number_id [Integer] The registered number we want to retrieve.
|
28
30
|
# @return [WhatsappSdk::Api::Response] Response object.
|
31
|
+
sig { params(phone_number_id: Integer).returns(WhatsappSdk::Api::Response) }
|
29
32
|
def registered_number(phone_number_id)
|
30
33
|
response = send_request(
|
31
34
|
http_method: "get",
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: true
|
2
3
|
|
3
4
|
module WhatsappSdk
|
4
5
|
module Api
|
5
6
|
class Request
|
6
|
-
|
7
|
-
API_CLIENT = "https://graph.facebook.com/#{API_VERSION}/"
|
7
|
+
extend T::Sig
|
8
8
|
|
9
9
|
def initialize(client = WhatsappSdk.configuration.client)
|
10
10
|
@client = client
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "responses/message_data_response"
|
4
5
|
require_relative "responses/phone_number_data_response"
|
@@ -9,19 +10,34 @@ require_relative "responses/message_error_response"
|
|
9
10
|
module WhatsappSdk
|
10
11
|
module Api
|
11
12
|
class Response
|
12
|
-
|
13
|
+
extend T::Sig
|
13
14
|
|
15
|
+
sig { returns(T.nilable(WhatsappSdk::Api::Responses::ErrorResponse)) }
|
16
|
+
attr_accessor :error
|
17
|
+
|
18
|
+
sig { returns(T.nilable(WhatsappSdk::Api::Responses::DataResponse)) }
|
19
|
+
attr_accessor :data
|
20
|
+
|
21
|
+
sig do
|
22
|
+
params(
|
23
|
+
response: T::Hash[T.untyped, T.untyped],
|
24
|
+
data_class_type: T.class_of(WhatsappSdk::Api::Responses::DataResponse),
|
25
|
+
error_class_type: T.class_of(WhatsappSdk::Api::Responses::ErrorResponse)
|
26
|
+
).void
|
27
|
+
end
|
14
28
|
def initialize(response:, data_class_type:, error_class_type: Responses::MessageErrorResponse)
|
15
29
|
@data = data_class_type.build_from_response(response: response)
|
16
30
|
@error = error_class_type.build_from_response(response: response)
|
17
31
|
end
|
18
32
|
|
19
33
|
# @return [Boolean] Whether or not the response is successful.
|
34
|
+
sig { returns(T::Boolean) }
|
20
35
|
def ok?
|
21
36
|
@error.nil?
|
22
37
|
end
|
23
38
|
|
24
39
|
# @return [Boolean] Whether or not the response has an error.
|
40
|
+
sig { returns(T::Boolean) }
|
25
41
|
def error?
|
26
42
|
!!@error
|
27
43
|
end
|
@@ -1,18 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
module WhatsappSdk
|
4
5
|
module Api
|
5
6
|
module Responses
|
6
7
|
class DataResponse
|
8
|
+
extend ::T::Sig
|
9
|
+
extend ::T::Helpers
|
10
|
+
|
11
|
+
abstract!
|
12
|
+
|
13
|
+
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
7
14
|
attr_reader :raw_data_response
|
8
15
|
|
16
|
+
sig { params(response: T::Hash[T.untyped, T.untyped]).void }
|
9
17
|
def initialize(response)
|
10
18
|
@raw_data_response = response
|
11
19
|
end
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
21
|
+
sig { abstract.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(DataResponse)) }
|
22
|
+
def self.build_from_response(response:); end
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "data_response"
|
4
5
|
|
@@ -6,14 +7,20 @@ module WhatsappSdk
|
|
6
7
|
module Api
|
7
8
|
module Responses
|
8
9
|
class ErrorResponse < DataResponse
|
9
|
-
|
10
|
+
sig { returns(T.nilable(T::Boolean)) }
|
11
|
+
attr_accessor :error
|
10
12
|
|
13
|
+
sig { returns(T.nilable(Integer)) }
|
14
|
+
attr_accessor :status
|
15
|
+
|
16
|
+
sig { params(response: T::Hash[T.untyped, T.untyped]).void }
|
11
17
|
def initialize(response:)
|
12
18
|
@error = response["error"]
|
13
19
|
@status = response["status"]
|
14
20
|
super(response)
|
15
21
|
end
|
16
22
|
|
23
|
+
sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(ErrorResponse)) }
|
17
24
|
def self.build_from_response(response:)
|
18
25
|
return unless response["error"]
|
19
26
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "data_response"
|
4
5
|
|
@@ -6,18 +7,36 @@ module WhatsappSdk
|
|
6
7
|
module Api
|
7
8
|
module Responses
|
8
9
|
class MediaDataResponse < DataResponse
|
9
|
-
|
10
|
+
sig { returns(String) }
|
11
|
+
attr_accessor :id
|
10
12
|
|
13
|
+
sig { returns(T.nilable(String)) }
|
14
|
+
attr_accessor :url
|
15
|
+
|
16
|
+
sig { returns(T.nilable(String)) }
|
17
|
+
attr_accessor :mime_type
|
18
|
+
|
19
|
+
sig { returns(T.nilable(String)) }
|
20
|
+
attr_accessor :sha256
|
21
|
+
|
22
|
+
sig { returns(T.nilable(Integer)) }
|
23
|
+
attr_accessor :file_size
|
24
|
+
|
25
|
+
sig { returns(T.nilable(String)) }
|
26
|
+
attr_accessor :messaging_product
|
27
|
+
|
28
|
+
sig { params(response: T::Hash[T.untyped, T.untyped]).void }
|
11
29
|
def initialize(response)
|
12
|
-
@id = response["id"]
|
13
|
-
@messaging_product = response["messaging_product"]
|
14
|
-
@url = response["url"]
|
15
|
-
@mime_type = response["mime_type"]
|
16
|
-
@sha256 = response["sha256"]
|
17
|
-
@file_size = response["file_size"]
|
30
|
+
@id = T.let(response["id"], String)
|
31
|
+
@messaging_product = T.let(response["messaging_product"], T.nilable(String))
|
32
|
+
@url = T.let(response["url"], T.nilable(String))
|
33
|
+
@mime_type = T.let(response["mime_type"], T.nilable(String))
|
34
|
+
@sha256 = T.let(response["sha256"], T.nilable(String))
|
35
|
+
@file_size = T.let(response["file_size"], T.nilable(Integer))
|
18
36
|
super(response)
|
19
37
|
end
|
20
38
|
|
39
|
+
sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(MediaDataResponse)) }
|
21
40
|
def self.build_from_response(response:)
|
22
41
|
return unless response["id"]
|
23
42
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "../request"
|
4
5
|
require_relative "data_response"
|
@@ -9,14 +10,28 @@ module WhatsappSdk
|
|
9
10
|
module Api
|
10
11
|
module Responses
|
11
12
|
class MessageDataResponse < DataResponse
|
12
|
-
|
13
|
+
extend T::Sig
|
13
14
|
|
15
|
+
sig { returns(T::Array[::WhatsappSdk::Resource::ContactResponse]) }
|
16
|
+
attr_reader :contacts
|
17
|
+
|
18
|
+
sig { returns(T::Array[::WhatsappSdk::Resource::Message]) }
|
19
|
+
attr_reader :messages
|
20
|
+
|
21
|
+
sig { params(response: T::Hash[T.untyped, T.untyped]).void }
|
14
22
|
def initialize(response:)
|
15
|
-
@contacts =
|
16
|
-
|
23
|
+
@contacts = T.let(
|
24
|
+
response["contacts"]&.map { |contact_json| parse_contact(contact_json) },
|
25
|
+
T::Array[::WhatsappSdk::Resource::ContactResponse]
|
26
|
+
)
|
27
|
+
@messages = T.let(
|
28
|
+
response["messages"]&.map { |contact_json| parse_message(contact_json) },
|
29
|
+
T::Array[::WhatsappSdk::Resource::Message]
|
30
|
+
)
|
17
31
|
super(response)
|
18
32
|
end
|
19
33
|
|
34
|
+
sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(MessageDataResponse)) }
|
20
35
|
def self.build_from_response(response:)
|
21
36
|
return unless response["messages"]
|
22
37
|
|
@@ -25,10 +40,12 @@ module WhatsappSdk
|
|
25
40
|
|
26
41
|
private
|
27
42
|
|
43
|
+
sig { params(message_json: T::Hash[T.untyped, T.untyped]).returns(::WhatsappSdk::Resource::Message) }
|
28
44
|
def parse_message(message_json)
|
29
45
|
::WhatsappSdk::Resource::Message.new(id: message_json["id"])
|
30
46
|
end
|
31
47
|
|
48
|
+
sig { params(contact_json: T::Hash[T.untyped, T.untyped]).returns(::WhatsappSdk::Resource::ContactResponse) }
|
32
49
|
def parse_contact(contact_json)
|
33
50
|
::WhatsappSdk::Resource::ContactResponse.new(input: contact_json["input"], wa_id: contact_json["wa_id"])
|
34
51
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "error_response"
|
4
5
|
|
@@ -6,18 +7,36 @@ module WhatsappSdk
|
|
6
7
|
module Api
|
7
8
|
module Responses
|
8
9
|
class MessageErrorResponse < ErrorResponse
|
9
|
-
|
10
|
+
sig { returns(Integer) }
|
11
|
+
attr_reader :code
|
10
12
|
|
13
|
+
sig { returns(T.nilable(Integer)) }
|
14
|
+
attr_reader :subcode
|
15
|
+
|
16
|
+
sig { returns(T.nilable(String)) }
|
17
|
+
attr_reader :message
|
18
|
+
|
19
|
+
sig { returns(T.nilable(String)) }
|
20
|
+
attr_reader :type
|
21
|
+
|
22
|
+
sig { returns(T.nilable(String)) }
|
23
|
+
attr_reader :data
|
24
|
+
|
25
|
+
sig { returns(T.nilable(String)) }
|
26
|
+
attr_reader :fbtrace_id
|
27
|
+
|
28
|
+
sig { params(response: T::Hash[T.untyped, T.untyped]).void }
|
11
29
|
def initialize(response:)
|
12
|
-
@code = response["code"]
|
13
|
-
@subcode = response["error_subcode"]
|
14
|
-
@message = response["message"]
|
15
|
-
@type = response["type"]
|
16
|
-
@data = response["data"]
|
17
|
-
@fbtrace_id = response["fbtrace_id"]
|
30
|
+
@code = T.let(response["code"], Integer)
|
31
|
+
@subcode = T.let(response["error_subcode"], T.nilable(Integer))
|
32
|
+
@message = T.let(response["message"], T.nilable(String))
|
33
|
+
@type = T.let(response["type"], T.nilable(String))
|
34
|
+
@data = T.let(response["data"], T.nilable(String))
|
35
|
+
@fbtrace_id = T.let(response["fbtrace_id"], T.nilable(String))
|
18
36
|
super(response: response)
|
19
37
|
end
|
20
38
|
|
39
|
+
sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(MessageErrorResponse)) }
|
21
40
|
def self.build_from_response(response:)
|
22
41
|
error_response = response["error"]
|
23
42
|
return unless error_response
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "data_response"
|
4
5
|
|
@@ -6,16 +7,28 @@ module WhatsappSdk
|
|
6
7
|
module Api
|
7
8
|
module Responses
|
8
9
|
class PhoneNumberDataResponse < DataResponse
|
9
|
-
|
10
|
+
sig { returns(String) }
|
11
|
+
attr_accessor :id
|
10
12
|
|
13
|
+
sig { returns(String) }
|
14
|
+
attr_accessor :verified_name
|
15
|
+
|
16
|
+
sig { returns(String) }
|
17
|
+
attr_accessor :display_phone_number
|
18
|
+
|
19
|
+
sig { returns(String) }
|
20
|
+
attr_accessor :quality_rating
|
21
|
+
|
22
|
+
sig { params(response: T::Hash[T.untyped, T.untyped]).void }
|
11
23
|
def initialize(response)
|
12
|
-
@id = response["id"]
|
13
|
-
@verified_name = response["verified_name"]
|
14
|
-
@display_phone_number = response["display_phone_number"]
|
15
|
-
@quality_rating = response["quality_rating"]
|
24
|
+
@id = T.let(response["id"], String)
|
25
|
+
@verified_name = T.let(response["verified_name"], String)
|
26
|
+
@display_phone_number = T.let(response["display_phone_number"], String)
|
27
|
+
@quality_rating = T.let(response["quality_rating"], String)
|
16
28
|
super(response)
|
17
29
|
end
|
18
30
|
|
31
|
+
sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(PhoneNumberDataResponse)) }
|
19
32
|
def self.build_from_response(response:)
|
20
33
|
return unless response["id"]
|
21
34
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "data_response"
|
4
5
|
require_relative "phone_number_data_response"
|
@@ -7,13 +8,19 @@ module WhatsappSdk
|
|
7
8
|
module Api
|
8
9
|
module Responses
|
9
10
|
class PhoneNumbersDataResponse < DataResponse
|
11
|
+
sig { returns(T::Array[PhoneNumberDataResponse]) }
|
10
12
|
attr_reader :phone_numbers
|
11
13
|
|
14
|
+
sig { params(response: T::Hash[T.untyped, T.untyped]).void }
|
12
15
|
def initialize(response)
|
13
|
-
@phone_numbers =
|
16
|
+
@phone_numbers = T.let(
|
17
|
+
response['data']&.map { |phone_number| parse_phone_number(phone_number) },
|
18
|
+
T::Array[PhoneNumberDataResponse]
|
19
|
+
)
|
14
20
|
super(response)
|
15
21
|
end
|
16
22
|
|
23
|
+
sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(PhoneNumbersDataResponse)) }
|
17
24
|
def self.build_from_response(response:)
|
18
25
|
return unless response["data"]
|
19
26
|
|
@@ -22,6 +29,7 @@ module WhatsappSdk
|
|
22
29
|
|
23
30
|
private
|
24
31
|
|
32
|
+
sig { params(phone_number: T::Hash[T.untyped, T.untyped]).returns(PhoneNumberDataResponse) }
|
25
33
|
def parse_phone_number(phone_number)
|
26
34
|
PhoneNumberDataResponse.new(phone_number)
|
27
35
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# typed: strict
|
2
3
|
|
3
4
|
require_relative "../request"
|
4
5
|
require_relative "data_response"
|
@@ -9,18 +10,24 @@ module WhatsappSdk
|
|
9
10
|
module Api
|
10
11
|
module Responses
|
11
12
|
class ReadMessageDataResponse < DataResponse
|
12
|
-
|
13
|
-
|
13
|
+
extend T::Sig
|
14
|
+
sig { params(response: T::Hash[T.untyped, T.untyped]).void }
|
14
15
|
def initialize(response:)
|
15
|
-
@success = response["success"]
|
16
|
+
@success = T.let(response["success"], T::Boolean)
|
16
17
|
super(response)
|
17
18
|
end
|
18
19
|
|
20
|
+
sig { override.params(response: T::Hash[T.untyped, T.untyped]).returns(T.nilable(ReadMessageDataResponse)) }
|
19
21
|
def self.build_from_response(response:)
|
20
22
|
return if response["error"]
|
21
23
|
|
22
24
|
new(response: response)
|
23
25
|
end
|
26
|
+
|
27
|
+
sig { returns(T::Boolean) }
|
28
|
+
def success?
|
29
|
+
@success
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|