Skip to content

Commit

Permalink
Add Makefile and update readme template
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Villavicencio committed May 14, 2020
1 parent 4c1fd75 commit bbf1fd7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
branches: [ master, next ]

jobs:
build:
Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
UNAME := $(shell uname)
install:
mkdir -p database
touch database/database.sqlite
touch database/database-test.sqlite
composer install
php artisan key:generate --force
php artisan migrate --force
php artisan db:seed --force

serve-setup:
php artisan serve --host=127.0.0.1
open-browser:
python3 -m webbrowser "http://127.0.0.1:8000";
serve: open-browser serve-setup

test:
php artisan migrate --database=testing --force
vendor/bin/phpunit
172 changes: 79 additions & 93 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,159 +1,145 @@
<a href="https://www.twilio.com">
<img src="https://static0.twilio.com/marketing/bundles/marketing/img/logos/wordmark-red.svg" alt="Twilio" width="250" />
</a>

# Airtng App: Part 1 - Workflow Automation with Twilio - Laravel

![](https://github.com/TwilioDevEd/airtng-laravel/workflows/Laravel/badge.svg)


> We are currently in the process of updating this sample template. If you are encountering any issues with the sample, please open an issue at [github.com/twilio-labs/code-exchange/issues](https://github.com/twilio-labs/code-exchange/issues) and we'll try to help you.
## About

Learn how to automate your workflow using Twilio's REST API and Twilio SMS. This example app is a vacation rental site where the host can confirm a reservation via SMS.

[Read the full tutorial here](https://www.twilio.com/docs/tutorials/walkthrough/workflow-automation/php/laravel)!

## Run the application
Implementations in other languages:

1. Clone the repository and `cd` into it.
| .NET | Java | Python | Ruby | Node |
| :--- | :--- | :----- | :-- | :--- |
| [Done](https://github.com/TwilioDevEd/airtng-csharp-dotnet-core) | [Done](https://github.com/TwilioDevEd/airtng-servlets) | [Done](https://github.com/TwilioDevEd/airtng-flask) | TBD | [Done](https://github.com/TwilioDevEd/airtng-node) |

1. Install the application's dependencies with [Composer](https://getcomposer.org/)
## Set up

```bash
$ composer install
```
1. The application uses [sqlite3](https://www.sqlite.org/) as the persistence layer. If you
don't have it already, you should install it.
### Requirements

1. Create an empty database file.
- [PHP >= 7.2.5](https://www.php.net/) and [composer](https://getcomposer.org/)
- A Twilio account - [sign up](https://www.twilio.com/try-twilio)
- The application uses [sqlite3](https://www.sqlite.org/) as the persistence layer. If you don't have it already, you should install it.

```bash
$ touch database/database.sqlite
```
### Twilio Account Settings

1. Copy the sample configuration file and edit it to match your configuration.
This application should give you a ready-made starting point for writing your own application.
Before we begin, we need to collect all the config values we need to run the application:

```bash
$ cp .env.example .env
```
| Config&nbsp;Value | Description |
| :---------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Account&nbsp;Sid | Your primary Twilio account identifier - find this [in the Console](https://www.twilio.com/console). |
| Auth&nbsp;Token | Used to authenticate - [just like the above, you'll find this here](https://www.twilio.com/console). |
| Phone&nbsp;number | A Twilio phone number in [E.164 format](https://en.wikipedia.org/wiki/E.164) - you can [get one here](https://www.twilio.com/console/phone-numbers/incoming) |

You can find your `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` under
your
[Twilio Account Settings](https://www.twilio.com/user/account/settings).
You can buy a Twilio phone number here [Twilio numbers](https://www.twilio.com/user/account/phone-numbers/search)
`TWILIO_NUMBER` should be set according to the phone number you purchased above.
### Local development

1. Generate an `APP_KEY`.
After the above requirements have been met:

```bash
$ php artisan key:generate
```
1. Clone this repository and `cd` into it

1. Run the migrations.
```bash
git clone [email protected]:TwilioDevEd/airtng-laravel.git
cd airtng-laravel
```

```bash
$ php artisan migrate
```
1. Install PHP dependencies

1. Load the seed data.
```bash
make install
```

```bash
$ php artisan db:seed
```
1. Set your environment variables

```bash
cp .env.example .env
```

See [Twilio Account Settings](#twilio-account-settings) to locate the necessary environment variables.

1. Expose the application to the wider Internet using [ngrok](https://ngrok.com/)

```bash
$ ngrok http 8000
```
Once you have started ngrok, update your Twilio number sms URL
settings to use your ngrok hostname. It will look something like
this:

Once you have started ngrok, update your Twilio number sms URL settings to use your ngrok hostname. It will look something like this:

```
http://<your-ngrok-subdomain>.ngrok.io/reservation/incoming
```

1. Configure Twilio to call your webhooks.
6. Configure Twilio to call your webhooks.

You will also need to configure Twilio to send requests to your application
when sms are received.
You will also need to configure Twilio to send requests to your application when sms are received.

You will need to provision at least one Twilio number with sms capabilities
so the application's users can make property reservations. You can buy a number [right
here](https://www.twilio.com/user/account/phone-numbers/search). Once you have
a number you need to configure it to work with your application. Open
[the number management page](https://www.twilio.com/user/account/phone-numbers/incoming)
and open a number's configuration by clicking on it.
You will need to provision at least one Twilio number with sms capabilities so the application's users can make property reservations. You can buy a number [right here](https://www.twilio.com/user/account/phone-numbers/search). Once you have a number you need to configure it to work with your application. Open [the number management page](https://www.twilio.com/user/account/phone-numbers/incoming) and open a number's configuration by clicking on it.

Remember that the number where you change the sms webhooks must be the same one you set on
the `TWILIO_NUMBER` environment variable.
Remember that the number where you change the sms webhooks must be the same one you set on the `TWILIO_NUMBER` environment variable.

![Configure Messaging](webhook.png)

For this application, you must set the voice webhook of your number so that it
looks something like this:
For this application, you must set the voice webhook of your number so that it looks something like this:

```
http://<your-ngrok-subdomain>.ngrok.io/reservation/incoming
```

And in this case set the `POST` method on the configuration for this webhook.

1. Run the application using Artisan.
1. Run the application

```bash
$ php artisan serve
```
```bash
make serve
```

It is `artisan serve` default behaviour to use `http://localhost:8000` when
the application is run. This means that the ip addresses where your app will be
reachable on you local machine will vary depending on the operating system.
1. Navigate to [http://localhost:8000](http://localhost:8000)

The most common scenario is that your app will be reachable through address
`http://127.0.0.1:8000`. This is important because ngrok creates the
tunnel using only that address. So, if `http://127.0.0.1:8000` is not reachable
in your local machine when you run the app, you must tell artisan to use this
address. Here's how to set that up:
That's it!
```bash
$ php artisan serve --host=127.0.0.1
```
### Unit and Integration Tests
## Dependencies
First, run the migrations for the testing database.
```bash
php artisan migrate --database=testing
```
This application uses this Twilio helper library:
* [twilio-php](https://github.com/twilio/twilio-php)
You can run the Unit tests locally by typing:
```bash
vendor/bin/phpunit
```
## Run the tests
### Cloud deployment
1. Create an empty database file.
Additionally to trying out this application locally, you can deploy it to a variety of host services. Here is a small selection of them.
```bash
$ touch database/database-test.sqlite
```
Please be aware that some of these might charge you for the usage or might make the source code for this application visible to the public. When in doubt research the respective hosting service first.
1. Run the migrations.
| Service | |
| :-------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Heroku](https://www.heroku.com/) | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) |
```bash
$ php artisan migrate --database=testing
```
## Resources
1. Run at the top-level directory.
- The CodeExchange repository can be found [here](https://github.com/twilio-labs/code-exchange/).
```bash
$ phpunit
```
## Contributing
or
This template is open source and welcomes contributions. All contributions are subject to our [Code of Conduct](https://github.com/twilio-labs/.github/blob/master/CODE_OF_CONDUCT.md).
```bash
$ vendor/bin/phpunit
```
## License
[MIT](http://www.opensource.org/licenses/mit-license.html)
If you don't have phpunit installed on your system, you can follow [these
instructions](https://phpunit.de/manual/current/en/installation.html) to
install it.
## Disclaimer
## Meta
No warranty expressed or implied. Software is as is.
* No warranty expressed or implied. Software is as is. Diggity.
* The CodeExchange repository can be found [here](https://github.com/twilio-labs/code-exchange/).
* [MIT License](http://www.opensource.org/licenses/mit-license.html)
* Lovingly crafted by Twilio Developer Education.
[twilio]: https://www.twilio.com

0 comments on commit bbf1fd7

Please sign in to comment.