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 and we'll try to help you.
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.
Implementations in other languages:
Python | Java | Node | PHP | Ruby |
---|---|---|---|---|
Done | Done | Done | Done | TBD |
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:
Config Value | Description |
---|---|
Account Sid | Your primary Twilio account identifier - find this in the Console. |
Auth Token | Used to authenticate - just like the above, you'll find this here. |
Phone number | A Twilio phone number in E.164 format - you can get one here |
After the above requirements have been met:
- Clone this repository and
cd
into it
git clone [email protected]:TwilioDevEd/airtng-csharp-dotnet-core.git
cd airtng-csharp-dotnet-core
- Build to install the dependencies
dotnet build
- Set your environment variables
cp AirTNG.Web/twilio.json.example AirTNG.Web/twilio.json
See Twilio Account Settings to locate the necessary environment variables.
- Install EF Core CLI if it's not already installed.
dotnet tool install --global dotnet-ef --version 3.0.0
- Create the local DB. This also should be executed in
AirTNG.Web
directory.
dotnet ef database update
- Run the application
dotnet run --project AirTNG.Web
-
Navigate to http://localhost:5000
-
To let our Twilio phone number use the callback endpoint we exposed, our development server will need to be publicly accessible. You could expose the application to the wider Internet using ngrok. Here, there is an interesting article about why we recommend you to use ngrok.
ngrok http 5000
Keep in mind that our endpoint is:
https://<your-ngrok-subdomain>.ngrok.io/Sms/Handle
-
Register your webhook with your Twilio Number at
https://www.twilio.com/console/phone-numbers/
. Your webhook url should include the ngrok host from the previous step and should look similar tohttps://<your-ngrok-subdomain>.ngrok.io/Sms/Handle
.
That's it!
If you have Docker already installed on your machine, you can use our docker-compose.yml
to setup your project.
- Make sure you have the project cloned.
- Setup the
twilio.json
file as outlined in the Local Development steps. - Run
docker-compose up
. - Follow the steps in Local Development on how to expose your port to Twilio using a tool like ngrok and configure the remaining parts of your application.
You can run the tests locally by typing:
dotnet test
- The CodeExchange repository can be found here.
This template is open source and welcomes contributions. All contributions are subject to our Code of Conduct.
No warranty expressed or implied. Software is as is.