Class: SignalWire::Skills::Builtin::InfoGathererSkill

Inherits:
SkillBase
  • Object
show all
Defined in:
lib/signalwire/skills/builtin/info_gatherer.rb

Instance Attribute Summary

Attributes inherited from SkillBase

#agent, #logger, #params, #swaig_fields

Instance Method Summary collapse

Methods inherited from SkillBase

#cleanup, #get_hints, #get_param, #initialize, #required_env_vars, #version

Constructor Details

This class inherits a constructor from SignalWire::Skills::SkillBase

Instance Method Details

#descriptionObject



11
# File 'lib/signalwire/skills/builtin/info_gatherer.rb', line 11

def description; 'Gather answers to a configurable list of questions'; end

#get_global_dataObject



63
64
65
66
67
68
69
70
71
# File 'lib/signalwire/skills/builtin/info_gatherer.rb', line 63

def get_global_data
  {
    @namespace => {
      'questions'      => @questions,
      'question_index' => 0,
      'answers'        => []
    }
  }
end

#get_parameter_schemaObject



84
85
86
87
88
89
90
# File 'lib/signalwire/skills/builtin/info_gatherer.rb', line 84

def get_parameter_schema
  {
    'questions' => { 'type' => 'array', 'required' => true },
    'prefix'    => { 'type' => 'string' },
    'completion_message' => { 'type' => 'string' }
  }
end

#get_prompt_sectionsObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/signalwire/skills/builtin/info_gatherer.rb', line 73

def get_prompt_sections
  [
    {
      'title' => "Info Gatherer (#{instance_key})",
      'body' => "You need to gather answers to a series of questions from the user. " \
                "Start by asking if they are ready, then call #{@start_tool} to get the first question. " \
                "After each answer, call #{@submit_tool} to record it and get the next question."
    }
  ]
end

#instance_keyObject



38
39
40
41
# File 'lib/signalwire/skills/builtin/info_gatherer.rb', line 38

def instance_key
  prefix = get_param('prefix')
  prefix && !prefix.to_s.empty? ? "info_gatherer_#{prefix}" : 'info_gatherer'
end

#nameObject



10
# File 'lib/signalwire/skills/builtin/info_gatherer.rb', line 10

def name;        'info_gatherer'; end

#register_toolsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/signalwire/skills/builtin/info_gatherer.rb', line 43

def register_tools
  [
    {
      name: @start_tool,
      description: 'Start the question sequence with the first question',
      parameters: {},
      handler: method(:handle_start)
    },
    {
      name: @submit_tool,
      description: 'Submit an answer to the current question and move to the next one',
      parameters: {
        'answer'            => { 'type' => 'string', 'description' => "The user's answer to the current question" },
        'confirmed_by_user' => { 'type' => 'boolean', 'description' => 'Only set to true when the user has explicitly confirmed the answer.' }
      },
      handler: method(:handle_submit)
    }
  ]
end

#setupObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/signalwire/skills/builtin/info_gatherer.rb', line 14

def setup
  @questions = get_param('questions')
  return false unless @questions.is_a?(Array) && !@questions.empty?

  @questions.each_with_index do |q, i|
    return false unless q.is_a?(Hash) && q['key_name'] && q['question_text']
  end

  prefix = get_param('prefix')
  if prefix && !prefix.empty?
    @start_tool = "#{prefix}_start_questions"
    @submit_tool = "#{prefix}_submit_answer"
    @namespace = "skill:#{prefix}"
  else
    @start_tool = 'start_questions'
    @submit_tool = 'submit_answer'
    @namespace = 'skill:info_gatherer'
  end

  @completion_message = get_param('completion_message',
    default: 'Thank you! All questions have been answered.')
  true
end

#supports_multiple_instances?Boolean

Returns:

  • (Boolean)


12
# File 'lib/signalwire/skills/builtin/info_gatherer.rb', line 12

def supports_multiple_instances?; true; end