Class: SignalWire::Contexts::GatherInfo
- Inherits:
-
Object
- Object
- SignalWire::Contexts::GatherInfo
- Defined in:
- lib/signalwire/contexts/context_builder.rb
Overview
Configuration for gathering information in a step via the C-side gather_info system.
Instance Attribute Summary collapse
-
#completion_action ⇒ Object
Returns the value of attribute completion_action.
-
#output_key ⇒ Object
Returns the value of attribute output_key.
-
#prompt ⇒ Object
Returns the value of attribute prompt.
-
#questions ⇒ Object
readonly
Returns the value of attribute questions.
Instance Method Summary collapse
-
#add_question(key:, question:, **opts) ⇒ Object
Add a question.
-
#initialize(output_key: nil, completion_action: nil, prompt: nil) ⇒ GatherInfo
constructor
A new instance of GatherInfo.
- #to_h ⇒ Object
Constructor Details
#initialize(output_key: nil, completion_action: nil, prompt: nil) ⇒ GatherInfo
Returns a new instance of GatherInfo.
55 56 57 58 59 60 |
# File 'lib/signalwire/contexts/context_builder.rb', line 55 def initialize(output_key: nil, completion_action: nil, prompt: nil) @output_key = output_key @completion_action = completion_action @prompt = prompt @questions = [] end |
Instance Attribute Details
#completion_action ⇒ Object
Returns the value of attribute completion_action.
52 53 54 |
# File 'lib/signalwire/contexts/context_builder.rb', line 52 def completion_action @completion_action end |
#output_key ⇒ Object
Returns the value of attribute output_key.
52 53 54 |
# File 'lib/signalwire/contexts/context_builder.rb', line 52 def output_key @output_key end |
#prompt ⇒ Object
Returns the value of attribute prompt.
52 53 54 |
# File 'lib/signalwire/contexts/context_builder.rb', line 52 def prompt @prompt end |
#questions ⇒ Object (readonly)
Returns the value of attribute questions.
53 54 55 |
# File 'lib/signalwire/contexts/context_builder.rb', line 53 def questions @questions end |
Instance Method Details
#add_question(key:, question:, **opts) ⇒ Object
Add a question. Returns self for chaining.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/signalwire/contexts/context_builder.rb', line 63 def add_question(key:, question:, **opts) @questions << GatherQuestion.new( key: key, question: question, type: opts.fetch(:type, 'string'), confirm: opts.fetch(:confirm, false), prompt: opts[:prompt], functions: opts[:functions] ) self end |
#to_h ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/signalwire/contexts/context_builder.rb', line 75 def to_h raise ArgumentError, "gather_info must have at least one question" if @questions.empty? h = { "questions" => @questions.map(&:to_h) } h["prompt"] = @prompt if @prompt h["output_key"] = @output_key if @output_key h["completion_action"] = @completion_action if @completion_action h end |