Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Twilio SDK v5.15 #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.DS_Store
composer.lock
.php_cs.cache
/vendor/
/vendor/
.discovery
2 changes: 0 additions & 2 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ preset: laravel

enabled:
- unalign_double_arrow

linting: true
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 7.0
- 7.1
- 7.2

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.1",
"botman/botman": "~2.0",
"twilio/sdk": "^5.15"
"twilio/sdk": "^6.3"
},
"require-dev": {
"botman/studio-addons": "~1.0",
Expand Down
8 changes: 4 additions & 4 deletions src/TwilioMessageDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BotMan\Drivers\Twilio;

use Twilio\Twiml;
use Twilio\TwiML\MessagingResponse;
use Twilio\Rest\Client as Twilio;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Outgoing\Question;
Expand Down Expand Up @@ -80,7 +80,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam
if ($message instanceof Question) {
$text = $message->getText();
$parameters['buttons'] = $message->getButtons() ?? [];
} elseif ($message instanceof Twiml) {
} elseif ($message instanceof MessagingResponse) {
$parameters['twiml'] = $message;
} elseif ($message instanceof OutgoingMessage) {
$attachment = $message->getAttachment();
Expand Down Expand Up @@ -127,8 +127,8 @@ public function sendPayload($payload)
return Response::create(json_encode($message->toArray()));
}

$response = new Twiml();
$message = $response->message();
$response = new MessagingResponse();
$message = $response->message('');

$body = $payload['text'];

Expand Down
6 changes: 3 additions & 3 deletions src/TwilioVoiceDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BotMan\Drivers\Twilio;

use Twilio\Twiml;
use Twilio\TwiML\VoiceResponse;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Drivers\Events\GenericEvent;
Expand Down Expand Up @@ -85,7 +85,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam
$text = $message->getText();
$isQuestion = true;
$parameters['buttons'] = $message->getButtons() ?? [];
} elseif ($message instanceof Twiml) {
} elseif ($message instanceof VoiceResponse) {
$parameters['twiml'] = $message;
} elseif ($message instanceof OutgoingMessage) {
$text = $message->getText();
Expand Down Expand Up @@ -120,7 +120,7 @@ public function sendPayload($payload)
$sayParameters['language'] = $payload['language'];
}

$response = new Twiml();
$response = new VoiceResponse();
if ($payload['question'] === true) {
$input = $payload['input'] ?? $this->config->get('input', TwilioSettings::INPUT_DTMF);
$gather = $response->gather(['input' => $input]);
Expand Down
13 changes: 8 additions & 5 deletions tests/TwilioMessageDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Mockery as m;
use Twilio\Rest\Client;
use Twilio\Twiml;
use Twilio\TwiML\MessagingResponse;
use BotMan\BotMan\Http\Curl;
use PHPUnit_Framework_TestCase;
use BotMan\BotMan\Messages\Attachments\Image;
Expand All @@ -23,13 +23,14 @@ private function getDriver($parameters = [], $htmlInterface = null)
$request = Request::create('', 'POST', $parameters, [], [], [
'Content-Type' => 'application/x-ww-form-urlencoded',
]);
$request->headers->set('X-Twilio-Signature', 'Lo3nfTHrzZ2sr2daOkmKFA9Ce0w=');
$request->headers->set('X-Twilio-Signature', 'WyyunabY4p/b+zeaeDiObGiGn8A=');
if ($htmlInterface === null) {
$htmlInterface = m::mock(Curl::class);
}

return new TwilioMessageDriver($request, [
'twilio' => [
'token' => '12345',
'fromNumber' => 'My-From-Number'
]
], $htmlInterface);
Expand Down Expand Up @@ -79,7 +80,7 @@ public function it_returns_the_driver_name()
/** @test */
public function it_matches_the_request()
{
$driver = $this->getDriver();
// $driver = $this->getDriver();
// $this->assertFalse($driver->matchesRequest());

$driver = $this->getValidDriver();
Expand Down Expand Up @@ -255,15 +256,17 @@ public function it_can_build_and_send_custom_twiml()
{
$driver = $this->getValidDriver();

$twiml = new Twiml();
$message = $twiml->message();
$twiml = new MessagingResponse();
$message = $twiml->message('');
$message->body('custom twiml');

$payload = $driver->buildServicePayload($twiml, new IncomingMessage('', '123', '456'), []);

/** @var Response $response */
$response = $driver->sendPayload($payload);
$expected = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL.'<Response><Message><Body>custom twiml</Body></Message></Response>'.PHP_EOL;


$this->assertSame($expected, $response->getContent());
}

Expand Down
12 changes: 8 additions & 4 deletions tests/TwilioVoiceDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Tests;

use Mockery as m;
use Twilio\Twiml;
use Twilio\TwiML\VoiceResponse;
use BotMan\BotMan\Http\Curl;
use PHPUnit_Framework_TestCase;
use BotMan\Drivers\Twilio\TwilioVoiceDriver;
Expand All @@ -21,12 +21,16 @@ private function getDriver($parameters = [], $htmlInterface = null)
$request = Request::create('', 'POST', $parameters, [], [], [
'Content-Type' => 'application/x-ww-form-urlencoded',
]);
$request->headers->set('X-Twilio-Signature', '+vqR5LqFQepeHnZIFIuq4jID2ws=');
$request->headers->set('X-Twilio-Signature', 'PHROMOUL2hHIKx89kQ1VFRXz+ko=');
if ($htmlInterface === null) {
$htmlInterface = m::mock(Curl::class);
}

return new TwilioVoiceDriver($request, [], $htmlInterface);
return new TwilioVoiceDriver($request, [
'twilio' => [
'token' => '12345'
]
], $htmlInterface);
}

private function getValidDriver($withDigits = true, $htmlInterface = null)
Expand Down Expand Up @@ -216,7 +220,7 @@ public function it_can_build_and_send_custom_twiml()
{
$driver = $this->getValidDriver();

$twiml = new Twiml();
$twiml = new VoiceResponse();
$twiml->say('custom twiml');

$payload = $driver->buildServicePayload($twiml, new IncomingMessage('', '', ''), []);
Expand Down