This app shows how to build a call forwarding system with voicemail using C# and Twilio.
How it works:
- Call is placed to your Twilio number
- Your app checks the time
- If the time is within the defined window, it will forward the call to another phone number
- If it is not in the defined time window, it will record a voicemail
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:
After the above requirements have been met:
- Clone this repository and
cd
into it
git clone [email protected]:twilio-samples/call-forwarding-csharp
cd call-forwarding-csharp
- Add necessary nuget packages
dotnet add package Twilio
dotnet add package Twilio.AspNet.Core
- Tweak phone number and time variables.
Necessary settings are located in the appsettings.json file in this project. Go into appsettings.json and fill in the phone number you want to forward your calls to under PhoneNumber
. You can also change DayStart
and DayEnd
variables. Times are in UTC in this demo.
- Build to install the dependencies
dotnet build
- Run the application
dotnet run
- Use ngrok or other tunneling service to expose your application to the internet
You will need to use ngrok or another tunneling service to allow Twilio to reach your running application. Use the following command, replacing the port number that's shown here with the port that your application is running on.
ngrock http http://localhost:5183
- Set your ngrok endpoint as a Webhook in the Twilio console. Remember to append /voice to the ngrok URL.
That's it!
- 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.