Class: SignalWire::Skills::Builtin::PlayBackgroundFileSkill

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

Instance Attribute Summary

Attributes inherited from SkillBase

#agent, #logger, #params, #swaig_fields

Instance Method Summary collapse

Methods inherited from SkillBase

#cleanup, #get_global_data, #get_hints, #get_param, #get_prompt_sections, #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/play_background_file.rb', line 11

def description; 'Control background file playback'; end

#get_parameter_schemaObject



73
74
75
76
77
78
# File 'lib/signalwire/skills/builtin/play_background_file.rb', line 73

def get_parameter_schema
  {
    'files' => { 'type' => 'array', 'required' => true,
                 'items' => { 'type' => 'object', 'required' => %w[key description url] } }
  }
end

#instance_keyObject



25
# File 'lib/signalwire/skills/builtin/play_background_file.rb', line 25

def instance_key; "play_background_file_#{@tool_name}"; end

#nameObject



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

def name;        'play_background_file'; end

#register_toolsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/signalwire/skills/builtin/play_background_file.rb', line 27

def register_tools
  enum_values = @files.map { |f| "start_#{f['key']}" } + ['stop']
  descriptions = @files.map { |f| "start_#{f['key']}: #{f['description']}" }
  descriptions << 'stop: Stop any currently playing background file'
  param_desc = 'Action to perform. Options: ' + descriptions.join('; ')

  expressions = @files.map do |f|
    result = Swaig::FunctionResult.new(
      "Tell the user you are now going to play #{f['description']} for them."
    )
    result.set_post_process(true)
    result.play_background_file(f['url'], wait: f.fetch('wait', false))

    {
      'string'  => '${args.action}',
      'pattern' => "/start_#{f['key']}/i",
      'output'  => result.to_h
    }
  end

  stop_result = Swaig::FunctionResult.new(
    'Tell the user you have stopped the background file playback.'
  ).stop_background_file

  expressions << {
    'string'  => '${args.action}',
    'pattern' => '/stop/i',
    'output'  => stop_result.to_h
  }

  tool = {
    'function'    => @tool_name,
    'description' => "Control background file playback for #{@tool_name.tr('_', ' ')}",
    'parameters'  => {
      'type' => 'object',
      'properties' => {
        'action' => { 'type' => 'string', 'description' => param_desc, 'enum' => enum_values }
      },
      'required' => ['action']
    },
    'data_map' => { 'expressions' => expressions }
  }

  [{ datamap: tool }]
end

#setupObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/signalwire/skills/builtin/play_background_file.rb', line 14

def setup
  @tool_name = get_param('tool_name', default: 'play_background_file')
  @files     = get_param('files')
  return false unless @files.is_a?(Array) && !@files.empty?

  @files.each do |f|
    return false unless f.is_a?(Hash) && f['key'] && f['description'] && f['url']
  end
  true
end

#supports_multiple_instances?Boolean

Returns:

  • (Boolean)


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

def supports_multiple_instances?; true; end