| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package SignalWire::Agents::Skills::Builtin::SwmlTransfer; |
|
2
|
3
|
|
|
3
|
|
25
|
use strict; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
132
|
|
|
3
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
201
|
|
|
4
|
3
|
|
|
3
|
|
19
|
use Moo; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
|
|
extends 'SignalWire::Agents::Skills::SkillBase'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1472
|
use SignalWire::Agents::Skills::SkillRegistry; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
2999
|
|
|
8
|
|
|
|
|
|
|
SignalWire::Agents::Skills::SkillRegistry->register_skill('swml_transfer', __PACKAGE__); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has '+skill_name' => (default => sub { 'swml_transfer' }); |
|
11
|
|
|
|
|
|
|
has '+skill_description' => (default => sub { 'Transfer calls between agents based on pattern matching' }); |
|
12
|
|
|
|
|
|
|
has '+supports_multiple_instances' => (default => sub { 1 }); |
|
13
|
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
0
|
2286
|
sub setup { 1 } |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub register_tools { |
|
17
|
3
|
|
|
3
|
0
|
545
|
my ($self) = @_; |
|
18
|
3
|
|
100
|
|
|
37
|
my $tool_name = $self->params->{tool_name} // 'transfer_call'; |
|
19
|
3
|
|
50
|
|
|
20
|
my $description = $self->params->{description} // 'Transfer call based on pattern matching'; |
|
20
|
3
|
|
100
|
|
|
19
|
my $param_name = $self->params->{parameter_name} // 'transfer_type'; |
|
21
|
3
|
|
100
|
|
|
16
|
my $transfers = $self->params->{transfers} // {}; |
|
22
|
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
13
|
my @patterns = keys %$transfers; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Build DataMap expressions from transfer patterns |
|
26
|
3
|
|
|
|
|
5
|
my @expressions; |
|
27
|
3
|
|
|
|
|
11
|
for my $pattern (@patterns) { |
|
28
|
3
|
|
|
|
|
7
|
my $cfg = $transfers->{$pattern}; |
|
29
|
3
|
|
33
|
|
|
44
|
my $url = $cfg->{url} // $cfg->{address} // ''; |
|
|
|
|
0
|
|
|
|
|
|
30
|
|
|
|
|
|
|
push @expressions, { |
|
31
|
|
|
|
|
|
|
string => "\${args.$param_name}", |
|
32
|
|
|
|
|
|
|
pattern => $pattern, |
|
33
|
|
|
|
|
|
|
output => { |
|
34
|
3
|
|
66
|
|
|
40
|
response => $cfg->{message} // "Transferring to $pattern", |
|
35
|
|
|
|
|
|
|
action => [{ swml_transfer => $url }], |
|
36
|
|
|
|
|
|
|
}, |
|
37
|
|
|
|
|
|
|
}; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$self->agent->register_swaig_function({ |
|
41
|
|
|
|
|
|
|
function => $tool_name, |
|
42
|
|
|
|
|
|
|
description => $description, |
|
43
|
|
|
|
|
|
|
parameters => { |
|
44
|
|
|
|
|
|
|
type => 'object', |
|
45
|
|
|
|
|
|
|
properties => { |
|
46
|
|
|
|
|
|
|
$param_name => { |
|
47
|
|
|
|
|
|
|
type => 'string', |
|
48
|
3
|
|
50
|
|
|
97
|
description => $self->params->{parameter_description} // 'The transfer destination', |
|
49
|
|
|
|
|
|
|
}, |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
|
|
|
|
|
|
required => [$param_name], |
|
52
|
|
|
|
|
|
|
}, |
|
53
|
|
|
|
|
|
|
data_map => { expressions => \@expressions }, |
|
54
|
|
|
|
|
|
|
}); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get_hints { |
|
58
|
1
|
|
|
1
|
0
|
38
|
my ($self) = @_; |
|
59
|
1
|
|
|
|
|
7
|
my @hints = ('transfer', 'connect', 'speak to', 'talk to'); |
|
60
|
1
|
|
50
|
|
|
3
|
for my $pattern (keys %{ $self->params->{transfers} // {} }) { |
|
|
1
|
|
|
|
|
11
|
|
|
61
|
1
|
|
|
|
|
8
|
push @hints, split(/[\s_-]+/, $pattern); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
1
|
|
|
|
|
5
|
return \@hints; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _get_prompt_sections { |
|
67
|
1
|
|
|
1
|
|
4
|
my ($self) = @_; |
|
68
|
1
|
|
50
|
|
|
6
|
my $transfers = $self->params->{transfers} // {}; |
|
69
|
1
|
|
|
|
|
6
|
my @destinations = map { "- $_" } keys %$transfers; |
|
|
1
|
|
|
|
|
6
|
|
|
70
|
|
|
|
|
|
|
return [ |
|
71
|
|
|
|
|
|
|
{ |
|
72
|
1
|
|
|
|
|
12
|
title => 'Transferring', |
|
73
|
|
|
|
|
|
|
body => "Available transfer destinations:\n" . join("\n", @destinations), |
|
74
|
|
|
|
|
|
|
}, |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
|
|
|
|
|
|
title => 'Transfer Instructions', |
|
77
|
|
|
|
|
|
|
body => 'When the user wants to be transferred, use the transfer tool.', |
|
78
|
|
|
|
|
|
|
}, |
|
79
|
|
|
|
|
|
|
]; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub get_parameter_schema { |
|
83
|
|
|
|
|
|
|
return { |
|
84
|
0
|
|
|
0
|
0
|
|
%{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema }, |
|
|
0
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
transfers => { type => 'object', required => 1 }, |
|
86
|
|
|
|
|
|
|
description => { type => 'string' }, |
|
87
|
|
|
|
|
|
|
parameter_name => { type => 'string', default => 'transfer_type' }, |
|
88
|
|
|
|
|
|
|
parameter_description => { type => 'string' }, |
|
89
|
|
|
|
|
|
|
default_message => { type => 'string' }, |
|
90
|
|
|
|
|
|
|
}; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |