module Facebook::Messenger::Subscriptions
Module Subscriptions
handles subscribing and unsubscribing Applications
to Pages.
Public Instance Methods
If there is any error in response, raise error.
@raise [Facebook::Messenger::Subscriptions::Error] If there is error
in response.
@param [Hash] response Response from facebook.
@return Raise the error.
# File lib/facebook/messenger/subscriptions.rb, line 75 def raise_errors(response) raise Error, response['error'] if response.key? 'error' end
Function subscribe the facebook app to page. @see developers.facebook.com/docs/graph-api/reference/page/subscribed_apps
@raise [Facebook::Messenger::Subscriptions::Error] if there is any error
in the response of subscribed_apps request.
@param [String] access_token Access token of page to which bot has
to subscribe.
@return [Boolean] TRUE
# File lib/facebook/messenger/subscriptions.rb, line 30 def subscribe(access_token:, subscribed_fields: []) response = post '/subscribed_apps', headers: { 'Content-Type' => 'application/json' }, body: { access_token: access_token, subscribed_fields: subscribed_fields }.to_json raise_errors(response) true end
Function unsubscribe the app from facebook page. @see developers.facebook.com/docs/graph-api/reference/page/subscribed_apps
@raise [Facebook::Messenger::Subscriptions::Error] if there is any error
in the response of subscribed_apps request.
@param [String] access_token Access token of page from which app has
to unsubscribe.
@return [Boolean] TRUE
# File lib/facebook/messenger/subscriptions.rb, line 55 def unsubscribe(access_token:) response = delete '/subscribed_apps', query: { access_token: access_token } raise_errors(response) true end