Class: BotPlatform::Dialogs::DialogContext
- Inherits:
-
Object
- Object
- BotPlatform::Dialogs::DialogContext
- Includes:
- Asserts
- Defined in:
- lib/bot_platform/dialogs/dialog_context.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dialog_stack ⇒ Object
Returns the value of attribute dialog_stack.
-
#dialogs ⇒ Object
Returns the value of attribute dialogs.
-
#turn_context ⇒ Object
Returns the value of attribute turn_context.
Instance Method Summary collapse
- #active_dialog ⇒ Object
- #continue_dialog ⇒ Object
-
#initialize(dialogs, turn_context, dialog_state) ⇒ DialogContext
constructor
A new instance of DialogContext.
- #prompt(dialog_id, options) ⇒ Object
-
#replace_dialog(dialog_id, options) ⇒ Object
stop active dialog and start a new dialog by given.
- #reprompt ⇒ Object
- #start_dialog(dialog_id, options) ⇒ Object
- #stop_active_dialog ⇒ Object
-
#stop_all ⇒ Object
stop all dialogs in the stack.
- #stop_dialog(result = nil) ⇒ Object
Methods included from Asserts
#assert_activity_is_not_null, #assert_activity_list_is_not_null, #assert_activity_type_is_not_null, #assert_context_is_not_null, #assert_conversation_reference_is_not_null, #assert_dialog_context_is_valid, #assert_dialog_id_is_valid, #assert_dialog_is_uniq, #assert_dialog_is_valid, #assert_dialog_set_is_valid, #assert_dialog_state_is_valid, #assert_is_not_empty, #assert_middleware_is_not_null, #assert_middleware_list_is_not_null, #assert_prompt_options_is_valid, #assert_turn_context_is_valid, #assert_waterfall_step_context_is_valid
Constructor Details
#initialize(dialogs, turn_context, dialog_state) ⇒ DialogContext
Returns a new instance of DialogContext.
10 11 12 13 14 15 16 17 18 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 10 def initialize(dialogs, turn_context, dialog_state) assert_dialog_set_is_valid dialogs assert_turn_context_is_valid turn_context assert_dialog_state_is_valid dialog_state @dialogs = dialogs @turn_context = turn_context @dialog_stack = dialog_state.dialog_stack end |
Instance Attribute Details
#dialog_stack ⇒ Object
Returns the value of attribute dialog_stack.
8 9 10 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 8 def dialog_stack @dialog_stack end |
#dialogs ⇒ Object
Returns the value of attribute dialogs.
8 9 10 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 8 def dialogs @dialogs end |
#turn_context ⇒ Object
Returns the value of attribute turn_context.
8 9 10 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 8 def turn_context @turn_context end |
Instance Method Details
#active_dialog ⇒ Object
20 21 22 23 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 20 def active_dialog return nil if @dialog_stack.nil? || @dialog_stack.length==0 @dialog_stack.last end |
#continue_dialog ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 43 def continue_dialog instance = active_dialog if instance != nil dialog = @dialogs.find instance.dialog_id if dialog return dialog.continue self end end return DialogResult.new :empty end |
#prompt(dialog_id, options) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 36 def prompt(dialog_id, ) assert_dialog_id_is_valid dialog_id assert_is_not_empty start_dialog dialog_id, end |
#replace_dialog(dialog_id, options) ⇒ Object
stop active dialog and start a new dialog by given
85 86 87 88 89 90 91 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 85 def replace_dialog(dialog_id, ) unless active_dialog.nil? @dialog_stack.pop end return start_dialog(dialog_id, ) end |
#reprompt ⇒ Object
93 94 95 96 97 98 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 93 def reprompt dialog = active_dialog if dialog != nil dialog.reprompt(turn_context) end end |
#start_dialog(dialog_id, options) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 25 def start_dialog(dialog_id, ) assert_dialog_id_is_valid dialog_id dialog = @dialogs.find(dialog_id) raise "dialog(id=#{dialog_id}) cannot be found." if dialog.nil? dialog_instance = DialogInstance.new dialog_id @dialog_stack.push dialog_instance dialog.start self, end |
#stop_active_dialog ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 100 def stop_active_dialog dialog = active_dialog if dialog != nil dialog.stop @dialog_stack.pop end end |
#stop_all ⇒ Object
stop all dialogs in the stack
75 76 77 78 79 80 81 82 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 75 def stop_all if @dialog_stack.any? @dialog_stack.each do |dialog| dialog.stop end @dialog_stack = [] end end |
#stop_dialog(result = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bot_platform/dialogs/dialog_context.rb', line 55 def stop_dialog(result=nil) if @dialog_stack.any? @dialog_stack.pop end instance = active_dialog #previous dialog if !instance.nil? dialog = @dialogs.find instance.dialog_id if dialog return dialog.resume self, DialogReason::END_CALLED, result end else return DialogResult.new :complete, result end end |