Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

TwilioDevEd/sdk-starter-csharp

Repository files navigation

Twilio

Twilio SDK Starter Application for C#

Build Status

.NET Core 3.1 Project

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.

Setup

  1. Install .NET Core.
  2. Clone this repository:
    git clone https://github.com/TwilioDevEd/sdk-starter-csharp.git

Configure the sample application

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.

Configure account information

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"

A Note on API Keys

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.

Configure product-specific settings

Depending on which demos you'd like to run, you may need to configure a few more values.

Configuring Twilio Sync

Twilio Sync works out of the box, using default settings per account.

Configuring Twilio Chat

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"

Configuring Twilio Notify

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"

Run The Application

Visual Studio

Open TwilioSdkStarterDotnetCore.sln and press F5 or click the Run button

Windows CLI, OS X or Linux

cd sdk-starter-csharp/src/TwilioSdkStarterDotnetCore.Web
dotnet restore
dotnet run

Your application should now be running at http://localhost:50768/.

Home Screen

Check your config values, and follow the links to the demo applications!

Running the SDK Starter Kit with ngrok

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

Run Tests

dotnet test tests/TwilioSdkStarterDotnetCore.Tests

License

MIT

About

Demo application showcasing Twilio API usage in C#

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5