Module: Bobot::Event
- Defined in:
- lib/bobot/event.rb,
lib/bobot/events/read.rb,
lib/bobot/events/optin.rb,
lib/bobot/events/common.rb,
lib/bobot/events/message.rb,
lib/bobot/events/delivery.rb,
lib/bobot/events/postback.rb,
lib/bobot/events/referral.rb,
lib/bobot/events/message_echo.rb,
lib/bobot/events/account_linking.rb,
lib/bobot/events/message_request.rb,
lib/bobot/events/policy_enforcement.rb,
lib/bobot/events/pass_thread_control.rb,
lib/bobot/events/take_thread_control.rb
Defined Under Namespace
Modules: Common
Classes: AccountLinking, Delivery, Message, MessageEcho, MessageRequest, Optin, PassThreadControl, PolicyEnforcement, Postback, Read, Referral, TakeThreadControl, UnknownPayload
Constant Summary
collapse
- EVENTS =
{
'message' => Message,
'delivery' => Delivery,
'postback' => Postback,
'optin' => Optin,
'read' => Read,
'account_linking' => AccountLinking,
'referral' => Referral,
'message_echo' => MessageEcho,
'policy-enforcement' => PolicyEnforcement,
'pass_thread_control' => PassThreadControl,
'take_thread_control' => TakeThreadControl,
}.freeze
Class Method Summary
collapse
Class Method Details
.parse(payload) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/bobot/event.rb', line 30
def self.parse(payload)
return MessageEcho.new(payload) if payload_is_echo?(payload)
EVENTS.each do |event, klass|
return klass.new(payload) if payload.key?(event)
end
raise UnknownPayload.new(payload)
end
|
.payload_is_echo?(payload) ⇒ Boolean
40
41
42
|
# File 'lib/bobot/event.rb', line 40
def self.payload_is_echo?(payload)
payload.key?('message') && payload['message']['is_echo'] == true
end
|