« blib/lib/SignalWire/Skills/Builtin/CustomSkills.pm
↑ Summary
blib/lib/SignalWire/REST/Namespaces/Compat.pm »
| 1 | package SignalWire::Prefabs::Survey; | ||||||||||||
| 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::Agent::AgentBase'; | |||||||||||
| 10 | |||||||||||||
| 11 | 0 | ▶ | has survey_name => (is => 'ro', default => sub { 'Survey' }); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 12 | 0 | ▶ | has survey_questions => (is => 'ro', default => sub { [] }); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 13 | 8 | ▶ | has introduction => (is => 'ro', default => sub { '' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 10 | ▶ | has conclusion => (is => 'ro', default => sub { '' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 10 | ▶ | has brand_name => (is => 'ro', default => sub { '' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 10 | ▶ | has max_retries => (is => 'ro', default => sub { 2 }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 10 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 19 | 10 | my ($self, $args) = @_; | |||||||||||
| 20 | |||||||||||||
| 21 | 10 | ▶ | $self->name('survey') if $self->name eq 'agent'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | 10 | ▶ | $self->route('/survey') if $self->route eq '/'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | 10 | $self->use_pom(1); | |||||||||||
| 24 | |||||||||||||
| 25 | 10 | my $questions = $self->survey_questions; | |||||||||||
| 26 | |||||||||||||
| 27 | 10 | $self->set_global_data({ | |||||||||||
| 28 | survey_name => $self->survey_name, | ||||||||||||
| 29 | questions => $questions, | ||||||||||||
| 30 | question_index => 0, | ||||||||||||
| 31 | answers => {}, | ||||||||||||
| 32 | completed => JSON::false, | ||||||||||||
| 33 | }); | ||||||||||||
| 34 | |||||||||||||
| 35 | 10 | ▶ | my $intro = $self->introduction || "Welcome to the ${\$self->survey_name}."; | ||||||||||
|
Condition100%2/2
$self->introduction || "Welcome to the ${\$self->survey_name;}."
MC/DC100%1/1
$self->introduction || "Welcome to the ${\$self->survey_name;}."
$self->introduction
Truth table100%2/2
A
A= $self->introduction
| |||||||||||||
| 36 | 10 | $self->prompt_add_section( | |||||||||||
| 37 | 'Survey Introduction', | ||||||||||||
| 38 | $intro, | ||||||||||||
| 39 | bullets => [ | ||||||||||||
| 40 | 'Introduce the survey to the user', | ||||||||||||
| 41 | 'Ask each question in sequence', | ||||||||||||
| 42 | 'Validate responses based on question type', | ||||||||||||
| 43 | 'Thank the user when complete', | ||||||||||||
| 44 | ], | ||||||||||||
| 45 | ); | ||||||||||||
| 46 | |||||||||||||
| 47 | # Build question descriptions | ||||||||||||
| 48 | 10 | my @q_bullets; | |||||||||||
| 49 | 10 | for my $q (@$questions) { | |||||||||||
| 50 | 12 | my $desc = "Q: $q->{text} (type: $q->{type})"; | |||||||||||
| 51 | 12 | ▶ | $desc .= " [required]" if $q->{required}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 52 | 12 | push @q_bullets, $desc; | |||||||||||
| 53 | } | ||||||||||||
| 54 | 10 | $self->prompt_add_section('Survey Questions', '', bullets => \@q_bullets); | |||||||||||
| 55 | |||||||||||||
| 56 | # Register survey tools | ||||||||||||
| 57 | $self->define_tool( | ||||||||||||
| 58 | name => 'submit_survey_answer', | ||||||||||||
| 59 | description => 'Submit an answer for the current survey question', | ||||||||||||
| 60 | parameters => { | ||||||||||||
| 61 | type => 'object', | ||||||||||||
| 62 | properties => { | ||||||||||||
| 63 | question_id => { type => 'string', description => 'ID of the question' }, | ||||||||||||
| 64 | answer => { type => 'string', description => 'The answer' }, | ||||||||||||
| 65 | }, | ||||||||||||
| 66 | required => ['question_id', 'answer'], | ||||||||||||
| 67 | }, | ||||||||||||
| 68 | 1 | ▶ | handler => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 69 | 1 | my ($a, $raw) = @_; | |||||||||||
| 70 | 1 | require SignalWire::SWAIG::FunctionResult; | |||||||||||
| 71 | 1 | return SignalWire::SWAIG::FunctionResult->new( | |||||||||||
| 72 | response => "Survey answer for $a->{question_id}: $a->{answer}", | ||||||||||||
| 73 | ); | ||||||||||||
| 74 | }, | ||||||||||||
| 75 | 10 | ); | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | 2 | 1; | |||||||||||