Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this gem support Broadcast API? #225

Open
soulfly opened this issue Sep 19, 2018 · 3 comments
Open

Does this gem support Broadcast API? #225

soulfly opened this issue Sep 19, 2018 · 3 comments

Comments

@soulfly
Copy link

soulfly commented Sep 19, 2018

Does this gem support Broadcast API?
https://developers.facebook.com/docs/messenger-platform/send-messages/broadcast-messages

@soulfly soulfly changed the title Does this get support Broadcast API? Does this gem support Broadcast API? Sep 19, 2018
@amrutjadhav
Copy link
Contributor

@soulfly No. Currently it does not support the Broadcast API. Broadcast API is only available in v2.11 and this gem is still on v2.9. So it has to update to v2.11 first then it will be possible to support Broadcast API.

@soulfly
Copy link
Author

soulfly commented Sep 20, 2018

Thanks @amrutjadhav
I have just created a monkey patch for this in a case somebody will need it

module Facebook
  module Messenger
    module Broadcast
      include HTTParty

      # Define base_uri for HTTParty.
      base_uri 'https://graph.facebook.com/v2.11/me'

      format :json

      module_function

      def create_message_creative(messages, access_token:)
        response = post '/message_creatives',
                      body: JSON.dump(messages),
                      format: :json,
                      query: {
                        access_token: access_token
                      }

        Facebook::Messenger::Bot::ErrorParser.raise_errors_from(response)

        response.body
      end

      def send_broadcast(message_creative_id, notification_type, schedule_time, access_token:)
        data = {:message_creative_id => message_creative_id,
                :notification_type => notification_type}
        data[:schedule_time] = schedule_time if schedule_time

        response = post '/broadcast_messages',
                      body: JSON.dump(data),
                      format: :json,
                      query: {
                        access_token: access_token
                      }

        Facebook::Messenger::Bot::ErrorParser.raise_errors_from(response)

        response.body
      end
    end
  end
end

@jgorset
Copy link
Owner

jgorset commented Dec 7, 2018

Cool. I'll be happy to merge a pull request for this, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants