ruby-whatsapp 0.3.0
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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +54 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +15 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +643 -0
- data/Rakefile +12 -0
- data/lib/ruby/whatsapp/client.rb +82 -0
- data/lib/ruby/whatsapp/configuration.rb +79 -0
- data/lib/ruby/whatsapp/instrumentation.rb +34 -0
- data/lib/ruby/whatsapp/media.rb +134 -0
- data/lib/ruby/whatsapp/message_templates/button/base.rb +26 -0
- data/lib/ruby/whatsapp/message_templates/button/copy_code.rb +59 -0
- data/lib/ruby/whatsapp/message_templates/button/otp/supported_app.rb +44 -0
- data/lib/ruby/whatsapp/message_templates/button/otp.rb +138 -0
- data/lib/ruby/whatsapp/message_templates/button/phone_number.rb +45 -0
- data/lib/ruby/whatsapp/message_templates/button/quick_reply.rb +38 -0
- data/lib/ruby/whatsapp/message_templates/button/url.rb +110 -0
- data/lib/ruby/whatsapp/message_templates/button.rb +56 -0
- data/lib/ruby/whatsapp/message_templates/categories.rb +47 -0
- data/lib/ruby/whatsapp/message_templates/component/base.rb +112 -0
- data/lib/ruby/whatsapp/message_templates/component/body.rb +139 -0
- data/lib/ruby/whatsapp/message_templates/component/buttons.rb +95 -0
- data/lib/ruby/whatsapp/message_templates/component/carousel/card.rb +100 -0
- data/lib/ruby/whatsapp/message_templates/component/carousel.rb +71 -0
- data/lib/ruby/whatsapp/message_templates/component/footer.rb +99 -0
- data/lib/ruby/whatsapp/message_templates/component/header.rb +188 -0
- data/lib/ruby/whatsapp/message_templates/component/limited_time_offer.rb +57 -0
- data/lib/ruby/whatsapp/message_templates/component.rb +62 -0
- data/lib/ruby/whatsapp/message_templates/component_set.rb +221 -0
- data/lib/ruby/whatsapp/message_templates/example.rb +148 -0
- data/lib/ruby/whatsapp/message_templates/library_template/body_inputs.rb +81 -0
- data/lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb +146 -0
- data/lib/ruby/whatsapp/message_templates/library_template.rb +114 -0
- data/lib/ruby/whatsapp/message_templates/parameter_formats.rb +49 -0
- data/lib/ruby/whatsapp/message_templates/placeholders.rb +86 -0
- data/lib/ruby/whatsapp/message_templates/response/collection.rb +74 -0
- data/lib/ruby/whatsapp/message_templates/response/created.rb +65 -0
- data/lib/ruby/whatsapp/message_templates/response/node.rb +152 -0
- data/lib/ruby/whatsapp/message_templates/response/paging.rb +39 -0
- data/lib/ruby/whatsapp/message_templates/response/quality_score.rb +49 -0
- data/lib/ruby/whatsapp/message_templates/response/summary.rb +68 -0
- data/lib/ruby/whatsapp/message_templates/response.rb +22 -0
- data/lib/ruby/whatsapp/message_templates/statuses.rb +66 -0
- data/lib/ruby/whatsapp/message_templates/template.rb +180 -0
- data/lib/ruby/whatsapp/message_templates/value_object.rb +62 -0
- data/lib/ruby/whatsapp/message_templates.rb +283 -0
- data/lib/ruby/whatsapp/messages/address.rb +103 -0
- data/lib/ruby/whatsapp/messages/audio.rb +64 -0
- data/lib/ruby/whatsapp/messages/base.rb +46 -0
- data/lib/ruby/whatsapp/messages/contacts/address.rb +84 -0
- data/lib/ruby/whatsapp/messages/contacts/contact.rb +78 -0
- data/lib/ruby/whatsapp/messages/contacts/email.rb +49 -0
- data/lib/ruby/whatsapp/messages/contacts/name.rb +68 -0
- data/lib/ruby/whatsapp/messages/contacts/org.rb +41 -0
- data/lib/ruby/whatsapp/messages/contacts/phone.rb +59 -0
- data/lib/ruby/whatsapp/messages/contacts/url.rb +51 -0
- data/lib/ruby/whatsapp/messages/contacts.rb +37 -0
- data/lib/ruby/whatsapp/messages/document.rb +79 -0
- data/lib/ruby/whatsapp/messages/image.rb +72 -0
- data/lib/ruby/whatsapp/messages/interactive/base.rb +15 -0
- data/lib/ruby/whatsapp/messages/interactive/body.rb +39 -0
- data/lib/ruby/whatsapp/messages/interactive/footer.rb +40 -0
- data/lib/ruby/whatsapp/messages/interactive/header.rb +102 -0
- data/lib/ruby/whatsapp/messages/interactive/list_buttons/section/row.rb +66 -0
- data/lib/ruby/whatsapp/messages/interactive/list_buttons/section.rb +64 -0
- data/lib/ruby/whatsapp/messages/interactive/list_buttons.rb +63 -0
- data/lib/ruby/whatsapp/messages/interactive/media_carousel/card/button/quick_reply.rb +50 -0
- data/lib/ruby/whatsapp/messages/interactive/media_carousel/card/button.rb +47 -0
- data/lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb +78 -0
- data/lib/ruby/whatsapp/messages/interactive/media_carousel.rb +50 -0
- data/lib/ruby/whatsapp/messages/interactive/product_carousel/card.rb +55 -0
- data/lib/ruby/whatsapp/messages/interactive/product_carousel.rb +50 -0
- data/lib/ruby/whatsapp/messages/interactive/reply_buttons/button.rb +59 -0
- data/lib/ruby/whatsapp/messages/interactive/reply_buttons.rb +47 -0
- data/lib/ruby/whatsapp/messages/interactive/url_button.rb +68 -0
- data/lib/ruby/whatsapp/messages/interactive.rb +112 -0
- data/lib/ruby/whatsapp/messages/location.rb +67 -0
- data/lib/ruby/whatsapp/messages/location_request.rb +41 -0
- data/lib/ruby/whatsapp/messages/mark_message_as_read.rb +42 -0
- data/lib/ruby/whatsapp/messages/reaction.rb +61 -0
- data/lib/ruby/whatsapp/messages/response/contacts.rb +36 -0
- data/lib/ruby/whatsapp/messages/response/messages.rb +27 -0
- data/lib/ruby/whatsapp/messages/response.rb +49 -0
- data/lib/ruby/whatsapp/messages/sticker.rb +62 -0
- data/lib/ruby/whatsapp/messages/template/component.rb +67 -0
- data/lib/ruby/whatsapp/messages/template/language.rb +55 -0
- data/lib/ruby/whatsapp/messages/template/parameter.rb +113 -0
- data/lib/ruby/whatsapp/messages/template.rb +62 -0
- data/lib/ruby/whatsapp/messages/text.rb +43 -0
- data/lib/ruby/whatsapp/messages/video.rb +68 -0
- data/lib/ruby/whatsapp/messages.rb +116 -0
- data/lib/ruby/whatsapp/railtie.rb +14 -0
- data/lib/ruby/whatsapp/request_error.rb +5 -0
- data/lib/ruby/whatsapp/response_handling.rb +44 -0
- data/lib/ruby/whatsapp/utils/language_codes.rb +96 -0
- data/lib/ruby/whatsapp/version.rb +5 -0
- data/lib/ruby/whatsapp/webhook/account_alerts.rb +58 -0
- data/lib/ruby/whatsapp/webhook/account_review_update.rb +27 -0
- data/lib/ruby/whatsapp/webhook/account_update/ban_info.rb +33 -0
- data/lib/ruby/whatsapp/webhook/account_update.rb +46 -0
- data/lib/ruby/whatsapp/webhook/automatic_events.rb +43 -0
- data/lib/ruby/whatsapp/webhook/business_capability_update.rb +36 -0
- data/lib/ruby/whatsapp/webhook/change.rb +61 -0
- data/lib/ruby/whatsapp/webhook/contact.rb +36 -0
- data/lib/ruby/whatsapp/webhook/entry.rb +35 -0
- data/lib/ruby/whatsapp/webhook/error.rb +47 -0
- data/lib/ruby/whatsapp/webhook/history.rb +54 -0
- data/lib/ruby/whatsapp/webhook/installer.rb +61 -0
- data/lib/ruby/whatsapp/webhook/message/audio.rb +28 -0
- data/lib/ruby/whatsapp/webhook/message/base.rb +61 -0
- data/lib/ruby/whatsapp/webhook/message/button.rb +33 -0
- data/lib/ruby/whatsapp/webhook/message/contacts/address.rb +68 -0
- data/lib/ruby/whatsapp/webhook/message/contacts/contact.rb +68 -0
- data/lib/ruby/whatsapp/webhook/message/contacts/email.rb +35 -0
- data/lib/ruby/whatsapp/webhook/message/contacts/name.rb +62 -0
- data/lib/ruby/whatsapp/webhook/message/contacts/org.rb +40 -0
- data/lib/ruby/whatsapp/webhook/message/contacts/phone.rb +40 -0
- data/lib/ruby/whatsapp/webhook/message/contacts/url.rb +35 -0
- data/lib/ruby/whatsapp/webhook/message/contacts.rb +31 -0
- data/lib/ruby/whatsapp/webhook/message/context.rb +49 -0
- data/lib/ruby/whatsapp/webhook/message/document.rb +32 -0
- data/lib/ruby/whatsapp/webhook/message/image.rb +18 -0
- data/lib/ruby/whatsapp/webhook/message/interactive.rb +53 -0
- data/lib/ruby/whatsapp/webhook/message/location.rb +49 -0
- data/lib/ruby/whatsapp/webhook/message/media.rb +54 -0
- data/lib/ruby/whatsapp/webhook/message/order/product_item.rb +50 -0
- data/lib/ruby/whatsapp/webhook/message/order.rb +43 -0
- data/lib/ruby/whatsapp/webhook/message/reaction.rb +37 -0
- data/lib/ruby/whatsapp/webhook/message/referral.rb +80 -0
- data/lib/ruby/whatsapp/webhook/message/sticker.rb +32 -0
- data/lib/ruby/whatsapp/webhook/message/system.rb +49 -0
- data/lib/ruby/whatsapp/webhook/message/text.rb +28 -0
- data/lib/ruby/whatsapp/webhook/message/unknown.rb +39 -0
- data/lib/ruby/whatsapp/webhook/message/video.rb +18 -0
- data/lib/ruby/whatsapp/webhook/message.rb +39 -0
- data/lib/ruby/whatsapp/webhook/message_template_components_update.rb +53 -0
- data/lib/ruby/whatsapp/webhook/message_template_quality_update.rb +59 -0
- data/lib/ruby/whatsapp/webhook/message_template_status_update.rb +54 -0
- data/lib/ruby/whatsapp/webhook/messages.rb +55 -0
- data/lib/ruby/whatsapp/webhook/metadata.rb +35 -0
- data/lib/ruby/whatsapp/webhook/notification.rb +36 -0
- data/lib/ruby/whatsapp/webhook/partner_solutions.rb +36 -0
- data/lib/ruby/whatsapp/webhook/payment_configuration_update.rb +51 -0
- data/lib/ruby/whatsapp/webhook/phone_number_name_update.rb +51 -0
- data/lib/ruby/whatsapp/webhook/phone_number_quality_update.rb +45 -0
- data/lib/ruby/whatsapp/webhook/security.rb +41 -0
- data/lib/ruby/whatsapp/webhook/signature.rb +28 -0
- data/lib/ruby/whatsapp/webhook/smb_app_state_sync/state_sync.rb +38 -0
- data/lib/ruby/whatsapp/webhook/smb_app_state_sync.rb +33 -0
- data/lib/ruby/whatsapp/webhook/smb_message_echoes.rb +48 -0
- data/lib/ruby/whatsapp/webhook/status/conversation.rb +42 -0
- data/lib/ruby/whatsapp/webhook/status/pricing.rb +38 -0
- data/lib/ruby/whatsapp/webhook/status.rb +65 -0
- data/lib/ruby/whatsapp/webhook/template_category_update.rb +64 -0
- data/lib/ruby/whatsapp/webhook/templates/webhooks_controller.rb.tt +31 -0
- data/lib/ruby/whatsapp/webhook/unknown_field.rb +37 -0
- data/lib/ruby/whatsapp/webhook/user_preferences.rb +47 -0
- data/lib/ruby/whatsapp/webhook/verification.rb +27 -0
- data/lib/ruby/whatsapp/webhook.rb +8 -0
- data/lib/ruby/whatsapp.rb +49 -0
- data/lib/tasks/whatsapp.rake +10 -0
- data/sig/ruby/whatsapp.rbs +6 -0
- metadata +267 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whatsapp
|
|
4
|
+
module Webhook
|
|
5
|
+
# Template category changes and re-categorization corrections.
|
|
6
|
+
#
|
|
7
|
+
# Best-effort schema: Meta's public docs describe this field in one line with
|
|
8
|
+
# no published JSON example. Validate against a real payload (App Dashboard
|
|
9
|
+
# "send test payload") before relying on these attribute names in production.
|
|
10
|
+
# Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/overview
|
|
11
|
+
class TemplateCategoryUpdate
|
|
12
|
+
# @!attribute [rw] message_template_id
|
|
13
|
+
# @return [Integer, nil]
|
|
14
|
+
attr_accessor :message_template_id
|
|
15
|
+
|
|
16
|
+
# @!attribute [rw] message_template_name
|
|
17
|
+
# @return [String, nil]
|
|
18
|
+
attr_accessor :message_template_name
|
|
19
|
+
|
|
20
|
+
# @!attribute [rw] message_template_language
|
|
21
|
+
# @return [String, nil]
|
|
22
|
+
attr_accessor :message_template_language
|
|
23
|
+
|
|
24
|
+
# @!attribute [rw] previous_category
|
|
25
|
+
# @return [String, nil]
|
|
26
|
+
attr_accessor :previous_category
|
|
27
|
+
|
|
28
|
+
# @!attribute [rw] new_category
|
|
29
|
+
# @return [String, nil]
|
|
30
|
+
attr_accessor :new_category
|
|
31
|
+
|
|
32
|
+
# @!attribute [rw] correct_category
|
|
33
|
+
# @return [String, nil]
|
|
34
|
+
attr_accessor :correct_category
|
|
35
|
+
|
|
36
|
+
def initialize(message_template_id:, message_template_name:, message_template_language:,
|
|
37
|
+
previous_category:, new_category:, correct_category: nil)
|
|
38
|
+
@message_template_id = message_template_id
|
|
39
|
+
@message_template_name = message_template_name
|
|
40
|
+
@message_template_language = message_template_language
|
|
41
|
+
@previous_category = previous_category
|
|
42
|
+
@new_category = new_category
|
|
43
|
+
@correct_category = correct_category
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class << self
|
|
47
|
+
# @param data [Hash] The raw `value` hash.
|
|
48
|
+
# @return [TemplateCategoryUpdate]
|
|
49
|
+
def deserialize(data)
|
|
50
|
+
data ||= {}
|
|
51
|
+
|
|
52
|
+
new(
|
|
53
|
+
message_template_id: data["message_template_id"],
|
|
54
|
+
message_template_name: data["message_template_name"],
|
|
55
|
+
message_template_language: data["message_template_language"],
|
|
56
|
+
previous_category: data["previous_category"],
|
|
57
|
+
new_category: data["new_category"],
|
|
58
|
+
correct_category: data["correct_category"]
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whatsapp
|
|
4
|
+
class WebhooksController < ApplicationController
|
|
5
|
+
skip_before_action :verify_authenticity_token, raise: false
|
|
6
|
+
|
|
7
|
+
# GET — Meta calls this once when you save the callback URL in the App Dashboard.
|
|
8
|
+
def verify
|
|
9
|
+
challenge = Whatsapp::Webhook::Verification.call(params: params)
|
|
10
|
+
return head :forbidden unless challenge
|
|
11
|
+
|
|
12
|
+
render plain: challenge
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# POST — Meta calls this for every event notification.
|
|
16
|
+
def receive
|
|
17
|
+
raw_body = request.body.read
|
|
18
|
+
|
|
19
|
+
unless Whatsapp::Webhook::Signature.valid?(payload: raw_body, header: request.headers["X-Hub-Signature-256"])
|
|
20
|
+
return head :unauthorized
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
notification = Whatsapp::Webhook::Notification.deserialize(JSON.parse(raw_body))
|
|
24
|
+
|
|
25
|
+
# TODO: your business logic here, e.g.:
|
|
26
|
+
# notification.entry.each { |entry| entry.changes.each { |change| WebhookJob.perform_later(change) } }
|
|
27
|
+
|
|
28
|
+
head :ok
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whatsapp
|
|
4
|
+
module Webhook
|
|
5
|
+
# Fallback value wrapper for any webhook `field` not in {Change::FIELDS} — either
|
|
6
|
+
# a field Meta added after this gem was released, or one deliberately left generic.
|
|
7
|
+
# Keeps the raw hash accessible instead of raising on an unrecognized notification.
|
|
8
|
+
class UnknownField
|
|
9
|
+
# @!attribute [r] raw
|
|
10
|
+
# @return [Hash]
|
|
11
|
+
attr_reader :raw
|
|
12
|
+
|
|
13
|
+
def initialize(raw:)
|
|
14
|
+
@raw = raw
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @param key [String]
|
|
18
|
+
# @return [Object, nil]
|
|
19
|
+
def [](key)
|
|
20
|
+
raw[key]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [Hash]
|
|
24
|
+
def to_h
|
|
25
|
+
raw
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class << self
|
|
29
|
+
# @param data [Hash, nil] The raw `value` hash.
|
|
30
|
+
# @return [UnknownField]
|
|
31
|
+
def deserialize(data)
|
|
32
|
+
new(raw: data || {})
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whatsapp
|
|
4
|
+
module Webhook
|
|
5
|
+
# User marketing message preference changes (e.g. a customer opting out of
|
|
6
|
+
# marketing messages).
|
|
7
|
+
#
|
|
8
|
+
# Best-effort schema: Meta's public docs describe this field in one line with
|
|
9
|
+
# no published JSON example. Validate against a real payload (App Dashboard
|
|
10
|
+
# "send test payload") before relying on these attribute names in production.
|
|
11
|
+
# Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/overview
|
|
12
|
+
class UserPreferences
|
|
13
|
+
# @!attribute [rw] wa_id
|
|
14
|
+
# @return [String, nil]
|
|
15
|
+
attr_accessor :wa_id
|
|
16
|
+
|
|
17
|
+
# @!attribute [rw] detail
|
|
18
|
+
# @return [String, nil]
|
|
19
|
+
attr_accessor :detail
|
|
20
|
+
|
|
21
|
+
# @!attribute [rw] value
|
|
22
|
+
# @return [String, nil] e.g. `"stop"`, `"resume"`.
|
|
23
|
+
attr_accessor :value
|
|
24
|
+
|
|
25
|
+
# @!attribute [rw] timestamp
|
|
26
|
+
# @return [String, nil]
|
|
27
|
+
attr_accessor :timestamp
|
|
28
|
+
|
|
29
|
+
def initialize(wa_id:, detail:, value:, timestamp:)
|
|
30
|
+
@wa_id = wa_id
|
|
31
|
+
@detail = detail
|
|
32
|
+
@value = value
|
|
33
|
+
@timestamp = timestamp
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class << self
|
|
37
|
+
# @param data [Hash] The raw `value` hash.
|
|
38
|
+
# @return [UserPreferences]
|
|
39
|
+
def deserialize(data)
|
|
40
|
+
data ||= {}
|
|
41
|
+
|
|
42
|
+
new(wa_id: data["wa_id"], detail: data["detail"], value: data["value"], timestamp: data["timestamp"])
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whatsapp
|
|
4
|
+
module Webhook
|
|
5
|
+
# Handles the one-time GET handshake Meta sends when a webhook callback URL is
|
|
6
|
+
# registered in the App Dashboard: `hub.mode`, `hub.verify_token`, `hub.challenge`.
|
|
7
|
+
# Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/overview
|
|
8
|
+
class Verification
|
|
9
|
+
class << self
|
|
10
|
+
# @param params [Hash] The request params, string-keyed as Rails provides them
|
|
11
|
+
# (e.g. `params["hub.mode"]`, `params["hub.verify_token"]`, `params["hub.challenge"]`).
|
|
12
|
+
# @param verify_token [String, nil] The token to check against. Defaults to the
|
|
13
|
+
# globally configured token; pass an explicit value for multi-tenant apps where
|
|
14
|
+
# each account has its own token.
|
|
15
|
+
# @return [String, nil] The `hub.challenge` value to echo back, or `nil` if the
|
|
16
|
+
# request doesn't match a subscribe handshake with the expected token.
|
|
17
|
+
def call(params:, verify_token: Whatsapp.configuration.verify_token)
|
|
18
|
+
return unless params["hub.mode"] == "subscribe"
|
|
19
|
+
return if verify_token.nil? || verify_token.empty?
|
|
20
|
+
return unless ActiveSupport::SecurityUtils.secure_compare(params["hub.verify_token"].to_s, verify_token)
|
|
21
|
+
|
|
22
|
+
params["hub.challenge"]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Whatsapp
|
|
4
|
+
# Deserializes and authenticates incoming WhatsApp Cloud API webhook notifications.
|
|
5
|
+
# Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/overview
|
|
6
|
+
module Webhook
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "logger"
|
|
5
|
+
require "uri"
|
|
6
|
+
require "http"
|
|
7
|
+
require "zeitwerk"
|
|
8
|
+
require "active_model"
|
|
9
|
+
require "active_support/security_utils"
|
|
10
|
+
require "openssl"
|
|
11
|
+
require "fileutils"
|
|
12
|
+
|
|
13
|
+
loader = Zeitwerk::Loader.for_gem
|
|
14
|
+
loader.collapse(__dir__)
|
|
15
|
+
# The Railtie must be required eagerly (below), not autoloaded, so it's excluded here.
|
|
16
|
+
loader.ignore("#{__dir__}/whatsapp/railtie.rb")
|
|
17
|
+
loader.setup
|
|
18
|
+
|
|
19
|
+
module Whatsapp
|
|
20
|
+
class Error < StandardError; end
|
|
21
|
+
|
|
22
|
+
class << self
|
|
23
|
+
attr_writer :configuration
|
|
24
|
+
|
|
25
|
+
# Returns the global configuration, lazily initializing it on first use.
|
|
26
|
+
# @return [Whatsapp::Configuration]
|
|
27
|
+
def configuration
|
|
28
|
+
@configuration ||= Configuration.new
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Yields the configuration for mutation and returns it.
|
|
32
|
+
# @yieldparam configuration [Whatsapp::Configuration]
|
|
33
|
+
# @return [Whatsapp::Configuration]
|
|
34
|
+
def configure
|
|
35
|
+
yield(configuration) if block_given?
|
|
36
|
+
|
|
37
|
+
configuration
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Exposed so the whole constant tree can be eagerly loaded (used in tests to
|
|
43
|
+
# guarantee every file resolves under Zeitwerk).
|
|
44
|
+
Whatsapp.define_singleton_method(:eager_load!) { loader.eager_load }
|
|
45
|
+
|
|
46
|
+
# Rails discovers Railtie subclasses at boot by class definition, so this must be
|
|
47
|
+
# required eagerly (never autoloaded) — and only when Rails is actually present,
|
|
48
|
+
# since this gem has no Rails dependency of its own.
|
|
49
|
+
require_relative "whatsapp/railtie" if defined?(Rails::Railtie)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :whatsapp do
|
|
4
|
+
namespace :install do
|
|
5
|
+
desc "Install a personalizable WhatsApp webhook controller into this Rails app"
|
|
6
|
+
task webhook: :environment do
|
|
7
|
+
Whatsapp::Webhook::Installer.call(root: Rails.root)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby-whatsapp
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Raniery
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: activemodel
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '7.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '7.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: http
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '5.1'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '5.1'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: logger
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.0'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: zeitwerk
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '2.6'
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '2.6'
|
|
68
|
+
description: 'A small, dependency-light Ruby client for the Meta WhatsApp Cloud API:
|
|
69
|
+
send text, media, template, interactive, and other message types, and upload, download,
|
|
70
|
+
and manage media assets.'
|
|
71
|
+
email:
|
|
72
|
+
- raniery@saleszera.com
|
|
73
|
+
executables: []
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".rubocop.yml"
|
|
79
|
+
- ".ruby-version"
|
|
80
|
+
- CHANGELOG.md
|
|
81
|
+
- CODE_OF_CONDUCT.md
|
|
82
|
+
- LICENSE.txt
|
|
83
|
+
- README.md
|
|
84
|
+
- Rakefile
|
|
85
|
+
- lib/ruby/whatsapp.rb
|
|
86
|
+
- lib/ruby/whatsapp/client.rb
|
|
87
|
+
- lib/ruby/whatsapp/configuration.rb
|
|
88
|
+
- lib/ruby/whatsapp/instrumentation.rb
|
|
89
|
+
- lib/ruby/whatsapp/media.rb
|
|
90
|
+
- lib/ruby/whatsapp/message_templates.rb
|
|
91
|
+
- lib/ruby/whatsapp/message_templates/button.rb
|
|
92
|
+
- lib/ruby/whatsapp/message_templates/button/base.rb
|
|
93
|
+
- lib/ruby/whatsapp/message_templates/button/copy_code.rb
|
|
94
|
+
- lib/ruby/whatsapp/message_templates/button/otp.rb
|
|
95
|
+
- lib/ruby/whatsapp/message_templates/button/otp/supported_app.rb
|
|
96
|
+
- lib/ruby/whatsapp/message_templates/button/phone_number.rb
|
|
97
|
+
- lib/ruby/whatsapp/message_templates/button/quick_reply.rb
|
|
98
|
+
- lib/ruby/whatsapp/message_templates/button/url.rb
|
|
99
|
+
- lib/ruby/whatsapp/message_templates/categories.rb
|
|
100
|
+
- lib/ruby/whatsapp/message_templates/component.rb
|
|
101
|
+
- lib/ruby/whatsapp/message_templates/component/base.rb
|
|
102
|
+
- lib/ruby/whatsapp/message_templates/component/body.rb
|
|
103
|
+
- lib/ruby/whatsapp/message_templates/component/buttons.rb
|
|
104
|
+
- lib/ruby/whatsapp/message_templates/component/carousel.rb
|
|
105
|
+
- lib/ruby/whatsapp/message_templates/component/carousel/card.rb
|
|
106
|
+
- lib/ruby/whatsapp/message_templates/component/footer.rb
|
|
107
|
+
- lib/ruby/whatsapp/message_templates/component/header.rb
|
|
108
|
+
- lib/ruby/whatsapp/message_templates/component/limited_time_offer.rb
|
|
109
|
+
- lib/ruby/whatsapp/message_templates/component_set.rb
|
|
110
|
+
- lib/ruby/whatsapp/message_templates/example.rb
|
|
111
|
+
- lib/ruby/whatsapp/message_templates/library_template.rb
|
|
112
|
+
- lib/ruby/whatsapp/message_templates/library_template/body_inputs.rb
|
|
113
|
+
- lib/ruby/whatsapp/message_templates/library_template/button_inputs.rb
|
|
114
|
+
- lib/ruby/whatsapp/message_templates/parameter_formats.rb
|
|
115
|
+
- lib/ruby/whatsapp/message_templates/placeholders.rb
|
|
116
|
+
- lib/ruby/whatsapp/message_templates/response.rb
|
|
117
|
+
- lib/ruby/whatsapp/message_templates/response/collection.rb
|
|
118
|
+
- lib/ruby/whatsapp/message_templates/response/created.rb
|
|
119
|
+
- lib/ruby/whatsapp/message_templates/response/node.rb
|
|
120
|
+
- lib/ruby/whatsapp/message_templates/response/paging.rb
|
|
121
|
+
- lib/ruby/whatsapp/message_templates/response/quality_score.rb
|
|
122
|
+
- lib/ruby/whatsapp/message_templates/response/summary.rb
|
|
123
|
+
- lib/ruby/whatsapp/message_templates/statuses.rb
|
|
124
|
+
- lib/ruby/whatsapp/message_templates/template.rb
|
|
125
|
+
- lib/ruby/whatsapp/message_templates/value_object.rb
|
|
126
|
+
- lib/ruby/whatsapp/messages.rb
|
|
127
|
+
- lib/ruby/whatsapp/messages/address.rb
|
|
128
|
+
- lib/ruby/whatsapp/messages/audio.rb
|
|
129
|
+
- lib/ruby/whatsapp/messages/base.rb
|
|
130
|
+
- lib/ruby/whatsapp/messages/contacts.rb
|
|
131
|
+
- lib/ruby/whatsapp/messages/contacts/address.rb
|
|
132
|
+
- lib/ruby/whatsapp/messages/contacts/contact.rb
|
|
133
|
+
- lib/ruby/whatsapp/messages/contacts/email.rb
|
|
134
|
+
- lib/ruby/whatsapp/messages/contacts/name.rb
|
|
135
|
+
- lib/ruby/whatsapp/messages/contacts/org.rb
|
|
136
|
+
- lib/ruby/whatsapp/messages/contacts/phone.rb
|
|
137
|
+
- lib/ruby/whatsapp/messages/contacts/url.rb
|
|
138
|
+
- lib/ruby/whatsapp/messages/document.rb
|
|
139
|
+
- lib/ruby/whatsapp/messages/image.rb
|
|
140
|
+
- lib/ruby/whatsapp/messages/interactive.rb
|
|
141
|
+
- lib/ruby/whatsapp/messages/interactive/base.rb
|
|
142
|
+
- lib/ruby/whatsapp/messages/interactive/body.rb
|
|
143
|
+
- lib/ruby/whatsapp/messages/interactive/footer.rb
|
|
144
|
+
- lib/ruby/whatsapp/messages/interactive/header.rb
|
|
145
|
+
- lib/ruby/whatsapp/messages/interactive/list_buttons.rb
|
|
146
|
+
- lib/ruby/whatsapp/messages/interactive/list_buttons/section.rb
|
|
147
|
+
- lib/ruby/whatsapp/messages/interactive/list_buttons/section/row.rb
|
|
148
|
+
- lib/ruby/whatsapp/messages/interactive/media_carousel.rb
|
|
149
|
+
- lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb
|
|
150
|
+
- lib/ruby/whatsapp/messages/interactive/media_carousel/card/button.rb
|
|
151
|
+
- lib/ruby/whatsapp/messages/interactive/media_carousel/card/button/quick_reply.rb
|
|
152
|
+
- lib/ruby/whatsapp/messages/interactive/product_carousel.rb
|
|
153
|
+
- lib/ruby/whatsapp/messages/interactive/product_carousel/card.rb
|
|
154
|
+
- lib/ruby/whatsapp/messages/interactive/reply_buttons.rb
|
|
155
|
+
- lib/ruby/whatsapp/messages/interactive/reply_buttons/button.rb
|
|
156
|
+
- lib/ruby/whatsapp/messages/interactive/url_button.rb
|
|
157
|
+
- lib/ruby/whatsapp/messages/location.rb
|
|
158
|
+
- lib/ruby/whatsapp/messages/location_request.rb
|
|
159
|
+
- lib/ruby/whatsapp/messages/mark_message_as_read.rb
|
|
160
|
+
- lib/ruby/whatsapp/messages/reaction.rb
|
|
161
|
+
- lib/ruby/whatsapp/messages/response.rb
|
|
162
|
+
- lib/ruby/whatsapp/messages/response/contacts.rb
|
|
163
|
+
- lib/ruby/whatsapp/messages/response/messages.rb
|
|
164
|
+
- lib/ruby/whatsapp/messages/sticker.rb
|
|
165
|
+
- lib/ruby/whatsapp/messages/template.rb
|
|
166
|
+
- lib/ruby/whatsapp/messages/template/component.rb
|
|
167
|
+
- lib/ruby/whatsapp/messages/template/language.rb
|
|
168
|
+
- lib/ruby/whatsapp/messages/template/parameter.rb
|
|
169
|
+
- lib/ruby/whatsapp/messages/text.rb
|
|
170
|
+
- lib/ruby/whatsapp/messages/video.rb
|
|
171
|
+
- lib/ruby/whatsapp/railtie.rb
|
|
172
|
+
- lib/ruby/whatsapp/request_error.rb
|
|
173
|
+
- lib/ruby/whatsapp/response_handling.rb
|
|
174
|
+
- lib/ruby/whatsapp/utils/language_codes.rb
|
|
175
|
+
- lib/ruby/whatsapp/version.rb
|
|
176
|
+
- lib/ruby/whatsapp/webhook.rb
|
|
177
|
+
- lib/ruby/whatsapp/webhook/account_alerts.rb
|
|
178
|
+
- lib/ruby/whatsapp/webhook/account_review_update.rb
|
|
179
|
+
- lib/ruby/whatsapp/webhook/account_update.rb
|
|
180
|
+
- lib/ruby/whatsapp/webhook/account_update/ban_info.rb
|
|
181
|
+
- lib/ruby/whatsapp/webhook/automatic_events.rb
|
|
182
|
+
- lib/ruby/whatsapp/webhook/business_capability_update.rb
|
|
183
|
+
- lib/ruby/whatsapp/webhook/change.rb
|
|
184
|
+
- lib/ruby/whatsapp/webhook/contact.rb
|
|
185
|
+
- lib/ruby/whatsapp/webhook/entry.rb
|
|
186
|
+
- lib/ruby/whatsapp/webhook/error.rb
|
|
187
|
+
- lib/ruby/whatsapp/webhook/history.rb
|
|
188
|
+
- lib/ruby/whatsapp/webhook/installer.rb
|
|
189
|
+
- lib/ruby/whatsapp/webhook/message.rb
|
|
190
|
+
- lib/ruby/whatsapp/webhook/message/audio.rb
|
|
191
|
+
- lib/ruby/whatsapp/webhook/message/base.rb
|
|
192
|
+
- lib/ruby/whatsapp/webhook/message/button.rb
|
|
193
|
+
- lib/ruby/whatsapp/webhook/message/contacts.rb
|
|
194
|
+
- lib/ruby/whatsapp/webhook/message/contacts/address.rb
|
|
195
|
+
- lib/ruby/whatsapp/webhook/message/contacts/contact.rb
|
|
196
|
+
- lib/ruby/whatsapp/webhook/message/contacts/email.rb
|
|
197
|
+
- lib/ruby/whatsapp/webhook/message/contacts/name.rb
|
|
198
|
+
- lib/ruby/whatsapp/webhook/message/contacts/org.rb
|
|
199
|
+
- lib/ruby/whatsapp/webhook/message/contacts/phone.rb
|
|
200
|
+
- lib/ruby/whatsapp/webhook/message/contacts/url.rb
|
|
201
|
+
- lib/ruby/whatsapp/webhook/message/context.rb
|
|
202
|
+
- lib/ruby/whatsapp/webhook/message/document.rb
|
|
203
|
+
- lib/ruby/whatsapp/webhook/message/image.rb
|
|
204
|
+
- lib/ruby/whatsapp/webhook/message/interactive.rb
|
|
205
|
+
- lib/ruby/whatsapp/webhook/message/location.rb
|
|
206
|
+
- lib/ruby/whatsapp/webhook/message/media.rb
|
|
207
|
+
- lib/ruby/whatsapp/webhook/message/order.rb
|
|
208
|
+
- lib/ruby/whatsapp/webhook/message/order/product_item.rb
|
|
209
|
+
- lib/ruby/whatsapp/webhook/message/reaction.rb
|
|
210
|
+
- lib/ruby/whatsapp/webhook/message/referral.rb
|
|
211
|
+
- lib/ruby/whatsapp/webhook/message/sticker.rb
|
|
212
|
+
- lib/ruby/whatsapp/webhook/message/system.rb
|
|
213
|
+
- lib/ruby/whatsapp/webhook/message/text.rb
|
|
214
|
+
- lib/ruby/whatsapp/webhook/message/unknown.rb
|
|
215
|
+
- lib/ruby/whatsapp/webhook/message/video.rb
|
|
216
|
+
- lib/ruby/whatsapp/webhook/message_template_components_update.rb
|
|
217
|
+
- lib/ruby/whatsapp/webhook/message_template_quality_update.rb
|
|
218
|
+
- lib/ruby/whatsapp/webhook/message_template_status_update.rb
|
|
219
|
+
- lib/ruby/whatsapp/webhook/messages.rb
|
|
220
|
+
- lib/ruby/whatsapp/webhook/metadata.rb
|
|
221
|
+
- lib/ruby/whatsapp/webhook/notification.rb
|
|
222
|
+
- lib/ruby/whatsapp/webhook/partner_solutions.rb
|
|
223
|
+
- lib/ruby/whatsapp/webhook/payment_configuration_update.rb
|
|
224
|
+
- lib/ruby/whatsapp/webhook/phone_number_name_update.rb
|
|
225
|
+
- lib/ruby/whatsapp/webhook/phone_number_quality_update.rb
|
|
226
|
+
- lib/ruby/whatsapp/webhook/security.rb
|
|
227
|
+
- lib/ruby/whatsapp/webhook/signature.rb
|
|
228
|
+
- lib/ruby/whatsapp/webhook/smb_app_state_sync.rb
|
|
229
|
+
- lib/ruby/whatsapp/webhook/smb_app_state_sync/state_sync.rb
|
|
230
|
+
- lib/ruby/whatsapp/webhook/smb_message_echoes.rb
|
|
231
|
+
- lib/ruby/whatsapp/webhook/status.rb
|
|
232
|
+
- lib/ruby/whatsapp/webhook/status/conversation.rb
|
|
233
|
+
- lib/ruby/whatsapp/webhook/status/pricing.rb
|
|
234
|
+
- lib/ruby/whatsapp/webhook/template_category_update.rb
|
|
235
|
+
- lib/ruby/whatsapp/webhook/templates/webhooks_controller.rb.tt
|
|
236
|
+
- lib/ruby/whatsapp/webhook/unknown_field.rb
|
|
237
|
+
- lib/ruby/whatsapp/webhook/user_preferences.rb
|
|
238
|
+
- lib/ruby/whatsapp/webhook/verification.rb
|
|
239
|
+
- lib/tasks/whatsapp.rake
|
|
240
|
+
- sig/ruby/whatsapp.rbs
|
|
241
|
+
homepage: https://github.com/saleszera/ruby-whatsapp
|
|
242
|
+
licenses:
|
|
243
|
+
- MIT
|
|
244
|
+
metadata:
|
|
245
|
+
allowed_push_host: https://rubygems.org
|
|
246
|
+
homepage_uri: https://github.com/saleszera/ruby-whatsapp
|
|
247
|
+
source_code_uri: https://github.com/saleszera/ruby-whatsapp
|
|
248
|
+
changelog_uri: https://github.com/saleszera/ruby-whatsapp/blob/main/CHANGELOG.md
|
|
249
|
+
rubygems_mfa_required: 'true'
|
|
250
|
+
rdoc_options: []
|
|
251
|
+
require_paths:
|
|
252
|
+
- lib
|
|
253
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
|
+
requirements:
|
|
255
|
+
- - ">="
|
|
256
|
+
- !ruby/object:Gem::Version
|
|
257
|
+
version: 3.2.0
|
|
258
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
|
+
requirements:
|
|
260
|
+
- - ">="
|
|
261
|
+
- !ruby/object:Gem::Version
|
|
262
|
+
version: '0'
|
|
263
|
+
requirements: []
|
|
264
|
+
rubygems_version: 3.6.9
|
|
265
|
+
specification_version: 4
|
|
266
|
+
summary: Ruby client for the Meta WhatsApp Cloud API.
|
|
267
|
+
test_files: []
|