| 1 | package SignalWire::Skills::Builtin::SwmlTransfer; | ||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 4 | 4 | ▶ | use Moo; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | 4 | extends 'SignalWire::Skills::SkillBase'; | |||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||
| 7 | 4 | ▶ | use SignalWire::Skills::SkillRegistry; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | 4 | SignalWire::Skills::SkillRegistry->register_skill('swml_transfer', __PACKAGE__); | |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | 7 | ▶ | has '+skill_name' => (default => sub { 'swml_transfer' }); | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 11 | 7 | ▶ | has '+skill_description' => (default => sub { 'Transfer calls between agents based on pattern matching' }); | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 12 | 7 | ▶ | has '+supports_multiple_instances' => (default => sub { 1 }); | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||
| 14 | 4 | ▶ | sub setup { 1 } | ||||||||||||||||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | 3 | ▶ | sub register_tools { | ||||||||||||||||||||||
|
Subroutine
register_tools: called CC=10 SCAR=23.5
Pod
undocumented
| |||||||||||||||||||||||||
| 17 | 3 | my ($self) = @_; | |||||||||||||||||||||||
| 18 | 3 | ▶ | my $tool_name = $self->params->{tool_name} // 'transfer_call'; | ||||||||||||||||||||||
|
Condition100%2/2
$self->params->{"tool_name"} // "transfer_call"
MC/DC100%1/1
$self->params->{"tool_name"} // "transfer_call"
$self->params->{"tool_name"}
Truth table100%2/2
A
A= $self->params->{"tool_name"}
| |||||||||||||||||||||||||
| 19 | 3 | ▶ | my $description = $self->params->{description} // 'Transfer call based on pattern matching'; | ||||||||||||||||||||||
|
Condition50%1/2
$self->params->{"description"} // "Transfer call based on pattern matching"
MC/DC0%0/1
$self->params->{"description"} // "Transfer call based on pattern matching"
$self->params->{"description"}
Truth table50%1/2
A
A= $self->params->{"description"}
| |||||||||||||||||||||||||
| 20 | 3 | ▶ | my $param_name = $self->params->{parameter_name} // 'transfer_type'; | ||||||||||||||||||||||
|
Condition100%2/2
$self->params->{"parameter_name"} // "transfer_type"
MC/DC100%1/1
$self->params->{"parameter_name"} // "transfer_type"
$self->params->{"parameter_name"}
Truth table100%2/2
A
A= $self->params->{"parameter_name"}
| |||||||||||||||||||||||||
| 21 | 3 | ▶ | my $transfers = $self->params->{transfers} // {}; | ||||||||||||||||||||||
|
Condition100%2/2
$self->params->{"transfers"} // {}
MC/DC100%1/1
$self->params->{"transfers"} // {}
$self->params->{"transfers"}
Truth table100%2/2
A
A= $self->params->{"transfers"}
| |||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||
| 23 | 3 | my @patterns = keys %$transfers; | |||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||
| 25 | # Build DataMap expressions from transfer patterns | ||||||||||||||||||||||||
| 26 | 3 | my @expressions; | |||||||||||||||||||||||
| 27 | 3 | for my $pattern (@patterns) { | |||||||||||||||||||||||
| 28 | 3 | my $cfg = $transfers->{$pattern}; | |||||||||||||||||||||||
| 29 | 3 | ▶ | my $url = $cfg->{url} // $cfg->{address} // ''; | ||||||||||||||||||||||
|
Condition40%2/5
($cfg->{"url"} // $cfg->{"address"}) // ""
$cfg->{"url"} // $cfg->{"address"}
MC/DC0%0/2
($cfg->{"url"} // $cfg->{"address"}) // ""
$cfg->{"url"}
$cfg->{"address"}
Truth table33%1/3
A // B
A= $cfg->{"url"}B= $cfg->{"address"}
| |||||||||||||||||||||||||
| 30 | push @expressions, { | ||||||||||||||||||||||||
| 31 | string => "\${args.$param_name}", | ||||||||||||||||||||||||
| 32 | pattern => $pattern, | ||||||||||||||||||||||||
| 33 | output => { | ||||||||||||||||||||||||
| 34 | 3 | ▶ | response => $cfg->{message} // "Transferring to $pattern", | ||||||||||||||||||||||
|
Condition100%2/2
$cfg->{"message"} // "Transferring to $pattern"
MC/DC100%1/1
$cfg->{"message"} // "Transferring to $pattern"
$cfg->{"message"}
Truth table100%2/2
A
A= $cfg->{"message"}
| |||||||||||||||||||||||||
| 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 | ▶ | description => $self->params->{parameter_description} // 'The transfer destination', | ||||||||||||||||||||||
|
Condition50%1/2
$self->params->{"parameter_description"} // "The transfer destination"
MC/DC0%0/1
$self->params->{"parameter_description"} // "The transfer destination"
$self->params->{"parameter_description"}
Truth table50%1/2
A
A= $self->params->{"parameter_description"}
| |||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||
| 51 | required => [$param_name], | ||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||
| 53 | data_map => { expressions => \@expressions }, | ||||||||||||||||||||||||
| 54 | }); | ||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||
| 57 | 1 | ▶ | sub get_hints { | ||||||||||||||||||||||
|
Subroutine
get_hints: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||
| 58 | 1 | my ($self) = @_; | |||||||||||||||||||||||
| 59 | 1 | my @hints = ('transfer', 'connect', 'speak to', 'talk to'); | |||||||||||||||||||||||
| 60 | 1 | ▶ | for my $pattern (keys %{ $self->params->{transfers} // {} }) { | ||||||||||||||||||||||
|
Condition50%1/2
$self->params->{"transfers"} // {}
MC/DC0%0/1
$self->params->{"transfers"} // {}
$self->params->{"transfers"}
Truth table50%1/2
A
A= $self->params->{"transfers"}
| |||||||||||||||||||||||||
| 61 | 1 | push @hints, split(/[\s_-]+/, $pattern); | |||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||
| 63 | 1 | return \@hints; | |||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||
| 66 | 1 | ▶ | sub _get_prompt_sections { | ||||||||||||||||||||||
|
Subroutine
_get_prompt_sections: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||
| 67 | 1 | my ($self) = @_; | |||||||||||||||||||||||
| 68 | 1 | ▶ | my $transfers = $self->params->{transfers} // {}; | ||||||||||||||||||||||
|
Condition50%1/2
$self->params->{"transfers"} // {}
MC/DC0%0/1
$self->params->{"transfers"} // {}
$self->params->{"transfers"}
Truth table50%1/2
A
A= $self->params->{"transfers"}
| |||||||||||||||||||||||||
| 69 | 1 | my @destinations = map { "- $_" } keys %$transfers; | |||||||||||||||||||||||
| 70 | return [ | ||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||
| 72 | 1 | 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 | 0 | ▶ | sub get_parameter_schema { | ||||||||||||||||||||||
|
Subroutine
get_parameter_schema: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 83 | return { | ||||||||||||||||||||||||
| 84 | 0 | %{ SignalWire::Skills::SkillBase->get_parameter_schema }, | |||||||||||||||||||||||
| 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 | 4 | 1; | |||||||||||||||||||||||