Skip to content

Commit acc3ec3

Browse files
committed
WIP - TTS Callback support
1 parent 4909cc6 commit acc3ec3

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* @author Tim Lytle <tim@timlytle.net>
4+
*/
5+
6+
namespace Nexmo\Voice\Message;
7+
use Nexmo\Client\Callback\CallbackInterface;
8+
use Nexmo\Client\Callback\Callback as BaseCallback;
9+
10+
class Callback extends BaseCallback implements CallbackInterface
11+
{
12+
const TIME_FORMAT = 'Y-m-d H:i:s';
13+
14+
protected $expected = array(
15+
'call-id',
16+
'status',
17+
'call-price',
18+
'call-rate',
19+
'call-duration',
20+
'to',
21+
'call-request',
22+
'network-code',
23+
'call-start',
24+
'call-end'
25+
);
26+
27+
public function getId()
28+
{
29+
return $this->data['call-id'];
30+
}
31+
32+
public function getTo()
33+
{
34+
return $this->data['to'];
35+
}
36+
37+
public function getStatus()
38+
{
39+
return $this->data['status'];
40+
}
41+
42+
public function getPrice()
43+
{
44+
return $this->data['call-price'];
45+
}
46+
47+
public function getRate()
48+
{
49+
return $this->data['call-rate'];
50+
}
51+
52+
public function getDuration()
53+
{
54+
return $this->data['call-duration'];
55+
}
56+
57+
public function getCreated()
58+
{
59+
\DateTime::createFromFormat(self::TIME_FORMAT, $this->data['call-request']);
60+
}
61+
62+
public function getStart()
63+
{
64+
\DateTime::createFromFormat(self::TIME_FORMAT, $this->data['call-start']);
65+
}
66+
67+
public function getEnd()
68+
{
69+
\DateTime::createFromFormat(self::TIME_FORMAT, $this->data['call-end']);
70+
}
71+
72+
public function getNetwork()
73+
{
74+
return $this->data['network-code'];
75+
}
76+
77+
}

src/Nexmo/Voice/Message/Message.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,38 @@ public function __construct($text, $to, $from = null)
2121
public function setLanguage($lang)
2222
{
2323
$this->params['lg'] = $lang;
24+
return $this;
2425
}
2526

2627
public function setVoice($voice)
2728
{
2829
$this->params['voice'] = $voice;
30+
return $this;
2931
}
3032

3133
public function setRepeat($count)
3234
{
3335
$this->params['repeat'] = (int) $count;
36+
return $this;
37+
}
38+
public function setCallback($url, $method = null)
39+
{
40+
$this->params['callback'] = $url;
41+
if(!is_null($method)){
42+
$this->params['callback_method'] = $method;
43+
}
44+
45+
return $this;
46+
}
47+
48+
public function setMachineDetection($hangup = true, $timeout = null)
49+
{
50+
$this->params['machine_detection'] = ($hangup ? 'hangup' : 'true');
51+
if(!is_null($timeout)){
52+
$this->params['machine_timeout'] = (int) $timeout;
53+
}
54+
55+
return $this;
3456
}
3557

3658
/**
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* @author Tim Lytle <tim@timlytle.net>
4+
*/
5+
6+
namespace Nexmo\Voice\Message;
7+
8+
class MessageTest extends PHPUnit_Framework_TestCase
9+
{
10+
protected $message;
11+
12+
protected $text = 'TTS Text';
13+
protected $to = '15553331212';
14+
protected $from = '15554441212';
15+
16+
public function setUp()
17+
{
18+
$this->message = new Message($this->text, $this->to, $this->from);
19+
}
20+
21+
}
22+

0 commit comments

Comments
 (0)