Skip to content

Commit

Permalink
Merge pull request #1 from botman/analysis-XlEWxJ
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
mpociot authored Nov 2, 2017
2 parents 132850d + bcf46e8 commit d69c4d8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/TwilioDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

abstract class TwilioDriver extends HttpDriver
{

/** @var array */
protected $messages = [];

Expand Down Expand Up @@ -48,6 +47,7 @@ public function getUser(IncomingMessage $matchingMessage)
protected function isSignatureValid()
{
$validator = new RequestValidator($this->config->get('token'));

return $validator->validate($this->signature, $this->requestUri, $this->payload);
}

Expand Down Expand Up @@ -79,4 +79,4 @@ public function sendRequest($endpoint, array $parameters, IncomingMessage $match
{
//
}
}
}
13 changes: 5 additions & 8 deletions src/TwilioMessageDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace BotMan\Drivers\Twilio;

use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Attachments\Location;
use Twilio\Twiml;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Drivers\Events\GenericEvent;
use Symfony\Component\HttpFoundation\Response;
use BotMan\BotMan\Messages\Attachments\Location;
use BotMan\BotMan\Interfaces\DriverEventInterface;
use BotMan\BotMan\Messages\Incoming\IncomingMessage;
use BotMan\BotMan\Messages\Outgoing\OutgoingMessage;
Expand Down Expand Up @@ -47,7 +45,6 @@ public function getConversationAnswer(IncomingMessage $message)
public function getMessages()
{
if (empty($this->messages)) {

$message = new IncomingMessage($this->event->get('Body'), $this->event->get('MessageSid'), $this->event->get('To'));

$this->messages = [$message];
Expand Down Expand Up @@ -85,7 +82,7 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam
} elseif ($message instanceof OutgoingMessage) {
$attachment = $message->getAttachment();
$text = $message->getText();
if ($attachment instanceof Location === false && !is_null($attachment)) {
if ($attachment instanceof Location === false && ! is_null($attachment)) {
$parameters['media'] = $attachment->getUrl();
}
} else {
Expand All @@ -104,22 +101,22 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam
public function sendPayload($payload)
{
if (isset($payload['twiml'])) {
return Response::create((string)$payload['twiml'])->send();
return Response::create((string) $payload['twiml'])->send();
}

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

$body = $payload['text'];

foreach ((array)$payload['buttons'] as $button) {
foreach ((array) $payload['buttons'] as $button) {
$body .= "\n".$button['text'];
}
$message->body($body);
if (isset($payload['media'])) {
$message->media($payload['media']);
}

return Response::create((string)$response)->send();
return Response::create((string) $response)->send();
}
}
2 changes: 1 addition & 1 deletion src/TwilioSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class TwilioSettings
const INPUT_DTMF = 'dtmf';
const INPUT_SPEECH = 'speech';
const INPUT_DTMF_SPEECH = 'dtmf speech';
}
}
9 changes: 4 additions & 5 deletions src/TwilioVoiceDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function getConversationAnswer(IncomingMessage $message)
public function getMessages()
{
if (empty($this->messages)) {

$message = new IncomingMessage($this->event->get('Digits'), $this->event->get('CallSid'), $this->event->get('To'));

$this->messages = [$message];
Expand Down Expand Up @@ -107,12 +106,12 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam
public function sendPayload($payload)
{
if (isset($payload['twiml'])) {
return Response::create((string)$payload['twiml'])->send();
return Response::create((string) $payload['twiml'])->send();
}

$sayParameters = [
'voice' => $this->config->get('voice'),
'language' => $this->config->get('language')
'language' => $this->config->get('language'),
];
if (isset($payload['voice'])) {
$sayParameters['voice'] = $payload['voice'];
Expand All @@ -126,13 +125,13 @@ public function sendPayload($payload)
$input = $payload['input'] ?? TwilioSettings::INPUT_DTMF;
$gather = $response->gather(['input' => $input]);
$gather->say($payload['text'], $sayParameters);
foreach ((array)$payload['buttons'] as $button) {
foreach ((array) $payload['buttons'] as $button) {
$gather->say($button['text'], $sayParameters);
}
} else {
$response->say($payload['text'], $sayParameters);
}

return Response::create((string)$response)->send();
return Response::create((string) $response)->send();
}
}
2 changes: 1 addition & 1 deletion stubs/twilio.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
| See: https://www.twilio.com/docs/api/twiml/gather#attributes-input
|
*/
'input' => \BotMan\Drivers\Twilio\TwilioSettings::INPUT_DTMF
'input' => \BotMan\Drivers\Twilio\TwilioSettings::INPUT_DTMF,
];
7 changes: 4 additions & 3 deletions tests/TwilioMessageDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Outgoing\Question;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use BotMan\Drivers\Twilio\TwilioMessageDriver;
use Symfony\Component\HttpFoundation\Response;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use BotMan\BotMan\Messages\Incoming\IncomingMessage;
use BotMan\BotMan\Messages\Outgoing\OutgoingMessage;
Expand All @@ -20,7 +20,7 @@ class TwilioMessageDriverTest extends PHPUnit_Framework_TestCase
private function getDriver($parameters = [], $htmlInterface = null)
{
$request = Request::create('', 'POST', $parameters, [], [], [
'Content-Type' => 'application/x-ww-form-urlencoded'
'Content-Type' => 'application/x-ww-form-urlencoded',
]);
$request->headers->set('X-Twilio-Signature', 'Lo3nfTHrzZ2sr2daOkmKFA9Ce0w=');
if ($htmlInterface === null) {
Expand Down Expand Up @@ -60,6 +60,7 @@ private function getValidDriver($htmlInterface = null)
'Direction' => 'inbound',
'ApiVersion' => '2010-04-01',
];

return $this->getDriver($parameters, $htmlInterface);
}

Expand Down Expand Up @@ -223,7 +224,7 @@ public function it_can_send_questions()

$question = Question::create('This is a question')->addButtons([
Button::create('Button 1')->value('1'),
Button::create('Button 2')->value('2')
Button::create('Button 2')->value('2'),
]);

$payload = $driver->buildServicePayload($question, new IncomingMessage('', '', ''), []);
Expand Down
9 changes: 5 additions & 4 deletions tests/TwilioVoiceDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use Twilio\Twiml;
use BotMan\BotMan\Http\Curl;
use PHPUnit_Framework_TestCase;
use BotMan\Drivers\Twilio\TwilioVoiceDriver;
use BotMan\BotMan\Messages\Outgoing\Question;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use BotMan\Drivers\Twilio\TwilioVoiceDriver;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use BotMan\BotMan\Messages\Incoming\IncomingMessage;
use BotMan\BotMan\Messages\Outgoing\OutgoingMessage;
Expand All @@ -19,7 +19,7 @@ class TwilioVoiceDriverTest extends PHPUnit_Framework_TestCase
private function getDriver($parameters = [], $htmlInterface = null)
{
$request = Request::create('', 'POST', $parameters, [], [], [
'Content-Type' => 'application/x-ww-form-urlencoded'
'Content-Type' => 'application/x-ww-form-urlencoded',
]);
$request->headers->set('X-Twilio-Signature', '+vqR5LqFQepeHnZIFIuq4jID2ws=');
if ($htmlInterface === null) {
Expand Down Expand Up @@ -61,6 +61,7 @@ private function getValidDriver($withDigits = true, $htmlInterface = null)
if ($withDigits === true) {
$parameters['Digits'] = '1';
}

return $this->getDriver($parameters, $htmlInterface);
}

Expand Down Expand Up @@ -188,7 +189,7 @@ public function it_can_send_payload()

$payload = [
'text' => 'string',
'question' => false
'question' => false,
];

/** @var Response $response */
Expand Down Expand Up @@ -233,7 +234,7 @@ public function it_can_send_questions()

$question = Question::create('This is a question')->addButtons([
Button::create('Button 1')->value('1'),
Button::create('Button 2')->value('2')
Button::create('Button 2')->value('2'),
]);

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

0 comments on commit d69c4d8

Please sign in to comment.