Class: InstagramConnect::Ingest::Handlers::MessageReactions

Inherits:
Base
  • Object
show all
Defined in:
lib/instagram_connect/ingest/handlers/message_reactions.rb

Overview

A customer reacting to (or un-reacting from) a message.

Reactions also reopen the 24-hour messaging window, which is why they bump the conversation's activity even though they are not messages.

Instance Attribute Summary

Attributes inherited from Base

#notification

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from InstagramConnect::Ingest::Handlers::Base

Class Method Details

.dedupe_key(event) ⇒ Object

A customer can react, unreact, then react again with the same emoji on the same message. Those are three real events sharing a mid, so the action and the wire timestamp both belong in the key. A genuine redelivery repeats the timestamp and still collapses, which is the distinction that matters.



14
15
16
17
18
19
# File 'lib/instagram_connect/ingest/handlers/message_reactions.rb', line 14

def self.dedupe_key(event)
  reaction = event["reaction"] || {}
  mid = reaction["mid"].presence or return nil

  [ mid, reaction["action"], reaction["reaction"], event["timestamp"] ].compact.join(":")
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/instagram_connect/ingest/handlers/message_reactions.rb', line 21

def call
  record = InstagramConnect::MessageReaction.create!(
    conversation: conversation,
    message: message,
    ig_message_id: mid,
    igsid: igsid,
    actor: actor,
    action: action,
    reaction: payload["reaction"],
    emoji: payload["emoji"],
    reacted_at: reacted_at
  )
  refresh_message_projection
  conversation.register_event(reacted_at)
  record
end