# frozen_string_literal: true
class BotController < Xip::Controller
if current_message.payload.present?
# Clear out the payload to prevent duplicate handling
current_message.payload = nil
# Allow devs to jump around flows and states by typing:
# /flow_name/state_name or
# /flow_name (jumps to first state) or
# //state_name (jumps to state in current flow)
# (only works for bots in development)
return if dev_jump_detected?
if current_session.present?
step_to session: current_session
step_to flow: 'hello', state: 'say_hello'
# Handle payloads globally since payload buttons remain in the chat
# and we cannot guess in which states they will be tapped.
case current_message.payload
when 'developer_restart', 'new_user'
step_to flow: 'hello', state: 'say_hello'
# Automatically called when clients receive an opt-out error from
# the platform. You can write your own steps for handling.
# Automatically called when clients receive an invalid session_id error from
# the platform. For example, attempting to text a landline.
# You can write your own steps for handling.
def handle_invalid_session_id