Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Code Exchange Upgrade #27

Merged
merged 4 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
node_modules
.sqlite
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
AUTH_TOKEN=your_auth_token
36 changes: 36 additions & 0 deletions .github/workflows/composer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

name: Composer

on:
push:
branches: [ master, next ]
pull_request:
branches: [ master, next ]

jobs:
build:

runs-on: ${{ matrix.platform }}
strategy:
max-parallel: 3
matrix:
platform: [windows-latest, macos-latest, ubuntu-latest]

steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: mbstring, fileinfo, pdo_sqlite
coverage: none
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: |
vendor/bin/phpunit tests --stderr
env:
ACCOUNT_SID: ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
AUTH_TOKEN: your_auth_token
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
.env
bin
10 changes: 10 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pull_request_rules:
- name: automatic merge for Dependabot pull requests
conditions:
- author=dependabot-preview[bot]
- status-success=build (macos-latest)
- status-success=build (windows-latest)
- status-success=build (ubuntu-latest)
actions:
merge:
method: squash
73 changes: 73 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at open-source@twilio.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing to Twilio

All third party contributors acknowledge that any contributions they provide will be made under the same open source license that the open source project is provided under.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM php:7.4

WORKDIR /usr/src/app

RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
RUN apt-get install -y zip unzip

COPY composer* ./
RUN curl --silent --show-error https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer


COPY . .
RUN make install

EXPOSE 8000

CMD [ "php", "-S", "0.0.0.0:8000" ]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
install:
composer install

serve:
php -S localhost:8000

118 changes: 90 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,135 @@
<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 href="https://www.twilio.com">
<img src="https://static0.twilio.com/marketing/bundles/marketing/img/logos/wordmark-red.svg" alt="Twilio" width="250" />
</a>

# Send an SMS during a phone call. Powered by Twilio and PHP/Slim

![](https://github.com/TwilioDevEd/send-sms-during-inbound-calls-php/workflows/Composer/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 send an SMS to someone who's called your Twilio phone number while they're on the call.

This small sample application will say a short message to an inbound caller and, at the same time, send them an SMS.

[Read the full tutorial here!](https://www.twilio.com/docs/sms/tutorials/send-sms-during-phone-call-php)

Implementations in other languages:

| .NET | Java | Python | Ruby | Node |
| :--- | :--- | :----- | :-- | :--- |
| [Done](https://github.com/TwilioDevEd/send-sms-during-inbound-calls-csharp) | [Done](https://github.com/TwilioDevEd/send-sms-during-inbound-calls-java) | [Done](https://github.com/TwilioDevEd/send-sms-during-inbound-calls-python) | [Done](https://github.com/TwilioDevEd/send-sms-during-inbound-calls-ruby) | [Done](https://github.com/TwilioDevEd/send-sms-during-inbound-calls-node) |

## Set up

### Requirements

- [PHP >= 7.2.5](https://www.php.net/) and [composer](https://getcomposer.org/)
- A Twilio account - [sign up](https://www.twilio.com/try-twilio)

### Twilio Account Settings

## Local Development
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:

This project is built using the [Slim](https://www.slimframework.com/) web framework, PHP 7, and the [Twilio PHP Helper Library](https://www.twilio.com/docs/libraries/php).
| 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). |

1. First clone this repository and `cd` into it.
### Local development

```bash
$ git clone https://github.com/TwilioDevEd/send-sms-during-inbound-calls-php.git
$ cd send-sms-during-inbound-calls-php
```
After the above requirements have been met:

1. Install the dependencies.
1. Clone this repository and `cd` into it

```bash
$ composer install
git clone git@github.com:TwilioDevEd/send-sms-during-inbound-calls-php.git
cd send-sms-during-inbound-calls-php
```

1. Create an environment file (`.env`) and define your Twilio Account SID and Auth Token. Both of these can be found in your [Twilio console](https://www.twilio.com/console).
1. Install PHP dependencies

```bash
export ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
export AUTH_TOKEN=your_auth_token
```
```bash
make install
```

1. Load the created file into your environment.
1. Set your environment variables

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

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

1. Run the application

```bash
$ php -S localhost:8080
make serve
```

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

> [Learn 6 awesome reasons why to use ngrok](https://www.twilio.com/blog/2015/09/6-awesome-reasons-to-use-ngrok-when-testing-webhooks.html).

```bash
$ ngrok http 8080 -host-header="localhost:8080"
ngrok http 8000 -host-header="localhost:8000"
```

1. Configure Twilio to call your webhooks

You will need to configure Twilio to call your application when calls are
received in your [*Twilio Number*](https://www.twilio.com/user/account/messaging/phone-numbers).
The voice url should look something like this:
You will need to configure Twilio to call your application when calls are received in your [*Twilio Number*](https://www.twilio.com/user/account/messaging/phone-numbers). The voice url with `POST` method should look something like this:

```
https://<your-ngrok-subdomain>.ngrok.io/answer
```

That's it!

### Docker

If you have [Docker](https://www.docker.com/) already installed on your machine, you can use our `docker-compose.yml` to setup your project.

1. Make sure you have the project cloned.
2. Setup the `.env` file as outlined in the [Local Development](#local-development) steps.
3. Run `docker-compose up`.
4. Follow the steps in [Local Development](#local-development) on how to expose your port to Twilio using a tool like [ngrok](https://ngrok.com/) and configure the remaining parts of your application.

### Unit and Integration Tests

You can run the Unit and Feature tests locally by typing:
```bash
vendor/bin/phpunit tests
```

### Cloud deployment

Additionally to trying out this application locally, you can deploy it to a variety of host services. Here is a small selection of them.

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.

| Service | |
| :-------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Heroku](https://www.heroku.com/) | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) |

## Resources

- The CodeExchange repository can be found [here](https://github.com/twilio-labs/code-exchange/).

## Contributing

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).

[Visit the project on GitHub](https://github.com/twilio-labs/sample-template-nodejs)

## License

[MIT](http://www.opensource.org/licenses/mit-license.html)

## Disclaimer

## Meta
No warranty expressed or implied. Software is as is.

* No warranty expressed or implied. Software is as is. Diggity.
* [MIT License](http://www.opensource.org/licenses/mit-license.html)
* Lovingly crafted by Twilio Developer Education.
[twilio]: https://www.twilio.com
18 changes: 16 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
{
"name": "twilio-deved/send-sms-during-inbound-calls",
"require": {
"slim/slim": "^3.10",
"twilio/sdk": "^5.21"
"php": "^7.2.5",
"slim/slim": "^4.5.0",
"twilio/sdk": "^6.1.0",
"vlucas/phpdotenv": "^4.1",
"slim/psr7": "^1.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "^9.1",
"mockery/mockery": "^1.3"
},
"autoload": {
"psr-4": {
"TwilioDevEd\\": "src"
}
}
}