Class: Whatsapp::SubscribedApp::Subscribe

Inherits:
Object
  • Object
show all
Extended by:
ResponseHandling, Transport
Defined in:
lib/ruby/whatsapp/subscribed_app/subscribe.rb

Overview

Subscribes this app to a WABA's webhook notifications.

override_callback_uri/verify_token are for Tech Providers routing several WABAs' notifications to different callback URLs instead of the one configured on the app itself. Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/reference/whatsapp-business-account/subscribed-apps-api

Constant Summary

Constants included from ResponseHandling

ResponseHandling::MAX_ERROR_BODY

Class Method Summary collapse

Class Method Details

.call(client: Client.new, override_callback_uri: nil, verify_token: nil) ⇒ Response::Subscription

Parameters:

  • client (Whatsapp::Client) (defaults to: Client.new)

    The WhatsApp client instance.

  • override_callback_uri (String, nil) (defaults to: nil)

    A per-WABA webhook callback override.

  • verify_token (String, nil) (defaults to: nil)

    The token Meta echoes back if it re-verifies override_callback_uri.

Returns:

Raises:

  • (Error)

    if no WABA ID is configured, or the request fails.



22
23
24
25
26
27
28
29
# File 'lib/ruby/whatsapp/subscribed_app/subscribe.rb', line 22

def call(client: Client.new, override_callback_uri: nil, verify_token: nil)
  body = { override_callback_uri:, verify_token: }.compact
  response = client.connection.post(edge_path(client), json: body)

  Response::Subscription.deserialize(
    parse_json(handle_response!(response, error_class: Error, action: "subscribe app"))
  )
end