Skip to content

Commit 957c532

Browse files
committed
adds twilio sample
1 parent a5fff75 commit 957c532

File tree

8 files changed

+1415
-0
lines changed

8 files changed

+1415
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Twilio & Google App Engine (Standard)
2+
3+
This sample application demonstrates how to use [Twilio with Google App Engine](https://cloud.google.com/appengine/docs/php/sms/twilio).
4+
5+
## Setup
6+
7+
Before running this sample:
8+
9+
1. You will need a [Twilio account](https://www.twilio.com/user/account).
10+
1. Update `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` in `index.php` to match your
11+
Twilio credentials. These can be found in your [account settings]
12+
(https://www.twilio.com/user/account/settings)
13+
1. Update `TWILIO_FROM_NUMBER` in `index.php` with a number you have authorized
14+
for sending messages. Follow [Twilio's documentation]
15+
(https://www.twilio.com/user/account/phone-numbers/getting-started) to set
16+
this up.
17+
18+
## Prerequisites
19+
20+
- Install [`composer`](https://getcomposer.org)
21+
- Install dependencies by running:
22+
23+
```sh
24+
composer install
25+
```
26+
27+
## Run locally
28+
29+
you can run locally using PHP's built-in web server:
30+
31+
```sh
32+
cd php-docs-samples/appengine/standard/twilio
33+
php -S localhost:8080
34+
```
35+
36+
Now you can view the app running at [http://localhost:8080](http://localhost:8080)
37+
in your browser.
38+
39+
## Deploy to App Engine
40+
41+
**Prerequisites**
42+
43+
- Install the [Google Cloud SDK](https://developers.google.com/cloud/sdk/).
44+
45+
**Deploy with gcloud**
46+
47+
```
48+
gcloud config set project YOUR_PROJECT_ID
49+
gcloud preview app deploy
50+
gcloud preview app browse
51+
```
52+
53+
The last command will open `https://{YOUR_PROJECT_ID}.appspot.com/`
54+
in your browser.

appengine/standard/twilio/app.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
use Silex\Application;
19+
20+
$app = new Application();
21+
22+
$app->get('/', function () use ($app) {
23+
if ($app['twilio.account_sid'] == 'TWILIO_ACCOUNT_SID') {
24+
return 'set your Twilio SID and Auth Token in <code>index.php</code>';
25+
}
26+
$sid = $app['twilio.account_sid'];
27+
$token = $app['twilio.auth_token'];
28+
$fromNumber = $app['twilio.from_number'];
29+
$toNumber = $app['twilio.to_number'];
30+
31+
# [START send_sms]
32+
$client = new Services_Twilio($sid, $token);
33+
$sms = $client->account->messages->sendMessage(
34+
$fromNumber, // From this number
35+
$toNumber, // Send to this number
36+
'Hello monkey!!'
37+
);
38+
39+
return sprintf('Message ID: %s, Message Body: %s', $sms->sid, $sms->body);
40+
# [END send_sms]
41+
});
42+
43+
$app->get('/twiml', function () {
44+
# [START twiml]
45+
$response = new Services_Twilio_Twiml();
46+
$response->say('Hello Monkey');
47+
48+
return (string) $response;
49+
# [END twiml]
50+
});
51+
52+
return $app;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"require": {
3+
"twilio/sdk": "^4.10",
4+
"silex/silex": "^1.3"
5+
},
6+
"require-dev": {
7+
"symfony/browser-kit": "^3.0",
8+
"satooshi/php-coveralls": "^1.0"
9+
}
10+
}

0 commit comments

Comments
 (0)