Class: FlowChat::App
- Inherits:
-
Object
- Object
- FlowChat::App
- Defined in:
- lib/flow_chat/app.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#navigation_stack ⇒ Object
readonly
Returns the value of attribute navigation_stack.
Instance Method Summary collapse
- #contact_name ⇒ Object
- #gateway ⇒ Object
- #go_back ⇒ Object
-
#initialize(context) ⇒ App
constructor
A new instance of App.
- #location ⇒ Object
- #media ⇒ Object
- #message_id ⇒ Object
- #msisdn ⇒ Object
- #platform ⇒ Object
- #say(msg, media: nil) ⇒ Object
- #screen(key) ⇒ Object
- #session ⇒ Object
- #timestamp ⇒ Object
- #user_id ⇒ Object
Constructor Details
#initialize(context) ⇒ App
Returns a new instance of App.
5 6 7 8 9 |
# File 'lib/flow_chat/app.rb', line 5 def initialize(context) @context = context @input = context.input @navigation_stack = [] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/flow_chat/app.rb', line 3 def context @context end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
3 4 5 |
# File 'lib/flow_chat/app.rb', line 3 def input @input end |
#navigation_stack ⇒ Object (readonly)
Returns the value of attribute navigation_stack.
3 4 5 |
# File 'lib/flow_chat/app.rb', line 3 def @navigation_stack end |
Instance Method Details
#contact_name ⇒ Object
66 67 68 |
# File 'lib/flow_chat/app.rb', line 66 def contact_name nil end |
#gateway ⇒ Object
46 47 48 |
# File 'lib/flow_chat/app.rb', line 46 def gateway context["request.gateway"] end |
#go_back ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/flow_chat/app.rb', line 27 def go_back return false if .empty? @context.input = nil current_screen = .last session.delete(current_screen) # Restart the flow from the beginning raise FlowChat::Interrupt::RestartFlow.new end |
#location ⇒ Object
70 71 72 |
# File 'lib/flow_chat/app.rb', line 70 def location nil end |
#media ⇒ Object
74 75 76 |
# File 'lib/flow_chat/app.rb', line 74 def media nil end |
#message_id ⇒ Object
58 59 60 |
# File 'lib/flow_chat/app.rb', line 58 def context["request.message_id"] end |
#msisdn ⇒ Object
54 55 56 |
# File 'lib/flow_chat/app.rb', line 54 def msisdn context["request.msisdn"] end |
#platform ⇒ Object
42 43 44 |
# File 'lib/flow_chat/app.rb', line 42 def platform context["request.platform"] end |
#say(msg, media: nil) ⇒ Object
38 39 40 |
# File 'lib/flow_chat/app.rb', line 38 def say(msg, media: nil) raise FlowChat::Interrupt::Terminate.new(msg, media: media) end |
#screen(key) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/flow_chat/app.rb', line 11 def screen(key) raise ArgumentError, "a block is expected" unless block_given? raise ArgumentError, "screen has already been presented" if .include?(key) << key return session.get(key) if session.get(key).present? user_input = prepare_user_input prompt = FlowChat::Prompt.new user_input @input = nil # input is being submitted to prompt so we clear it value = yield prompt session.set(key, value) value end |
#session ⇒ Object
78 79 80 |
# File 'lib/flow_chat/app.rb', line 78 def session @context.session end |
#timestamp ⇒ Object
62 63 64 |
# File 'lib/flow_chat/app.rb', line 62 def context["request.timestamp"] end |
#user_id ⇒ Object
50 51 52 |
# File 'lib/flow_chat/app.rb', line 50 def user_id context["request.user_id"] end |