ruby-whatsapp 0.3.1 → 0.4.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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -1
  3. data/README.md +292 -497
  4. data/docs/README.md +73 -0
  5. data/docs/business_phone_number/README.md +232 -0
  6. data/docs/business_phone_number/account.md +170 -0
  7. data/docs/business_phone_number/profile.md +220 -0
  8. data/docs/configuration.md +172 -0
  9. data/docs/errors.md +208 -0
  10. data/docs/media/README.md +161 -0
  11. data/docs/message_templates/README.md +206 -0
  12. data/docs/message_templates/authentication.md +107 -0
  13. data/docs/message_templates/carousel.md +103 -0
  14. data/docs/message_templates/components.md +179 -0
  15. data/docs/message_templates/library.md +98 -0
  16. data/docs/message_templates/limited_time_offer.md +94 -0
  17. data/docs/message_templates/responses.md +173 -0
  18. data/docs/message_templates/standard.md +138 -0
  19. data/docs/messages/README.md +135 -0
  20. data/docs/messages/address.md +86 -0
  21. data/docs/messages/audio.md +43 -0
  22. data/docs/messages/contacts.md +129 -0
  23. data/docs/messages/document.md +49 -0
  24. data/docs/messages/image.md +59 -0
  25. data/docs/messages/interactive.md +281 -0
  26. data/docs/messages/location.md +51 -0
  27. data/docs/messages/location_request.md +59 -0
  28. data/docs/messages/mark_message_as_read.md +84 -0
  29. data/docs/messages/reaction.md +59 -0
  30. data/docs/messages/sticker.md +40 -0
  31. data/docs/messages/template.md +166 -0
  32. data/docs/messages/text.md +55 -0
  33. data/docs/messages/video.md +41 -0
  34. data/docs/subscribed_app/README.md +139 -0
  35. data/docs/webhooks/README.md +209 -0
  36. data/docs/webhooks/account_alerts.md +44 -0
  37. data/docs/webhooks/account_review_update.md +29 -0
  38. data/docs/webhooks/account_update.md +54 -0
  39. data/docs/webhooks/automatic_events.md +47 -0
  40. data/docs/webhooks/business_capability_update.md +40 -0
  41. data/docs/webhooks/history.md +44 -0
  42. data/docs/webhooks/message_template_components_update.md +46 -0
  43. data/docs/webhooks/message_template_quality_update.md +49 -0
  44. data/docs/webhooks/message_template_status_update.md +55 -0
  45. data/docs/webhooks/messages.md +385 -0
  46. data/docs/webhooks/partner_solutions.md +35 -0
  47. data/docs/webhooks/payment_configuration_update.md +40 -0
  48. data/docs/webhooks/phone_number_name_update.md +44 -0
  49. data/docs/webhooks/phone_number_quality_update.md +40 -0
  50. data/docs/webhooks/security.md +43 -0
  51. data/docs/webhooks/smb_app_state_sync.md +53 -0
  52. data/docs/webhooks/smb_message_echoes.md +54 -0
  53. data/docs/webhooks/template_category_update.md +52 -0
  54. data/docs/webhooks/user_preferences.md +48 -0
  55. data/lib/ruby/whatsapp/business_phone_number/account/details.rb +149 -0
  56. data/lib/ruby/whatsapp/business_phone_number/account/get.rb +53 -0
  57. data/lib/ruby/whatsapp/business_phone_number/account/transport.rb +30 -0
  58. data/lib/ruby/whatsapp/business_phone_number/account/update.rb +76 -0
  59. data/lib/ruby/whatsapp/business_phone_number/account.rb +23 -0
  60. data/lib/ruby/whatsapp/business_phone_number/deregister.rb +38 -0
  61. data/lib/ruby/whatsapp/business_phone_number/profile/details.rb +105 -0
  62. data/lib/ruby/whatsapp/business_phone_number/profile/get.rb +56 -0
  63. data/lib/ruby/whatsapp/business_phone_number/profile/update.rb +148 -0
  64. data/lib/ruby/whatsapp/business_phone_number/profile/verticals.rb +54 -0
  65. data/lib/ruby/whatsapp/business_phone_number/profile.rb +22 -0
  66. data/lib/ruby/whatsapp/business_phone_number/register.rb +105 -0
  67. data/lib/ruby/whatsapp/business_phone_number/request_code.rb +85 -0
  68. data/lib/ruby/whatsapp/business_phone_number/response.rb +39 -0
  69. data/lib/ruby/whatsapp/business_phone_number/transport.rb +27 -0
  70. data/lib/ruby/whatsapp/business_phone_number/verify_code.rb +63 -0
  71. data/lib/ruby/whatsapp/business_phone_number.rb +29 -0
  72. data/lib/ruby/whatsapp/message_templates.rb +2 -6
  73. data/lib/ruby/whatsapp/path_building.rb +33 -0
  74. data/lib/ruby/whatsapp/subscribed_app/list.rb +28 -0
  75. data/lib/ruby/whatsapp/subscribed_app/response/app.rb +57 -0
  76. data/lib/ruby/whatsapp/subscribed_app/response/collection.rb +41 -0
  77. data/lib/ruby/whatsapp/subscribed_app/response/subscription.rb +49 -0
  78. data/lib/ruby/whatsapp/subscribed_app/response/unsubscription.rb +31 -0
  79. data/lib/ruby/whatsapp/subscribed_app/response.rb +19 -0
  80. data/lib/ruby/whatsapp/subscribed_app/subscribe.rb +33 -0
  81. data/lib/ruby/whatsapp/subscribed_app/transport.rb +24 -0
  82. data/lib/ruby/whatsapp/subscribed_app/unsubscribe.rb +26 -0
  83. data/lib/ruby/whatsapp/subscribed_app.rb +15 -0
  84. data/lib/ruby/whatsapp/version.rb +1 -1
  85. metadata +80 -1
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whatsapp
4
+ module SubscribedApp
5
+ module Response
6
+ # One app subscribed to a WABA's webhook notifications.
7
+ #
8
+ # Meta nests `id`/`name`/`link` inside `whatsapp_business_api_data`; this class
9
+ # flattens that away since the wrapper carries no information of its own.
10
+ # Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-account/subscribed-apps-api
11
+ class App
12
+ # @!attribute [rw] id
13
+ # @return [String, nil] The subscribed app's ID.
14
+ attr_accessor :id
15
+
16
+ # @!attribute [rw] name
17
+ # @return [String, nil] The subscribed app's name.
18
+ attr_accessor :name
19
+
20
+ # @!attribute [rw] link
21
+ # @return [String, nil] A link to the app.
22
+ attr_accessor :link
23
+
24
+ # @!attribute [rw] override_callback_uri
25
+ # @return [String, nil] The per-WABA webhook callback override, if one is set.
26
+ attr_accessor :override_callback_uri
27
+
28
+ # @param id [String, nil]
29
+ # @param name [String, nil]
30
+ # @param link [String, nil]
31
+ # @param override_callback_uri [String, nil]
32
+ def initialize(id: nil, name: nil, link: nil, override_callback_uri: nil)
33
+ @id = id
34
+ @name = name
35
+ @link = link
36
+ @override_callback_uri = override_callback_uri
37
+ end
38
+
39
+ class << self
40
+ # @param data [Hash, nil] One element of the `data` array.
41
+ # @return [App]
42
+ def deserialize(data)
43
+ data ||= {}
44
+ api_data = data["whatsapp_business_api_data"] || {}
45
+
46
+ new(
47
+ id: api_data["id"],
48
+ name: api_data["name"],
49
+ link: api_data["link"],
50
+ override_callback_uri: data["override_callback_uri"]
51
+ )
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whatsapp
4
+ module SubscribedApp
5
+ module Response
6
+ # The apps currently subscribed to a WABA's webhook notifications: `{data}`.
7
+ #
8
+ # Enumerable over its apps, so `list.map(&:name)` reads naturally without
9
+ # reaching for `.data` first.
10
+ # Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-account/subscribed-apps-api
11
+ class Collection
12
+ include Enumerable
13
+
14
+ # @!attribute [rw] data
15
+ # @return [Array<App>]
16
+ attr_accessor :data
17
+
18
+ # @param data [Array<App>]
19
+ def initialize(data: [])
20
+ @data = data
21
+ end
22
+
23
+ class << self
24
+ # @param response [Hash, nil] The parsed response body.
25
+ # @return [Collection]
26
+ def deserialize(response)
27
+ response ||= {}
28
+
29
+ new(data: Array(response["data"]).map { |entry| App.deserialize(entry) })
30
+ end
31
+ end
32
+
33
+ # @yieldparam app [App]
34
+ # @return [Enumerator]
35
+ def each(&)
36
+ data.each(&)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whatsapp
4
+ module SubscribedApp
5
+ module Response
6
+ # The response to subscribing this app to a WABA's webhook notifications:
7
+ # `{success, data}`.
8
+ #
9
+ # `data` mirrors {Collection}'s shape exactly, since Meta echoes back every app
10
+ # now subscribed — deserialization is delegated to {Collection.deserialize}
11
+ # rather than duplicating the `App` mapping.
12
+ # Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-account/subscribed-apps-api
13
+ class Subscription
14
+ include Enumerable
15
+
16
+ # @!attribute [rw] success
17
+ # @return [Boolean] Whether the subscription succeeded.
18
+ attr_accessor :success
19
+
20
+ # @!attribute [rw] data
21
+ # @return [Array<App>]
22
+ attr_accessor :data
23
+
24
+ # @param success [Boolean]
25
+ # @param data [Array<App>]
26
+ def initialize(success: false, data: [])
27
+ @success = success
28
+ @data = data
29
+ end
30
+
31
+ class << self
32
+ # @param response [Hash, nil] The parsed response body.
33
+ # @return [Subscription]
34
+ def deserialize(response)
35
+ response ||= {}
36
+
37
+ new(success: response["success"] == true, data: Collection.deserialize(response).to_a)
38
+ end
39
+ end
40
+
41
+ # @yieldparam app [App]
42
+ # @return [Enumerator]
43
+ def each(&)
44
+ data.each(&)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whatsapp
4
+ module SubscribedApp
5
+ module Response
6
+ # The response to unsubscribing this app from a WABA's webhook notifications:
7
+ # `{success}`.
8
+ # Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-account/subscribed-apps-api
9
+ class Unsubscription
10
+ # @!attribute [rw] success
11
+ # @return [Boolean] Whether the app was unsubscribed.
12
+ attr_accessor :success
13
+
14
+ # @param success [Boolean]
15
+ def initialize(success: false)
16
+ @success = success
17
+ end
18
+
19
+ class << self
20
+ # @param response [Hash, nil] The parsed response body.
21
+ # @return [Unsubscription]
22
+ def deserialize(response)
23
+ response ||= {}
24
+
25
+ new(success: response["success"] == true)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whatsapp
4
+ module SubscribedApp
5
+ # Deserializers for the responses of the `subscribed_apps` edge.
6
+ #
7
+ # Three response shapes, one per action, so a namespace of small classes rather
8
+ # than a single one with optional fields:
9
+ #
10
+ # {Collection} `{data}` List
11
+ # {Subscription} `{success, data}` Subscribe
12
+ # {Unsubscription} `{success}` Unsubscribe
13
+ #
14
+ # Every class follows the gem's `.deserialize(data)` convention and tolerates a nil
15
+ # or partial payload, so a field Meta stops sending cannot raise.
16
+ module Response
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whatsapp
4
+ module SubscribedApp
5
+ # Subscribes this app to a WABA's webhook notifications.
6
+ #
7
+ # `override_callback_uri`/`verify_token` are for Tech Providers routing several
8
+ # WABAs' notifications to different callback URLs instead of the one configured on
9
+ # the app itself.
10
+ # Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-account/subscribed-apps-api
11
+ class Subscribe
12
+ extend ResponseHandling
13
+ extend Transport
14
+
15
+ class << self
16
+ # @param client [Whatsapp::Client] The WhatsApp client instance.
17
+ # @param override_callback_uri [String, nil] A per-WABA webhook callback override.
18
+ # @param verify_token [String, nil] The token Meta echoes back if it re-verifies
19
+ # `override_callback_uri`.
20
+ # @return [Response::Subscription]
21
+ # @raise [Error] if no WABA ID is configured, or the request fails.
22
+ def call(client: Client.new, override_callback_uri: nil, verify_token: nil)
23
+ body = { override_callback_uri:, verify_token: }.compact
24
+ response = client.connection.post(edge_path(client), json: body)
25
+
26
+ Response::Subscription.deserialize(
27
+ parse_json(handle_response!(response, error_class: Error, action: "subscribe app"))
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whatsapp
4
+ module SubscribedApp
5
+ # The one piece shared by {List}, {Subscribe}, and {Unsubscribe}: all three address
6
+ # the same WABA-scoped edge, differing only in HTTP verb and body. Extended (not
7
+ # included) since those classes are class-method-only.
8
+ #
9
+ # The guard itself and its message live in {Whatsapp::PathBuilding}, shared with every
10
+ # other ID-scoped feature; what stays here is the edge this module addresses.
11
+ module Transport
12
+ include Whatsapp::PathBuilding
13
+
14
+ private
15
+
16
+ # @param client [Whatsapp::Client]
17
+ # @return [String] The versioned path to the `subscribed_apps` edge.
18
+ # @raise [Error] if no WABA ID is configured.
19
+ def edge_path(client)
20
+ scoped_path(client, :waba_id, "subscribed_apps", error_class: Error, purpose: "subscribed apps")
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whatsapp
4
+ module SubscribedApp
5
+ # Unsubscribes this app from a WABA's webhook notifications. All webhook
6
+ # deliveries for that WABA stop immediately.
7
+ # Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-account/subscribed-apps-api
8
+ class Unsubscribe
9
+ extend ResponseHandling
10
+ extend Transport
11
+
12
+ class << self
13
+ # @param client [Whatsapp::Client] The WhatsApp client instance.
14
+ # @return [Response::Unsubscription]
15
+ # @raise [Error] if no WABA ID is configured, or the request fails.
16
+ def call(client: Client.new)
17
+ response = client.connection.delete(edge_path(client))
18
+
19
+ Response::Unsubscription.deserialize(
20
+ parse_json(handle_response!(response, error_class: Error, action: "unsubscribe app"))
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whatsapp
4
+ # Subscribes or unsubscribes this app from a WhatsApp Business Account's webhook
5
+ # notifications, and lists which apps are currently subscribed.
6
+ #
7
+ # This is what turns webhook delivery on and off in the first place — the opposite
8
+ # concern from {Whatsapp::Webhook}, which only deserializes notifications once Meta
9
+ # is already sending them. Addresses `waba_id`, not `phone_id`, like
10
+ # {Whatsapp::MessageTemplates}. See `lib/ruby/whatsapp/subscribed_app/CLAUDE.md`.
11
+ # Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-account/subscribed-apps-api
12
+ module SubscribedApp
13
+ class Error < Whatsapp::Error; end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Whatsapp
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-whatsapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raniery
@@ -82,7 +82,75 @@ files:
82
82
  - LICENSE.txt
83
83
  - README.md
84
84
  - Rakefile
85
+ - docs/README.md
86
+ - docs/business_phone_number/README.md
87
+ - docs/business_phone_number/account.md
88
+ - docs/business_phone_number/profile.md
89
+ - docs/configuration.md
90
+ - docs/errors.md
91
+ - docs/media/README.md
92
+ - docs/message_templates/README.md
93
+ - docs/message_templates/authentication.md
94
+ - docs/message_templates/carousel.md
95
+ - docs/message_templates/components.md
96
+ - docs/message_templates/library.md
97
+ - docs/message_templates/limited_time_offer.md
98
+ - docs/message_templates/responses.md
99
+ - docs/message_templates/standard.md
100
+ - docs/messages/README.md
101
+ - docs/messages/address.md
102
+ - docs/messages/audio.md
103
+ - docs/messages/contacts.md
104
+ - docs/messages/document.md
105
+ - docs/messages/image.md
106
+ - docs/messages/interactive.md
107
+ - docs/messages/location.md
108
+ - docs/messages/location_request.md
109
+ - docs/messages/mark_message_as_read.md
110
+ - docs/messages/reaction.md
111
+ - docs/messages/sticker.md
112
+ - docs/messages/template.md
113
+ - docs/messages/text.md
114
+ - docs/messages/video.md
115
+ - docs/subscribed_app/README.md
116
+ - docs/webhooks/README.md
117
+ - docs/webhooks/account_alerts.md
118
+ - docs/webhooks/account_review_update.md
119
+ - docs/webhooks/account_update.md
120
+ - docs/webhooks/automatic_events.md
121
+ - docs/webhooks/business_capability_update.md
122
+ - docs/webhooks/history.md
123
+ - docs/webhooks/message_template_components_update.md
124
+ - docs/webhooks/message_template_quality_update.md
125
+ - docs/webhooks/message_template_status_update.md
126
+ - docs/webhooks/messages.md
127
+ - docs/webhooks/partner_solutions.md
128
+ - docs/webhooks/payment_configuration_update.md
129
+ - docs/webhooks/phone_number_name_update.md
130
+ - docs/webhooks/phone_number_quality_update.md
131
+ - docs/webhooks/security.md
132
+ - docs/webhooks/smb_app_state_sync.md
133
+ - docs/webhooks/smb_message_echoes.md
134
+ - docs/webhooks/template_category_update.md
135
+ - docs/webhooks/user_preferences.md
85
136
  - lib/ruby/whatsapp.rb
137
+ - lib/ruby/whatsapp/business_phone_number.rb
138
+ - lib/ruby/whatsapp/business_phone_number/account.rb
139
+ - lib/ruby/whatsapp/business_phone_number/account/details.rb
140
+ - lib/ruby/whatsapp/business_phone_number/account/get.rb
141
+ - lib/ruby/whatsapp/business_phone_number/account/transport.rb
142
+ - lib/ruby/whatsapp/business_phone_number/account/update.rb
143
+ - lib/ruby/whatsapp/business_phone_number/deregister.rb
144
+ - lib/ruby/whatsapp/business_phone_number/profile.rb
145
+ - lib/ruby/whatsapp/business_phone_number/profile/details.rb
146
+ - lib/ruby/whatsapp/business_phone_number/profile/get.rb
147
+ - lib/ruby/whatsapp/business_phone_number/profile/update.rb
148
+ - lib/ruby/whatsapp/business_phone_number/profile/verticals.rb
149
+ - lib/ruby/whatsapp/business_phone_number/register.rb
150
+ - lib/ruby/whatsapp/business_phone_number/request_code.rb
151
+ - lib/ruby/whatsapp/business_phone_number/response.rb
152
+ - lib/ruby/whatsapp/business_phone_number/transport.rb
153
+ - lib/ruby/whatsapp/business_phone_number/verify_code.rb
86
154
  - lib/ruby/whatsapp/client.rb
87
155
  - lib/ruby/whatsapp/configuration.rb
88
156
  - lib/ruby/whatsapp/instrumentation.rb
@@ -168,9 +236,20 @@ files:
168
236
  - lib/ruby/whatsapp/messages/template/parameter.rb
169
237
  - lib/ruby/whatsapp/messages/text.rb
170
238
  - lib/ruby/whatsapp/messages/video.rb
239
+ - lib/ruby/whatsapp/path_building.rb
171
240
  - lib/ruby/whatsapp/railtie.rb
172
241
  - lib/ruby/whatsapp/request_error.rb
173
242
  - lib/ruby/whatsapp/response_handling.rb
243
+ - lib/ruby/whatsapp/subscribed_app.rb
244
+ - lib/ruby/whatsapp/subscribed_app/list.rb
245
+ - lib/ruby/whatsapp/subscribed_app/response.rb
246
+ - lib/ruby/whatsapp/subscribed_app/response/app.rb
247
+ - lib/ruby/whatsapp/subscribed_app/response/collection.rb
248
+ - lib/ruby/whatsapp/subscribed_app/response/subscription.rb
249
+ - lib/ruby/whatsapp/subscribed_app/response/unsubscription.rb
250
+ - lib/ruby/whatsapp/subscribed_app/subscribe.rb
251
+ - lib/ruby/whatsapp/subscribed_app/transport.rb
252
+ - lib/ruby/whatsapp/subscribed_app/unsubscribe.rb
174
253
  - lib/ruby/whatsapp/utils/language_codes.rb
175
254
  - lib/ruby/whatsapp/version.rb
176
255
  - lib/ruby/whatsapp/webhook.rb