blib/lib/SignalWire/Agents/Prefabs/Receptionist.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 87.9% 51 / 58 CC 7 SCAR 9.6
CC
7
Cov
91%
BUILD
4.0
__ANON__
4.0
__ANON__
1.1
CRAP 2.6
« blib/lib/SignalWire/Agents/Logging.pm ↑ Summary blib/lib/SignalWire/Agents/REST/Namespaces/Fabric.pm »
1 package SignalWire::Agents::Prefabs::Receptionist;
2 # Copyright (c) 2025 SignalWire
3 # Licensed under the MIT License.
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use JSON qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 extends 'SignalWire::Agents::Agent::AgentBase';
10  
11 0 ▶has departments => (is => 'ro', default => sub { [] });
Subroutine __ANON__: not called CC=1 SCAR=1.2
12 9 ▶has greeting => (is => 'ro', default => sub { 'Thank you for calling. How can I help you today?' });
Subroutine __ANON__: called CC=1 SCAR=0.0
13 11 ▶has voice => (is => 'ro', default => sub { 'rime.spore' });
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 11 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
16 11 my ($self, $args) = @_;
17  
18 11 ▶ $self->name('receptionist') if $self->name eq 'agent';
Branch: 1 branch
BranchTrueFalseTotal
if $self->name eq "agent" 11 0 11
19 11 ▶ $self->route('/receptionist') if $self->route eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if $self->route eq "/" 11 0 11
20 11 $self->use_pom(1);
21  
22 11 my $departments = $self->departments;
23  
24 11 $self->set_global_data({
25 departments => $departments,
26 caller_info => {},
27 });
28  
29 # Build department list for prompt
30 11 my @dept_bullets;
31 11 for my $dept (@$departments) {
32 14 push @dept_bullets, "$dept->{name}: $dept->{description}";
33 }
34  
35 $self->prompt_add_section(
36 11 'Receptionist Role',
37 $self->greeting,
38 bullets => [
39 'Greet the caller warmly',
40 'Determine which department they need',
41 'Transfer them to the correct department',
42 @dept_bullets,
43 ],
44 );
45  
46 # Register transfer tool
47 $self->define_tool(
48 name => 'transfer_to_department',
49 description => 'Transfer the caller to the specified department',
50 parameters => {
51 type => 'object',
52 properties => {
53 department => { type => 'string', description => 'Department name to transfer to' },
54 },
55 required => ['department'],
56 },
57 3 ▶ handler => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
58 3 my ($a, $raw) = @_;
59 3 require SignalWire::Agents::SWAIG::FunctionResult;
60 3 ▶ my $dept_name = $a->{department} // '';
Condition50%1/2
$a->{"department"} // ""
l!l
30
MC/DC0%0/1
$a->{"department"} // ""
$a->{"department"}
Truth table50%1/2
A
A= $a->{"department"}
Aresult
11
00
61 3 for my $dept (@$departments) {
62 3 ▶ if (lc($dept->{name}) eq lc($dept_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $dept->{"name"} eq lc $dept_name) 2 1 3
63 2 my $result = SignalWire::Agents::SWAIG::FunctionResult->new(
64 response => "Transferring to $dept_name",
65 );
66 2 return $result;
67 }
68 }
69 1 return SignalWire::Agents::SWAIG::FunctionResult->new(
70 response => "Department '$dept_name' not found",
71 );
72 },
73 11 );
74 }
75  
76 2 1;
« blib/lib/SignalWire/Agents/Logging.pm ↑ Summary blib/lib/SignalWire/Agents/REST/Namespaces/Fabric.pm »