Class: SignalWire::Skills::Builtin::SwmlTransferSkill
- Inherits:
-
SkillBase
- Object
- SkillBase
- SignalWire::Skills::Builtin::SwmlTransferSkill
show all
- Defined in:
- lib/signalwire/skills/builtin/swml_transfer.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_param, #initialize, #required_env_vars, #version
Instance Method Details
#description ⇒ Object
12
|
# File 'lib/signalwire/skills/builtin/swml_transfer.rb', line 12
def description; 'Transfer calls between agents based on pattern matching'; end
|
#get_hints ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/signalwire/skills/builtin/swml_transfer.rb', line 69
def get_hints
hints = []
@transfers&.each_key do |pattern|
clean = pattern.gsub(%r{^/|/[i]*$}, '')
next if clean.empty? || clean.start_with?('.')
if clean.include?('|')
clean.split('|').each { |p| hints << p.strip.downcase }
else
hints << clean.downcase
end
end
hints.concat(%w[transfer connect speak\ to talk\ to])
end
|
#get_parameter_schema ⇒ Object
102
103
104
105
106
107
108
109
110
|
# File 'lib/signalwire/skills/builtin/swml_transfer.rb', line 102
def get_parameter_schema
{
'transfers' => { 'type' => 'object', 'required' => true },
'description' => { 'type' => 'string', 'default' => 'Transfer call based on pattern matching' },
'parameter_name' => { 'type' => 'string', 'default' => 'transfer_type' },
'default_message' => { 'type' => 'string', 'default' => 'Please specify a valid transfer type.' },
'required_fields' => { 'type' => 'object', 'default' => {} }
}
end
|
#get_prompt_sections ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/signalwire/skills/builtin/swml_transfer.rb', line 83
def get_prompt_sections
return [] unless @transfers && !@transfers.empty?
bullets = @transfers.map do |pattern, config|
clean = pattern.gsub(%r{^/|/[i]*$}, '')
dest = config['url'] || config['address']
"\"#{clean}\" - transfers to #{dest}"
end
[
{ 'title' => 'Transferring', 'body' => "Transfer calls using #{@tool_name}.", 'bullets' => bullets },
{ 'title' => 'Transfer Instructions', 'body' => 'How to use the transfer capability:',
'bullets' => [
"Use the #{@tool_name} function when a transfer is needed",
"Pass the destination type to the '#{@param_name}' parameter"
] }
]
end
|
#instance_key ⇒ Object
38
|
# File 'lib/signalwire/skills/builtin/swml_transfer.rb', line 38
def instance_key; "swml_transfer_#{@tool_name}"; end
|
#name ⇒ Object
11
|
# File 'lib/signalwire/skills/builtin/swml_transfer.rb', line 11
def name; 'swml_transfer'; end
|
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
|
# File 'lib/signalwire/skills/builtin/swml_transfer.rb', line 40
def register_tools
dm = DataMap.new(@tool_name)
.description(@desc)
.parameter(@param_name, 'string', @param_desc, required: true)
@required_fields.each do |field, field_desc|
dm.parameter(field, 'string', field_desc, required: true)
end
@transfers.each do |pattern, config|
result = Swaig::FunctionResult.new(config['message'])
result.set_post_process(config['post_process'])
if config.key?('url')
result.swml_transfer(config['url'], config['return_message'], final: config['final'])
else
result.connect(config['address'], final: config['final'], from_addr: config['from_addr'])
end
dm.expression("${args.#{@param_name}}", pattern, result)
end
default_result = Swaig::FunctionResult.new(@default_message)
dm.expression("${args.#{@param_name}}", '/.*/', default_result)
[{ datamap: dm.to_swaig_function }]
end
|
#setup ⇒ Object
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/swml_transfer.rb', line 15
def setup
@transfers = get_param('transfers')
return false unless @transfers.is_a?(Hash) && !@transfers.empty?
@tool_name = get_param('tool_name', default: 'transfer_call')
@desc = get_param('description', default: 'Transfer call based on pattern matching')
@param_name = get_param('parameter_name', default: 'transfer_type')
@param_desc = get_param('parameter_description', default: 'The type of transfer to perform')
@default_message = get_param('default_message', default: 'Please specify a valid transfer type.')
@required_fields = get_param('required_fields') || {}
@transfers.each do |pattern, config|
return false unless config.is_a?(Hash)
return false unless config.key?('url') || config.key?('address')
config['message'] ||= 'Transferring you now...'
config['return_message'] ||= 'The transfer is complete. How else can I help you?'
config['post_process'] = true unless config.key?('post_process')
config['final'] = true unless config.key?('final')
end
true
end
|
#supports_multiple_instances? ⇒ Boolean
13
|
# File 'lib/signalwire/skills/builtin/swml_transfer.rb', line 13
def supports_multiple_instances?; true; end
|