Skip to content

TwilioDevEd/receive-mms-laravel

Repository files navigation

Twilio

Recieve SMS and MMS Messages. Powered by Twilio - PHP/Laravel

Build Status

Use Twilio to receive SMS and MMS messages. For a step-by-step tutorial see the Twilio docs.

Note: protect your webhooks

Twilio supports HTTP Basic and Digest Authentication. Authentication allows you to password protect your TwiML URLs on your web server so that only you and Twilio can access them.

Learn more about HTTP authentication here, which includes sample code you can use to secure your web application by validating incoming Twilio requests.

Local development

First you need to install PHP and Composer.

To run the app locally:

  1. Clone this repository and cd into it

    git clone [email protected]:TwilioDevEd/receive-mms-laravel.git && \
    
    cd receive-mms-laravel
  2. Install dependencies

    composer install
  3. Copy the sample configuration file and edit it to match your configuration

    cp .env-example .env

    You can find your TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN in your Twilio Account Settings. You will also need a TWILIO_NUMBER, which you may find here.

    Run source .env to export the environment variables

  4. Generate application key

    php artisan key:generate
  5. Create database file and run migrations:

    touch ./database/database.sqlite && \
    php artisan migrate --force
  6. Run the application

    php artisan serve --port 8000
  7. Run ngrok:

    ngrok http 8000
    

Be sure to copy the ngrok http url and associate it with your Twilio Phone Number in your twilio console. The incoming SMS webhook url for your number should be as follows: https://<given-ngrok-domain>/api/incoming

  1. Check it out at http://localhost:8000

That's it

Run the tests

You can run the tests locally by typing

phpunit

Meta

  • No warranty expressed or implied. Software is as is. Diggity.
  • MIT License
  • Lovingly crafted by Twilio Developer Education.