Skip to content

Commit 23c6323

Browse files
committed
Added Reply to Inbound Message:
- Creates Text Message - TODO: Support other types of replies.
1 parent 6a85d46 commit 23c6323

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Message/InboundMessage.php

+11
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ public static function createFromGlobals()
4747
return new self($serverRequest);
4848
}
4949

50+
/**
51+
* Create a matching reply to the inbound message. Currently only supports text replies.
52+
*
53+
* @param string $body
54+
* @return Text
55+
*/
56+
public function createReply($body)
57+
{
58+
return new Text($this->getFrom(), $this->getTo(), $body);
59+
}
60+
5061
public function getRequestData($sent = true)
5162
{
5263
$request = $this->getRequest();

test/Message/InboundMessageTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ public function testResponseArrayAccess($response)
109109
$this->assertEquals('US-VIRTUAL-BANDWIDTH', $message['network']);
110110
}
111111

112+
public function testCanCreateReply()
113+
{
114+
$message = new InboundMessage($this->getServerRequest());
115+
116+
$reply = $message->createReply('this is a reply');
117+
$this->assertInstanceOf('Nexmo\Message\Message', $reply);
118+
119+
$params = $reply->getRequestData(false);
120+
121+
$this->assertEquals('14845552121', $params['to']);
122+
$this->assertEquals('16105553939', $params['from']);
123+
$this->assertEquals('this is a reply', $params['text']);
124+
}
125+
112126
public function getResponses()
113127
{
114128
return [

0 commit comments

Comments
 (0)