From def479323a0cd4b37d6ebd11f3656076ec3e2de3 Mon Sep 17 00:00:00 2001 From: Brandon Jank Date: Thu, 9 Nov 2017 13:32:23 -0800 Subject: [PATCH] add test incoming/outgoing nexmo sms routes --- .env.example | 1 + app/Http/Middleware/VerifyCsrfToken.php | 2 +- composer.json | 1 + config/nexmo.php | 31 +++++++++++++++++++++++++ routes/web.php | 18 ++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 config/nexmo.php diff --git a/.env.example b/.env.example index cd8c266..9b9e818 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,7 @@ APP_ENV=local APP_KEY= APP_DEBUG=true APP_LOG_LEVEL=debug +DEBUGBAR_ENABLED=true APP_URL=http://localhost:8000/ API_CHALLENGE=change_me diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php index a2c3541..dfa5f59 100644 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ b/app/Http/Middleware/VerifyCsrfToken.php @@ -12,6 +12,6 @@ class VerifyCsrfToken extends BaseVerifier * @var array */ protected $except = [ - // + '/sms/receive' ]; } diff --git a/composer.json b/composer.json index 4849f16..776ad26 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "maatwebsite/excel": "^2.1", "nesbot/carbon": "^1.22", "nexmo/client": "^1.0", + "nexmo/laravel": "^1.0", "predis/predis": "^1.1", "spatie/laravel-activitylog": "^2.1", "yajra/laravel-datatables-buttons": "3.*", diff --git a/config/nexmo.php b/config/nexmo.php new file mode 100644 index 0000000..e43bac1 --- /dev/null +++ b/config/nexmo.php @@ -0,0 +1,31 @@ + function_exists('env') ? env('NEXMO_KEY', '') : '', + 'api_secret' => function_exists('env') ? env('NEXMO_SECRET', '') : '', + + /* + |-------------------------------------------------------------------------- + | Signature Secret + |-------------------------------------------------------------------------- + | + | If you're using a signature secret, use this section. This can be used + | without an `api_secret` for some APIs, as well as with an `api_secret` + | for all APIs. + | + */ + + 'signature_secret' => function_exists('env') ? env('NEXMO_SIGNATURE_SECRET', '') : '', + +]; diff --git a/routes/web.php b/routes/web.php index cdab77b..df1b180 100644 --- a/routes/web.php +++ b/routes/web.php @@ -91,3 +91,21 @@ * Site Controller * *-----------------------*/ Route::resource('site', 'SiteController'); + +/*-----------------------* + * SMS Controller * + *-----------------------*/ +Route::get('/sms/send/{to}', function(\Nexmo\Client $nexmo, $to){ + $message = $nexmo->message()->send([ + 'to' => $to, + 'from' => env('NEXMO_FROM'), + 'text' => 'This is a test sms message from SmartSettia.' + ]); + Log::info('sent message: ' . $message['message-id']); +}); +Route::post('/sms/receive', function(\Nexmo\Client $nexmo){ + $message = \Nexmo\Message\InboundMessage::createFromGlobals(); + Log::info('got text: ' . $message->getBody()); + $reply =$nexmo->message()->send($message->createReply('This is for SmartSettia notifications only. Please contact admin@smartsettia.com for assistance.')); + Log::info('sent reply: ' . $reply['message-id']); +}); \ No newline at end of file