Skip to content

message_reads events break the stealth session model #25

@lightyrs

Description

@lightyrs

I'm implementing message_reads and encountering the following issue:

Given the default route method in BotController, for example:

def route
  if current_session.present?
    step_to session: current_session
  else
    step_to flow: 'hello', state: 'say_hello'
  end
end

When a message_read event occurs, the bot will go into an infinite loop.

In order to mitigate this, I'm creating *_read states for every state and doing this in the BotController:

def route
  if current_session.present?
    if !in_read_state? && current_message&.read.try(:[], :watermark)
      step_to_read_state
    else
      step_to session: current_session
    end
  else
    step_to flow: 'hello', state: 'say_hello'
  end
end

def step_to_read_state
  update_session_to state: "#{current_session.state_string}_read"
end

def in_read_state?
  current_session.state_string.match(/_read$/)
end

however, this simply leads to dropping through the CatchAll stack.

Ideally, stealth should be able to handle events like message_read in a different way than actual message received events.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions