This sample project demonstrates how to use Twilio APIs in a C# web application. Once the app is up and running, check out the home page to see which demos you can run. You'll find examples for Chat, Video, Sync, and more.
Let's get started!
NOTE: This project requires Visual Studio 2019, or .NET Core 3.1 installed on your computer.
- Install .NET Core.
- Clone this repository:
git clone https://github.com/TwilioDevEd/sdk-starter-csharp.git
To run the application, you'll need to gather your Twilio account credentials and configure them
in User Secrets via the secrets.json
file. If you are unsure how to do this, check out this blog post on User Secrets.
These credentials should mirror those in the appsettings.json
file found in the root of the TwilioSdkStarterDotnetCore.Web
project.
Every sample in the demo requires some basic credentials from your Twilio account. Configure these first.
Config Value | Description |
---|---|
TwilioAccount:AccountSid |
Your primary Twilio account identifier - find this in the console here. |
TwilioAccount:ApiKey |
Used to authenticate - generate one here. |
TwilioAccount:ApiSecret |
Used to authenticate - just like the above, you'll get one here. |
To set a configuration value, use the dotnet
command line:
cd sdk-starter-dotnet-core/src/TwilioSdkStarterDotnetCore.Web
dotnet user-secrets set "TwilioAccount:AccountSid" "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
dotnet user-secrets set "TwilioAccount:ApiKey" "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
dotnet user-secrets set "TwilioAccount:ApiSecret" "xxxxxxxxxxxxxxxxxxxxxxxx"
When you generate an API key pair at the URLs above, your API Secret will only be shown once - make sure to save this information in a secure location.
Depending on which demos you'd like to run, you may need to configure a few more values.
Twilio Sync works out of the box, using default settings per account.
In addition to the above, you'll need to generate a Chat Service in the Twilio Console. Put the result in your secrets.
Config Value | Where to get one. |
---|---|
TwilioAccount:ChatServiceSid |
Generate one in the Twilio Chat console |
cd sdk-starter-csharp/src/TwilioSdkStarterDotnetCore.Web
dotnet user-secrets set "TwilioAccount:ChatServiceSid" "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
You will need to create a Notify Service and add at least one credential on the Mobile Push Credential screen (such as Apple Push Notification Service or Firebase Cloud Messaging for Android) to send notifications using Notify.
Config Value | Where to get one. |
---|---|
TwilioAccount:NotificationServiceSid |
Generate one in the Notify Console. |
A Push Credential | Generate one with Apple or Google and configure it as a Notify credential. |
cd sdk-starter-csharp/src/TwilioSdkStarterDotnetCore.Web
dotnet user-secrets set "TwilioAccount:NotificationServiceSid" "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Open TwilioSdkStarterDotnetCore.sln
and press F5 or click the Run button
cd sdk-starter-csharp/src/TwilioSdkStarterDotnetCore.Web
dotnet restore
dotnet run
Your application should now be running at http://localhost:50768/.
Check your config values, and follow the links to the demo applications!
If you are going to connect to this SDK Starter Kit with a mobile app (and you should try it out!), your phone won't be able to access localhost directly. You'll need to create a publicly accessible URL using a tool like ngrok to send HTTP/HTTPS traffic to a server running on your localhost. Use HTTPS to make web connections that retrieve a Twilio access token.
ngrok http 50768
dotnet test tests/TwilioSdkStarterDotnetCore.Tests
MIT