Skip to content

Commit

Permalink
Merge 94a1904 into fc8d8cb
Browse files Browse the repository at this point in the history
  • Loading branch information
denmarkmeralpis committed Apr 10, 2020
2 parents fc8d8cb + 94a1904 commit b3865b0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/facebook/messenger/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Bot
policy_enforcement
pass_thread_control
game_play
message_reaction
].freeze

class << self
Expand Down
4 changes: 3 additions & 1 deletion lib/facebook/messenger/incoming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'facebook/messenger/incoming/policy_enforcement'
require 'facebook/messenger/incoming/pass_thread_control'
require 'facebook/messenger/incoming/game_play'
require 'facebook/messenger/incoming/message_reaction'

module Facebook
module Messenger
Expand All @@ -35,7 +36,8 @@ module Incoming
'payment' => Payment,
'policy_enforcement' => PolicyEnforcement,
'pass_thread_control' => PassThreadControl,
'game_play' => GamePlay
'game_play' => GamePlay,
'reaction' => MessageReaction
}.freeze

# Parse the given payload and create new object of class related
Expand Down
23 changes: 23 additions & 0 deletions lib/facebook/messenger/incoming/message_reaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Facebook
module Messenger
module Incoming
# The Message echo class represents an incoming Facebook Messenger message
# @see https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/message-reactions
class MessageReaction
include Facebook::Messenger::Incoming::Common

def action
@messaging['reaction']['action']
end

def emoji
@messaging['reaction']['emoji']
end

def reaction
@messaging['reaction']['reaction']
end
end
end
end
end
58 changes: 58 additions & 0 deletions spec/facebook/messenger/incoming/message_reaction_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'spec_helper'

describe Facebook::Messenger::Incoming::MessageReaction do
let :payload do
{
'sender' => {
'id' => '3'
},
'recipient' => {
'id' => '3'
},
'timestamp' => 145_776_419_762_7,
'reaction' => {
'action' => 'react',
'emoji' => '👍',
'reaction' => 'like'
}
}
end

subject { Facebook::Messenger::Incoming::MessageReaction.new(payload) }

describe '.messaging' do
it 'returns the original payload' do
expect(subject.messaging).to eq(payload)
end
end

describe '.sender' do
it 'returns the sender' do
expect(subject.sender).to eq(payload['sender'])
end
end

describe '.recipient' do
it 'returns the recipient' do
expect(subject.recipient).to eq(payload['recipient'])
end
end

describe '.action' do
it 'returns the reaction action' do
expect(subject.action).to eq(payload['reaction']['action'])
end
end

describe '.emoji' do
it 'returns the reaction emoji' do
expect(subject.emoji).to eq(payload['reaction']['emoji'])
end
end

describe '.reaction' do
it 'returns the reaction reaction' do
expect(subject.reaction).to eq(payload['reaction']['reaction'])
end
end
end

0 comments on commit b3865b0

Please sign in to comment.