Skip to content

Commit 7e4cd35

Browse files
feat(hackathon): Add Twilio API functionality , 8 down, 12 to go
1 parent 10494f7 commit 7e4cd35

File tree

7 files changed

+274
-3
lines changed

7 files changed

+274
-3
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
use Twilio;
8+
use App\Http\Requests;
9+
use App\Http\Controllers\Controller;
10+
11+
class TwilioController extends Controller
12+
{
13+
/**
14+
* Return all data to the Stripe API dashboard
15+
* @return mixed
16+
*/
17+
public function getPage()
18+
{
19+
return view('api.twilio');
20+
}
21+
22+
/**
23+
* Send a Text Message
24+
* @param Request $request
25+
* @return string
26+
*/
27+
public function sendTextMessage(Request $request)
28+
{
29+
$this->validate($request, [
30+
'message' => 'required',
31+
'number' => 'required'
32+
]);
33+
34+
$number = $request->input('number');
35+
$message = $request->input('message') . ' #LaravelHackathonStarter';
36+
37+
Twilio::message($number, $message);
38+
39+
return redirect()->back()->with('info','Your Message has been sent successfully');
40+
}
41+
}

app/Http/routes.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@
7575
'middleware' => ['auth']
7676
]);
7777

78+
Route::get('/api/twilio', [
79+
'uses' => 'TwilioController@getPage',
80+
'as' => 'api.twilio',
81+
'middleware' => ['auth']
82+
]);
83+
84+
Route::post('/api/twilio', [
85+
'uses' => 'TwilioController@sendTextMessage',
86+
'middleware' => ['auth']
87+
]);
88+
7889
Route::post('/tweet/new', [
7990
'uses' => 'TwitterController@sendTweet',
8091
'as' => 'tweet.new',

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"jrm2k6/cloudder": "^0.2.2",
1414
"graham-campbell/github": "^4.2",
1515
"thujohn/twitter": "^2.1",
16-
"metalmatze/lastfm-api-wrapper": "dev-master"
16+
"metalmatze/lastfm-api-wrapper": "dev-master",
17+
"aloha/twilio": "^2.0"
1718
},
1819
"require-dev": {
1920
"fzaninotto/faker": "~1.4",

composer.lock

Lines changed: 106 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/app.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
JD\Cloudder\CloudderServiceProvider::class,
153153
GrahamCampbell\GitHub\GitHubServiceProvider::class,
154154
Thujohn\Twitter\TwitterServiceProvider::class,
155+
Aloha\Twilio\Support\Laravel\ServiceProvider::class,
155156

156157
/*
157158
* Application Service Providers...
@@ -210,6 +211,7 @@
210211
'Cloudder' => JD\Cloudder\Facades\Cloudder::class,
211212
'GitHub' => GrahamCampbell\GitHub\Facades\GitHub::class,
212213
'Twitter' => Thujohn\Twitter\Facades\Twitter::class,
214+
'Twilio' => Aloha\Twilio\Support\Laravel\Facade::class,
213215

214216
],
215217

config/twilio.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
return [
4+
5+
'twilio' => [
6+
7+
'default' => 'twilio',
8+
9+
'connections' => [
10+
11+
'twilio' => [
12+
13+
/*
14+
|--------------------------------------------------------------------------
15+
| SID
16+
|--------------------------------------------------------------------------
17+
|
18+
| Your Twilio Account SID #
19+
|
20+
*/
21+
22+
'sid' => env('TWILIO_SID'),
23+
24+
/*
25+
|--------------------------------------------------------------------------
26+
| Access Token
27+
|--------------------------------------------------------------------------
28+
|
29+
| Access token that can be found in your Twilio dashboard
30+
|
31+
*/
32+
33+
'token' => env('TWILIO_TOKEN'),
34+
35+
/*
36+
|--------------------------------------------------------------------------
37+
| From Number
38+
|--------------------------------------------------------------------------
39+
|
40+
| The Phone number registered with Twilio that your SMS & Calls will come from
41+
|
42+
*/
43+
44+
'from' => env('TWILIO_FROM'),
45+
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Verify Twilio's SSL Certificates
49+
|--------------------------------------------------------------------------
50+
|
51+
| Allows the client to bypass verifiying Twilio's SSL certificates.
52+
| It is STRONGLY advised to leave this set to true for production environments.
53+
|
54+
*/
55+
56+
'ssl_verify' => true,
57+
58+
],
59+
],
60+
],
61+
];

resources/views/api/twilio.blade.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@extends('layouts.master')
2+
3+
@section('content')
4+
<div class="main-container">
5+
@include('layouts.partials.alerts')
6+
7+
<div class="page-header">
8+
<h2><i style="color: #f00" class="fa fa-phone"></i>Twilio API</h2>
9+
</div>
10+
11+
<div class="btn-group btn-group-justified">
12+
<a href="https://github.com/aloha/laravel-twilio" target="_blank" class="btn btn-primary">
13+
<i class="fa fa-check-square-o"></i> Laravel Twilio
14+
</a>
15+
<a href="https://apigee.com/console/twilio" target="_blank" class="btn btn-primary">
16+
<i class="fa fa-laptop"></i> API Console
17+
</a>
18+
<a href="https://www.twilio.com/docs/api/rest" target="_blank" class="btn btn-primary">
19+
<i class="fa fa-code-fork"></i> REST API
20+
</a>
21+
</div>
22+
23+
<br>
24+
25+
<div class="row">
26+
<div class="col-sm-6">
27+
<form role="form" method="POST" action="{{ route('api.twilio') }}">
28+
{!! csrf_field() !!}
29+
<div class="form-group{{ $errors->has('number') ? ' has-error' : '' }}">
30+
<label class="control-label">Number to text</label>
31+
<input type="text" name="number" autofocus="" class="form-control">
32+
@if ($errors->has('number'))
33+
<span class="help-block">{{ $errors->first('number') }}</span>
34+
@endif
35+
</div>
36+
<div class="form-group{{ $errors->has('message') ? ' has-error' : '' }}">
37+
<label class="control-label">Message</label>
38+
<input type="text" name="message" class="form-control">
39+
@if ($errors->has('message'))
40+
<span class="help-block">{{ $errors->first('message') }}</span>
41+
@endif
42+
</div>
43+
<button type="submit" class="btn btn-default">
44+
<i class="fa fa-location-arrow"></i> Send
45+
</button>
46+
</form>
47+
</div>
48+
</div>
49+
50+
</div>
51+
@stop

0 commit comments

Comments
 (0)