diff --git a/.gitignore b/.gitignore index fb0edf3..edb6da1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .DS_Store composer.lock .php_cs.cache -/vendor/ \ No newline at end of file +/vendor/ +.discovery diff --git a/.styleci.yml b/.styleci.yml index a2f2088..1ef9935 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -2,5 +2,3 @@ preset: laravel enabled: - unalign_double_arrow - -linting: true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index aeb9686..78cdaad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 7.0 - 7.1 - 7.2 diff --git a/composer.json b/composer.json index 5d97a70..8277c3d 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/TwilioMessageDriver.php b/src/TwilioMessageDriver.php index 69c6ea6..c69b856 100644 --- a/src/TwilioMessageDriver.php +++ b/src/TwilioMessageDriver.php @@ -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; @@ -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(); @@ -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']; diff --git a/src/TwilioVoiceDriver.php b/src/TwilioVoiceDriver.php index 21adaaa..54cbaae 100644 --- a/src/TwilioVoiceDriver.php +++ b/src/TwilioVoiceDriver.php @@ -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; @@ -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(); @@ -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]); diff --git a/tests/TwilioMessageDriverTest.php b/tests/TwilioMessageDriverTest.php index eceb5e9..6e0a0d7 100644 --- a/tests/TwilioMessageDriverTest.php +++ b/tests/TwilioMessageDriverTest.php @@ -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; @@ -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); @@ -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(); @@ -255,8 +256,8 @@ 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'), []); @@ -264,6 +265,8 @@ public function it_can_build_and_send_custom_twiml() /** @var Response $response */ $response = $driver->sendPayload($payload); $expected = ''.PHP_EOL.'custom twiml'.PHP_EOL; + + $this->assertSame($expected, $response->getContent()); } diff --git a/tests/TwilioVoiceDriverTest.php b/tests/TwilioVoiceDriverTest.php index 6de1bd9..2b33dc7 100644 --- a/tests/TwilioVoiceDriverTest.php +++ b/tests/TwilioVoiceDriverTest.php @@ -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; @@ -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) @@ -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('', '', ''), []);