This ASP.NET application demonstrates the integration of Twilio for handling voice calls. The application includes controllers for managing calls, a homepage, and generating Twilio access tokens.
-
CallController.cs
- Handles Twilio calls and connections.
- Includes a method to connect to a specified phone number or a predefined support agent.
-
HomeController.cs
- The default controller managing the main views of the application.
-
TokenController.cs
- Generates Twilio access tokens with the necessary grants for voice capabilities.
Ensure that your appsettings.json
file includes the necessary Twilio configuration settings:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"TWIML_APP_SID": "your_twiml_app_sid",
"TWILIO_ACCOUNT_SID": "your_twilio_account_sid",
"TEST_TWILIO_ACCOUNT_SID": "your_test_twilio_account_sid",
"TEST_TWILIO_AUTH_TOKEN": "your_test_twilio_auth_token",
"TWILIO_API_KEY_SID": "your_twilio_api_key_sid",
"TWILIO_API_KEY_SECRET": "your_twilio_api_key_secret",
"TWILIO_PHONE_NO": "your_twilio_phone_number"
}
The script handles Twilio Client configuration and provides functions for initiating, answering, and ending calls.
- Include the Twilio JavaScript library in your HTML file.
- Ensure the server-side token generation endpoint is correctly configured.
- Include the
browser-calls.js
script in your HTML file. - Call functions like
callCustomer(phoneNumber)
,callSupport()
, andhangUp()
based on your application's logic.
- Twilio.AspNet.Core
- Twilio.TwiML
- Twilio.Jwt.AccessToken
- Twilio JavaScript library
- Clone the repository.
- Update the
appsettings.json
file with your Twilio credentials. - Build and run the project.
- Feel free to customize this application based on your specific requirements or integrate it into your ASP.NET project for Twilio-powered voice communication.