-
Notifications
You must be signed in to change notification settings - Fork 62
/
tropo.class.php
1730 lines (1579 loc) · 48.7 KB
/
tropo.class.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This file contains PHP classes that can be used to interact with the Tropo WebAPI/
* @see https://www.tropo.com/docs/webapi/
*
* @copyright 2010 Mark J. Headd (http://www.voiceingov.org)
* @package TropoPHP
* @author Mark Headd
* @author Adam Kalsey
*/
/**
* The main Tropo WebAPI class.
* The methods on this class can be used to invoke specifc Tropo actions.
* @package TropoPHP
* @see https://www.tropo.com/docs/webapi/tropo.htm
*
*/
include 'tropo-rest.class.php';
class Tropo extends BaseClass {
/**
* The container for JSON actions.
*
* @var array
* @access private
*/
public $tropo;
/**
* The TTS voice to use when rendering content.
*
* @var string
* @access private
*/
private $_voice;
/**
* The language to use when rendering content.
*
* @var string
* @access private
*/
private $_language;
/**
* Class constructor for the Tropo class.
* @access private
*/
public function __construct() {
$this->tropo = array();
}
/**
* Set a default voice for use with all Text To Speech.
*
* Tropo's text to speech engine can pronounce your text with
* a variety of voices in different languages. All elements where
* you can create text to speech (TTS) accept a voice parameter.
* Tropo's default is "Allison" but you can set a default for this
* script here.
*
* @param string $voice
*/
public function setVoice($voice) {
$this->_voice = $voice;
}
/**
* Set a default language to use in speech recognition.
*
* When recognizing spoken input, Tropo allows you to set a language
* to let the platform know which language is being spoken and which
* recognizer to use. The default is en-us (US English), but you can
* set a different default to be used in your application here.
*
* @param string $language
*/
public function setLanguage($language) {
$this->_language = $language;
}
/**
* Sends a prompt to the user and optionally waits for a response.
*
* The ask method allows for collecting input using either speech
* recognition or DTMF (also known as Touch Tone). You can either
* pass in a fully-formed Ask object or a string to use as the
* prompt and an array of parameters.
*
* The available parameters are
* - choices: (string) The grammar to use in recognizing and validating input
* - as: (string) an SSML type hinting how to say the TTS
* - event: (string) only say this on certain events (i.e. no input)
* - voice: (string) Override the default TTS voice
* - attempts: (int) How many times the caller can attempt input before
* an error is thrown
* - bargein: (bool) Should the user be allowed to barge in before TTS is complete?
* - minConfidence: (int) How confident should Tropo be in a speech reco match?
* - name: (string) identifies the return value of an ask, so you know the context for
* the returned information. As an example, if you asked the user for their favorite
* color, the name value would be "color" while the returned value might be "blue".
* - required: (bool) Is input required here?
* - timeout: (float) How long (in seconds) should Tropo wait for input?
* - mode: (string) Only applies to the voice channel and can be either 'speech', 'dtmf', or 'both'.
* - terminator: (string) This is the touch-tone key (also known as "DTMF digit") that indicates the end of input.
*
* @param string|Ask $ask
* @param array $params
* @see https://www.tropo.com/docs/webapi/ask.htm
*/
public function ask($ask, Array $params=NULL) {
if(!is_object($ask)) {
$voice = isset($this->_voice) ? $this->_voice : null;
$p = array('as','event','voice','attempts', 'bargein', 'minConfidence', 'name', 'required', 'timeout');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$say = new Say($ask, $as, null, $voice);
$params["mode"] = isset($params["mode"]) ? $params["mode"] : null;
$params["dtmf"] = isset($params["dtmf"]) ? $params["dtmf"] : null;
$choices = isset($params["choices"]) ? new Choices($params["choices"], $params["mode"], $params["terminator"]) : null;
$ask = new Ask($attempts, $bargein, $choices, $minConfidence, $name, $required, $say, $timeout, $voice);
if (is_array($event)) {
// If an event was passed in, add the events to the Ask
foreach ($event as $e => $val){
$ask->addEvent(new Say($val, $as, $e, $voice));
}
}
}
$this->ask = sprintf($ask);
}
/**
* Places a call or sends an an IM, Twitter, or SMS message. To start a call, use the Session API to tell Tropo to launch your code.
*
* @param string|Call $call
* @param array $params
* @see https://www.tropo.com/docs/webapi/call.htm
*/
public function call($call, Array $params=NULL) {
if(!is_object($call)) {
$p = array('to', 'from', 'network', 'channel', 'answerOnMedia', 'timeout', 'headers', 'recording');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$call = new Call($call, $from, $network, $channel, $answerOnMedia, $timeout, $headers, $recording);
}
$this->call = sprintf($call);
}
/**
* This object allows multiple lines in separate sessions to be conferenced together so that the parties on each line can talk to each other simultaneously.
* This is a voice channel only feature.
*
* @param string|Conference $conference
* @param array $params
* @see https://www.tropo.com/docs/webapi/conference.htm
*/
public function conference($conference, Array $params=NULL) {
if(!is_object($conference)) {
$p = array('name', 'id', 'mute', 'on', 'playTones', 'required', 'terminator');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$conference = new Conference($name, $id, $mute, $on, $playTones, $required, $terminator);
}
$this->conference = sprintf($conference);
}
/**
* This function instructs Tropo to "hang-up" or disconnect the session associated with the current session.
* @see https://www.tropo.com/docs/webapi/hangup.htm
*/
public function hangup() {
$hangup = new Hangup();
$this->hangup = sprintf($hangup);
}
/**
* A shortcut method to create a session, say something, and hang up, all in one step. This is particularly useful for sending out a quick SMS or IM.
*
* @param string|Message $message
* @param array $params
* @see https://www.tropo.com/docs/webapi/message.htm
*/
public function message($message, Array $params=null) {
if(!is_object($message)) {
$say = new Say($message);
$to = $params["to"];
$p = array('channel', 'network', 'from', 'voice', 'timeout', 'answerOnMedia','headers');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$message = new Message($say, $to, $channel, $network, $from, $voice, $timeout, $answerOnMedia, $headers);
}
$this->message = sprintf($message);
}
/**
* Adds an event callback so that your application may be notified when a particular event occurs.
* Possible events are: "continue", "error", "incomplete" and "hangup".
*
* @param array $params
* @see https://www.tropo.com/docs/webapi/on.htm
*/
public function on($on) {
if (!is_object($on) && is_array($on)) {
$params = $on;
$say = (array_key_exists('say', $params)) ? new Say($params["say"]) : null;
$next = (array_key_exists('next', $params)) ? $params["next"] : null;
$on = new On($params["event"], $next, $say);
}
$this->on = sprintf($on);
}
/**
* Plays a prompt (audio file or text to speech) and optionally waits for a response from the caller that is recorded.
* If collected, responses may be in the form of DTMF or speech recognition using a simple grammar format defined below.
* The record funtion is really an alias of the prompt function, but one which forces the record option to true regardless of how it is (or is not) initially set.
* At the conclusion of the recording, the audio file may be automatically sent to an external server via FTP or an HTTP POST/Multipart Form.
* If specified, the audio file may also be transcribed and the text returned to you via an email address or HTTP POST/Multipart Form.
*
* @param array|Record $record
* @see https://www.tropo.com/docs/webapi/record.htm
*/
public function record($record) {
if(!is_object($record) && is_array($record)) {
$params = $record;
$choices = isset($params["choices"]) ? new Choices($params["choices"]) : null;
$say = $params["say"];
if (is_array($params['transcription'])) {
$p = array('url', 'id', 'emailFormat');
foreach ($p as $option) {
$$option = null;
if (!is_array($params["transcription"]) || !array_key_exists($option, $params["transcription"])) {
$params["transcription"][$option] = null;
}
}
$transcription = new Transcription($params["transcription"]["url"],$params["transcription"]["id"],$params["transcription"]["emailFormat"]);
} else {
$transcription = $params["transcription"];
}
$p = array('attempts', 'bargein', 'beep', 'format', 'maxTime', 'maxSilence', 'method', 'password', 'required', 'timeout', 'username', 'url');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$record = new Record($attempts, $bargein, $beep, $choices, $format, $maxSilence, $maxTime, $method, $password, $required, $say, $timeout, $transcription, $username, $url);
}
$this->record = sprintf($record);
}
/**
* The redirect function forwards an incoming call to another destination / phone number before answering it.
* The redirect function must be called before answer is called; redirect expects that a call be in the ringing or answering state.
* Use transfer when working with active answered calls.
*
* @param string|Redirect $redirect
* @param array $params
* @see https://www.tropo.com/docs/webapi/redirect.htm
*/
public function redirect($redirect, Array $params=NULL) {
if(!is_object($redirect)) {
$to = isset($params["to"]) ? $params["to"]: null;
$from = isset($params["from"]) ? $params["from"] : null;
$redirect = new Redirect($to, $from);
}
$this->redirect = sprintf($redirect);
}
/**
* Allows Tropo applications to reject incoming sessions before they are answered.
* For example, an application could inspect the callerID variable to determine if the user is known, and then use the reject call accordingly.
*
* @see https://www.tropo.com/docs/webapi/reject.htm
*
*/
public function reject() {
$reject = new Reject();
$this->reject = sprintf($reject);
}
/**
* When the current session is a voice channel this key will either play a message or an audio file from a URL.
* In the case of an text channel it will send the text back to the user via i nstant messaging or SMS.
*
* @param string|Say $say
* @param array $params
* @see https://www.tropo.com/docs/webapi/say.htm
*/
public function say($say, Array $params=NULL) {
if(!is_object($say)) {
if (isset($this->_voice)) {
$voice = $this->_voice;
}
$p = array('as', 'format', 'event','voice');
$value = $say;
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$say = new Say($value, $as, $event, $voice);
}
$this->say = array(sprintf($say));
}
/**
* Allows Tropo applications to begin recording the current session.
* The resulting recording may then be sent via FTP or an HTTP POST/Multipart Form.
*
* @param array|StartRecording $startRecording
* @see https://www.tropo.com/docs/webapi/startrecording.htm
*/
public function startRecording($startRecording) {
if(!is_object($startRecording) && is_array($startRecording)) {
$params = $startRecording;
$p = array('format', 'method', 'password', 'url', 'username');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$startRecording = new StartRecording($format, $method, $password, $url, $username);
}
$this->startRecording = sprintf($startRecording);
}
/**
* Stops a previously started recording.
*
*
*/
public function stopRecording() {
$stopRecording = new stopRecording();
$this->stopRecording = sprintf($stopRecording);
}
/**
* Transfers an already answered call to another destination / phone number.
* Call may be transferred to another phone number or SIP address, which is set through the "to" parameter and is in URL format.
*
* @param string|Transfer $transfer
* @param array $params
* @see https://www.tropo.com/docs/webapi/transfer.htm
*/
public function transfer($transfer, Array $params=NULL) {
if(!is_object($transfer)) {
$choices = isset($params["choices"]) ? new Choices($params["choices"]) : null;
$to = isset($params["to"]) ? $params["to"] : $transfer;
$p = array('answerOnMedia', 'ringRepeat', 'timeout', 'from', 'on');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$transfer = new Transfer($to, $answerOnMedia, $choices, $from, $ringRepeat, $timeout, $on);
}
$this->transfer = sprintf($transfer);
}
/**
* Launches a new session with the Tropo Session API.
* (Pass through to SessionAPI class.)
*
* @param string $token Your outbound session token from Tropo
* @param array $params An array of key value pairs that will be added as query string parameters
* @return bool True if the session was launched successfully
*/
public function createSession($token, Array $params=NULL) {
try {
$session = new SessionAPI();
$result = $session->createSession($token, $params);
return $result;
}
// If an exception occurs, wrap it in a TropoException and rethrow.
catch (Exception $ex) {
throw new TropoException($ex->getMessage(), $ex->getCode());
}
}
/**
* Creates a new Tropo Application
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param array $params
* @return string JSON
*/
public function createApplication($userid, $password, Array $params) {
$p = array('href', 'name', 'voiceUrl', 'messagingUrl', 'platform', 'partition');
foreach ($p as $property) {
$$property = null;
if (is_array($params) && array_key_exists($property, $params)) {
$$property = $params[$property];
}
}
try {
$provision = new ProvisioningAPI($userid, $password);
$result = $provision->createApplication($href, $name, $voiceUrl, $messagingUrl, $platform, $partition);
return $result;
}
// If an exception occurs, wrap it in a TropoException and rethrow.
catch (Exception $ex) {
throw new TropoException($ex->getMessage(), $ex->getCode());
}
}
/**
* Add/Update an address (phone number, IM address or token) for an existing Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @param array $params
* @return string JSON
*/
public function updateApplicationAddress($userid, $passwd, $applicationID, Array $params) {
$p = array('type', 'prefix', 'number', 'city', 'state', 'channel', 'username', 'password', 'token');
foreach ($p as $property) {
$$property = null;
if (is_array($params) && array_key_exists($property, $params)) {
$$property = $params[$property];
}
}
try {
$provision = new ProvisioningAPI($userid, $passwd);
$result = $provision->updateApplicationAddress($applicationID, $type, $prefix, $number, $city, $state, $channel, $username, $password, $token);
return $result;
}
// If an exception occurs, wrap it in a TropoException and rethrow.
catch (Exception $ex) {
throw new TropoException($ex->getMessage(), $ex->getCode());
}
}
/**
* Update a property (name, URL, platform, etc.) for an existing Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @param array $params
* @return string JSON
*/
public function updateApplicationProperty($userid, $password, $applicationID, Array $params) {
$p = array('href', 'name', 'voiceUrl', 'messagingUrl', 'platform', 'partition');
foreach ($p as $property) {
$$property = null;
if (is_array($params) && array_key_exists($property, $params)) {
$$property = $params[$property];
}
}
try {
$provision = new ProvisioningAPI($userid, $password);
$result = $provision->updateApplicationProperty($applicationID, $href, $name, $voiceUrl, $messagingUrl, $platform, $partition);
return $result;
}
// If an exception occurs, wrap it in a TropoException and rethrow.
catch (Exception $ex) {
throw new TropoException($ex->getMessage(), $ex->getCode());
}
}
/**
* Delete an existing Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @return string JSON
*/
public function deleteApplication($userid, $password, $applicationID) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->deleteApplication($applicationID);
}
/**
* Delete an address for an existing Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @param string $number
* @return string JSON
*/
public function deleteApplicationAddress($userid, $password, $applicationID, $addresstype, $address) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->deleteApplicationAddress($applicationID, $addresstype, $address);
}
/**
* View a list of Tropo applications.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @return string JSON
*/
public function viewApplications($userid, $password) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->viewApplications();
}
/**
* View the details of a specific Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @return string JSON
*/
public function viewSpecificApplication($userid, $password, $applicationID) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->viewSpecificApplication($applicationID);
}
/**
* View the addresses for a specific Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @return string JSON
*/
public function viewAddresses($userid, $password, $applicationID) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->viewAddresses($applicationID);
}
/**
* View a list of available exchanges for assigning a number to a Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param unknown_type $userid
* @param unknown_type $password
* @return unknown
*/
public function viewExchanges($userid, $password) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->viewExchanges();
}
/**
* Renders the Tropo object as JSON.
*
*/
public function renderJSON() {
header('Content-type: application/json');
echo $this;
}
/**
* Allows undefined methods to be called.
* This method is invloked by Tropo class methods to add action items to the Tropo array.
*
* @param string $name
* @param mixed $value
* @access private
*/
public function __set($name, $value) {
array_push($this->tropo, array($name => $value));
}
/**
* Controls how JSON structure for the Tropo object is rendered.
*
* @return string
* @access private
*/
public function __toString() {
// Remove voice and language so they do not appear in the rednered JSON.
unset($this->_voice);
unset($this->_language);
// Call the unescapeJSON() method in the parent class.
return parent::unescapeJSON(json_encode($this));
}
}
/**
* Base class for Tropo class and indvidual Tropo action classes.
* Derived classes must implement both a constructor and __toString() function.
* @package TropoPHP_Support
* @abstract BaseClass
*/
abstract class BaseClass {
/**
* Class constructor
* @abstract __construct()
*/
abstract public function __construct();
/**
* toString Function
* @abstract __toString()
*/
abstract public function __toString();
/**
* Allows derived classes to set Undeclared properties.
*
* @param mixed $attribute
* @param mixed $value
*/
public function __set($attribute, $value) {
$this->$attribute= $value;
}
/**
* Removes escape characters from a JSON string.
*
* @param string $json
* @return string
*/
public function unescapeJSON($json) {
return str_replace(array("\\", "\"{", "}\""), array("", "{", "}"), $json);
}
}
/**
* Base class for empty actions.
* @package TropoPHP_Support
*
*/
class EmptyBaseClass {
final public function __toString() {
return json_encode(null);
}
}
/**
* Action classes. Each specific object represents a specific Tropo action.
*
*/
/**
* Sends a prompt to the user and optionally waits for a response.
* @package TropoPHP_Support
*
*/
class Ask extends BaseClass {
private $_attempts;
private $_bargein;
private $_choices;
private $_minConfidence;
private $_name;
private $_required;
private $_say;
private $_timeout;
private $_voice;
/**
* Class constructor
*
* @param int $attempts
* @param boolean $bargein
* @param Choices $choices
* @param float $minConfidence
* @param string $name
* @param boolean $required
* @param Say $say
* @param int $timeout
* @param string $voice
*/
public function __construct($attempts=NULL, $bargein=NULL, Choices $choices=NULL, $minConfidence=NULL, $name=NULL, $required=NULL, Say $say=NULL, $timeout=NULL, $voice=NULL) {
$this->_attempts = $attempts;
$this->_bargein = $bargein;
$this->_choices = isset($choices) ? sprintf($choices) : null ;
$this->_minConfidence = $minConfidence;
$this->_name = $name;
$this->_required = $required;
$this->_voice = $voice;
$this->_say = isset($say) ? sprintf($say) : null;
$this->_say = array($this->_say); // Convert the say to an array
$this->_timeout = $timeout;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if(isset($this->_attempts)) { $this->attempts = $this->_attempts; }
if(isset($this->_bargein)) { $this->bargein = $this->_bargein; }
if(isset($this->_choices)) { $this->choices = $this->_choices; }
if(isset($this->_minConfidence)) { $this->minConfidence = $this->_minConfidence; }
if(isset($this->_name)) { $this->name = $this->_name; }
if(isset($this->_required)) { $this->required = $this->_required; }
if(isset($this->_say)) { $this->say = $this->_say; }
if(isset($this->_timeout)) { $this->timeout = $this->_timeout; }
if(isset($this->_voice)) { $this->voice = $this->_voice; }
return $this->unescapeJSON(json_encode($this));
}
/**
* Adds an additional Say to the Ask
*
* Used to add events such as a prompt to say on timeout or nomatch
*
* @param Say $say A say object
*/
public function addEvent(Say $say) {
$this->_say[] = sprintf($say);
}
}
/**
* This object allows Tropo to make an outbound call. The call can be over voice or one
* of the text channels.
* @package TropoPHP_Support
*
*/
class Call extends BaseClass {
private $_to;
private $_from;
private $_network;
private $_channel;
private $_answerOnMedia;
private $_timeout;
private $_headers;
private $_recording;
/**
* Class constructor
*
* @param string $to
* @param string $from
* @param string $network
* @param string $channel
* @param boolean $answerOnMedia
* @param int $timeout
* @param array $headers
* @param StartRecording $recording
*/
public function __construct($to, $from=NULL, $network=NULL, $channel=NULL, $answerOnMedia=NULL, $timeout=NULL, Array $headers=NULL, StartRecording $recording=NULL) {
$this->_to = $to;
$this->_from = $from;
$this->_network = $network;
$this->_channel = $channel;
$this->_answerOnMedia = $answerOnMedia;
$this->_timeout = $timeout;
$this->_headers = $headers;
$this->_recording = isset($recording) ? sprintf($recording) : null ;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->to = $this->_to;
if(isset($this->_from)) { $this->from = $this->_from; }
if(isset($this->_network)) { $this->network = $this->_network; }
if(isset($this->_channel)) { $this->channel = $this->_channel; }
if(isset($this->_timeout)) { $this->timeout = $this->_timeout; }
if(isset($this->_answerOnMedia)) { $this->answerOnMedia = $this->_answerOnMedia; }
if(count($this->_headers)) { $this->headers = $this->_headers; }
if(isset($this->_recording)) { $this->recording = $this->_recording; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Defines the input to be collected from the user.
* @package TropoPHP_Support
*/
class Choices extends BaseClass {
private $_value;
private $_mode;
private $_termChar;
/**
* Class constructor
*
* @param string $value
* @param string $mode
* @param string $termChar
*/
public function __construct($value, $mode=NULL, $termChar=NULL) {
$this->_value = $value;
$this->_mode = $mode;
$this->_termChar = $termChar;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->value = $this->_value;
if(isset($this->_mode)) { $this->mode = $this->_mode; }
if(isset($this->_termChar)) { $this->terminator = $this->_termChar; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* This object allows multiple lines in separate sessions to be conferenced together so that
* the parties on each line can talk to each other simultaneously.
* This is a voice channel only feature.
*
* TODO: Conference object should support multiple event handlers (e.g. join and leave).
* @package TropoPHP_Support
*
*/
class Conference extends BaseClass {
private $_id;
private $_mute;
private $_name;
private $_on;
private $_playTones;
private $_required;
private $_terminator;
/**
* Class constructor
*
* @param int $id
* @param boolean $mute
* @param string $name
* @param On $on
* @param boolean $playTones
* @param boolean $required
* @param string $terminator
*/
public function __construct($name, $id=NULL, $mute=NULL, On $on=NULL, $playTones=NULL, $required=NULL, $terminator=NULL) {
$this->_name = $name;
$this->_id = $id;
$this->_mute = $mute;
$this->_on = isset($on) ? sprintf($on) : null;
$this->_playTones = $playTones;
$this->_required = $required;
$this->_terminator = $terminator;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->name = $this->_name;
if(isset($this->_id)) { $this->id = $this->_id; }
if(isset($this->_mute)) { $this->mute = $this->_mute; }
if(isset($this->_on)) { $this->on = $this->_on; }
if(isset($this->_playTones)) { $this->playTones = $this->_playTones; }
if(isset($this->_required)) { $this->required = $this->_required; }
if(isset($this->_terminator)) { $this->terminator = $this->_terminator; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* This function instructs Tropo to "hang-up" or disconnect the session associated with the current session.
* @package TropoPHP_Support
*
*/
class Hangup extends EmptyBaseClass { }
/**
* This function instructs Tropo to send a message.
* @package TropoPHP_Support
*
*/
class Message extends BaseClass {
private $_say;
private $_to;
private $_channel;
private $_network;
private $_from;
private $_voice;
private $_timeout;
private $_answerOnMedia;
private $_headers;
/**
* Class constructor
*
* @param Say $say
* @param string $to
* @param string $channel
* @param string $network
* @param string $from
* @param string $voice
* @param integer $timeout
* @param boolean $answerOnMedia
* @param array $headers
*/
public function __construct(Say $say, $to, $channel=null, $network=null, $from=null, $voice=null, $timeout=null, $answerOnMedia=null, Array $headers=null) {
$this->_say = isset($say) ? sprintf($say) : null ;
$this->_to = $to;
$this->_channel = $channel;
$this->_network = $network;
$this->_from = $from;
$this->_voice = $voice;
$this->_timeout = $timeout;
$this->_answerOnMedia = $answerOnMedia;
$this->_headers = $headers;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->say = $this->_say;
$this->to = $this->_to;
if(isset($this->_channel)) { $this->channel = $this->_channel; }
if(isset($this->_network)) { $this->network = $this->_network; }
if(isset($this->_from)) { $this->from = $this->_from; }
if(isset($this->_voice)) { $this->voice = $this->_voice; }
if(isset($this->_timeout)) { $this->timeout = $this->_timeout; }
if(isset($this->_answerOnMedia)) { $this->answerOnMedia = $this->_answerOnMedia; }
if(count($this->_headers)) { $this->headers = $this->_headers; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Adds an event callback so that your application may be notified when a particular event occurs.
* @package TropoPHP_Support
*
*/
class On extends BaseClass {
private $_event;
private $_next;
private $_say;
/**
* Class constructor
*
* @param string $event
* @param string $next
* @param Say $say
*/
public function __construct($event=NULL, $next=NULL, Say $say=NULL) {
$this->_event = $event;
$this->_next = $next;
$this->_say = isset($say) ? sprintf($say) : null ;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if(isset($this->_event)) { $this->event = $this->_event; }
if(isset($this->_next)) { $this->next = $this->_next; }
if(isset($this->_say)) { $this->say = $this->_say; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Plays a prompt (audio file or text to speech) and optionally waits for a response from the caller that is recorded.
* @package TropoPHP_Support
*
*/
class Record extends BaseClass {
private $_attempts;
private $_bargein;
private $_beep;