Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Commit

Permalink
added min required subscribed fields for messenger bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Engelhardt authored and Timo Engelhardt committed Apr 20, 2019
1 parent 33fccf4 commit 07f378a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/rubotnik.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class << self

def logger
@logger ||= Logger.new($stdout).tap do |log|
log.progname = self.name
log.progname = name
end
end

def route(event, &block)
if [:message, :postback].include?(event)
if %i[message postback].include?(event)
Bot.on event do |e|
case e
when Facebook::Messenger::Incoming::Message
Expand All @@ -45,7 +45,10 @@ def route(event, &block)
end

def subscribe(token)
Facebook::Messenger::Subscriptions.subscribe(access_token: token)
Facebook::Messenger::Subscriptions.subscribe(
access_token: token,
subscribed_fields: %w[messages messaging_postbacks]
)
end

def set_profile(*payloads)
Expand Down
6 changes: 5 additions & 1 deletion spec/rubotnik_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@

describe 'subscribe' do
it 'subscribes to a fb page' do
subscribed_fields = %w[messages messaging_postbacks]
token = 'xxx'
expect(Facebook::Messenger::Subscriptions)
.to receive(:subscribe).with(access_token: token)
.to receive(:subscribe).with(
access_token: token,
subscribed_fields: subscribed_fields
)

described_class.subscribe(token)
end
Expand Down

0 comments on commit 07f378a

Please sign in to comment.