Module: InstagramConnect::Ingest::Registry
- Defined in:
- lib/instagram_connect/ingest/registry.rb
Overview
Maps a webhook field to the handler that parses it, and infers the field
for messaging events (Meta delivers all of them under entry.messaging
regardless of which subscription triggered them, so the field has to be
recovered from the event's shape).
Constant Summary collapse
- HANDLERS =
{ "messages" => Handlers::Messages, "message_echoes" => Handlers::Messages, "messaging_postbacks" => Handlers::MessagingPostbacks, "message_reactions" => Handlers::MessageReactions, "messaging_seen" => Handlers::MessagingSeen, "messaging_referral" => Handlers::MessagingReferral, "messaging_optins" => Handlers::MessagingOptins, "messaging_handover" => Handlers::MessagingHandover, "comments" => Handlers::Comments, "live_comments" => Handlers::Comments, "mentions" => Handlers::Mentions, "story_insights" => Handlers::StoryInsights }.freeze
- KNOWN_FIELDS =
Every field the gem knows Meta can send on the
instagramobject. Fields without a handler are still worth subscribing to: they bank asunhandledrows and replay once a handler ships, whereas an unsubscribed field is gone for good — Meta does not storementionsorstory_insightsnotifications, and re-delivers nothing. %w[ messages message_echoes message_reactions messaging_postbacks messaging_seen messaging_referral messaging_optins messaging_handover messaging_policy_enforcement response_feedback standby comments live_comments mentions story_insights ].freeze
- MESSAGING_SHAPES =
Shape tests in priority order.
is_echomust be checked before the plainmessagecase, since an echo carries a message too. [ [ "message_echoes", ->(e) { e["message"] && e.dig("message", "is_echo") } ], [ "messages", ->(e) { e["message"] } ], [ "message_reactions", ->(e) { e["reaction"] } ], [ "messaging_postbacks", ->(e) { e["postback"] } ], [ "messaging_seen", ->(e) { e["read"] } ], [ "messaging_referral", ->(e) { e["referral"] } ], [ "messaging_optins", ->(e) { e["optin"] } ], [ "messaging_handover", lambda { |e| e["pass_thread_control"] || e["take_thread_control"] || e["request_thread_control"] } ] ].freeze
- UNKNOWN_FIELD =
"unknown".freeze
Class Method Summary collapse
- .handled?(field) ⇒ Boolean
- .handled_fields ⇒ Object
- .handler_for(field) ⇒ Object
-
.messaging_field_for(event) ⇒ Object
message.referralandpostback.referralare nested inside their parent event and stay with it; only a standalonereferralis a referral event in its own right, which is why the shape tests run in order rather than checking every key independently. -
.subscribable_fields ⇒ Object
The fields a host should subscribe its Page to.
Class Method Details
.handled?(field) ⇒ Boolean
69 70 71 |
# File 'lib/instagram_connect/ingest/registry.rb', line 69 def handled?(field) HANDLERS.key?(field) end |
.handled_fields ⇒ Object
79 80 81 |
# File 'lib/instagram_connect/ingest/registry.rb', line 79 def handled_fields HANDLERS.keys end |
.handler_for(field) ⇒ Object
65 66 67 |
# File 'lib/instagram_connect/ingest/registry.rb', line 65 def handler_for(field) HANDLERS.fetch(field, Handlers::Unknown) end |
.messaging_field_for(event) ⇒ Object
message.referral and postback.referral are nested inside their
parent event and stay with it; only a standalone referral is a
referral event in its own right, which is why the shape tests run in
order rather than checking every key independently.
87 88 89 90 |
# File 'lib/instagram_connect/ingest/registry.rb', line 87 def messaging_field_for(event) found = MESSAGING_SHAPES.find { |(_field, test)| test.call(event) } found ? found.first : UNKNOWN_FIELD end |
.subscribable_fields ⇒ Object
The fields a host should subscribe its Page to. Everything the gem knows about, handled or not — see KNOWN_FIELDS.
75 76 77 |
# File 'lib/instagram_connect/ingest/registry.rb', line 75 def subscribable_fields KNOWN_FIELDS end |