Sha256: 07ef54e9e804a8014a572c3b8e611e415a28b3781dc0db9c116eee04f98803d5

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

class BotController < Xip::Controller

  helper :all

  def route
    if current_message.payload.present?
      handle_payloads
      # Clear out the payload to prevent duplicate handling
      current_message.payload = nil
      return
    end

    # 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
    else
      step_to flow: 'hello', state: 'say_hello'
    end
  end

private

  # Handle payloads globally since payload buttons remain in the chat
  # and we cannot guess in which states they will be tapped.
  def handle_payloads
    case current_message.payload
    when 'developer_restart', 'new_user'
      step_to flow: 'hello', state: 'say_hello'
    when 'goodbye'
      step_to flow: 'goodbye'
    end
  end

  # Automatically called when clients receive an opt-out error from
  # the platform. You can write your own steps for handling.
  def handle_opt_out
    do_nothing
  end

  # 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
    do_nothing
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xip-2.0.0.beta2 lib/xip/generators/builder/bot/controllers/bot_controller.rb