At the top of the file we are importing the TwilioRestClient and building a client object using our Twilio account credentials and phone numbers. Your account sid and auth token can be found in your Twilio console.

I’ve set my credentials as environment variables using the $ export command. If you decide to hard-code your credentials, do not push your source code to a public github repo as it will expose them to the world.

The message = client.messages.create(...) line uses the client object to send an outgoing SMS with the given parameters.

Save the file again, restart the app, run your curl command ( $ curl -d '' localhost:5000 ), and check your phone. You should have received a text message from your Twilio number that says “Hello, World!” If you did not receive a text or your app displays an error, double check that you copy and pasted your Twilio credentials properly.

Handling Stripe Webhooks

The next step is to configure an endpoint in our Stripe account to send data to our application.

If you want to know more about Stripe’s webhooks and how they work, check out their documentation or this blog post. Basically, webhooks allow you to send data to a specific URL whenever events involving your Stripe account occur.

But first we need to make our app publicly accessible so that it can be reached by Stripe. We are going to use ngrok to accomplish this. In a separate terminal run the following command: