Sha256: 8a486d5c4ceed5b24e5c0d45ae5c8f14256451e640bd1f2200fab70186953592

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

class BotController < Stealth::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

3 entries across 3 versions & 1 rubygems

Version Path
stealth-2.0.0.beta3 lib/stealth/generators/builder/bot/controllers/bot_controller.rb
stealth-2.0.0.beta2 lib/stealth/generators/builder/bot/controllers/bot_controller.rb
stealth-2.0.0.beta1 lib/stealth/generators/builder/bot/controllers/bot_controller.rb