This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoiceXml.php
99 lines (73 loc) · 3.04 KB
/
VoiceXml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace App;
class VoiceXML {
protected $builder;
protected $prompts;
protected $response;
function __construct()
{
$this->prompts = collect([]);
}
public function prompt($src)
{
$this->prompts->push($src);
return $this;
}
public function response($formId, $endpoint)
{
$vxml = new \SimpleXMLElement('<vxml/>');
$vxml->addAttribute('xmlns', 'http://www.w3.org/2001/vxml');
$vxml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$vxml->addAttribute('version', '2.1');
$vxml->addAttribute('xsi:schemaLocation', 'http://www.w3.org/2001/vxml http://www.w3.org/TR/2007/REC-voicexml21-20070619/vxml.xsd');
$property = $vxml->addChild('property');
$property->addAttribute('name', 'inputmodes');
$property->addAttribute('value', 'dtmf');
$form = $vxml->addChild('form');
$form->addAttribute('id', $formId);
$field = $form->addChild('field');
$field->addAttribute('name', 'option');
$prompts = $field->addChild('prompt');
$this->prompts->each(function($src) use ($prompts) {
$prompts->addChild('audio')->addAttribute('src', $src);
});
$filled = $field->addChild('filled');
$if = $filled->addChild('if');
$if->addAttribute('cond', "option == '1'");
$c = $if->addChild('assign');
$c->addAttribute('name', 'option');
$c->addAttribute('expr', "'1'");
$if->addChild('elseif')->addAttribute('cond', "option == '2'");
$c = $if->addChild('assign');
$c->addAttribute('name', 'option');
$c->addAttribute('expr', "'2'");
$if->addChild('elseif')->addAttribute('cond', "option == '3'");
$c = $if->addChild('assign');
$c->addAttribute('name', 'option');
$c->addAttribute('expr', "'3'");
$if->addChild('elseif')->addAttribute('cond', "option == '4'");
$c = $if->addChild('assign');
$c->addAttribute('name', 'option');
$c->addAttribute('expr', "'4'");
$if->addChild('else');
$filled->addChild('goto')->addAttribute('next', "submit_form");
$sForm = $vxml->addChild('form');
$sForm->addAttribute('id', 'submit_form');
$block = $sForm->addChild('block');
$submit = $block->addChild('submit');
$submit->addAttribute('next', $endpoint);
$submit->addAttribute('method', 'POST');
$submit->addAttribute('namelist', 'option');
return $vxml;
}
public function disconnect()
{
$vxml = new \SimpleXMLElement('<vxml/>');
$vxml->addAttribute('xmlns', 'http://www.w3.org/2001/vxml');
$vxml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$vxml->addAttribute('version', '2.1');
$vxml->addAttribute('xsi:schemaLocation', 'http://www.w3.org/2001/vxml http://www.w3.org/TR/2007/REC-voicexml21-20070619/vxml.xsd');
$property = $vxml->addChild('disconnect');
return $vxml;
}
}