├── .gitignore ├── README.md ├── asp.net-messaging ├── .env.sample ├── .vs │ ├── ProjectEvaluation │ │ ├── asp.net-messaging.metadata.v5.2 │ │ └── asp.net-messaging.projects.v5.2 │ └── asp.net-messaging │ │ ├── FileContentIndex │ │ ├── e729049c-9518-4f58-873e-14fec2f55004.vsidx │ │ └── read.lock │ │ └── v17 │ │ └── .futdcache.v2 ├── .vscode │ ├── launch.json │ └── tasks.json ├── Controllers │ └── TelnyxMessagingController.cs ├── Models │ ├── InboundWebhook.cs │ └── OutboundWebhook.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── README.md ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json └── asp.net-messaging.csproj ├── asp.net-sms-autoresponder ├── .env.sample ├── .gitignore ├── Program.cs ├── Properties │ └── launchSettings.json ├── README.md ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json └── asp.net-sms-autoresponder.csproj ├── asp_net-IVR ├── .env.sample ├── .vscode │ ├── launch.json │ └── tasks.json ├── Controllers │ └── TelnyxCallControlController.cs ├── Models │ └── CallControlWebhook.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── README.md ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json └── asp_net-IVR.csproj ├── console-app-inventory-management ├── .vscode │ ├── launch.json │ └── tasks.json ├── Program.cs ├── README.md └── console-app-inventory-management.csproj ├── console-app-messaging-profile ├── .env.sample ├── .vscode │ ├── launch.json │ └── tasks.json ├── Program.cs ├── README.md └── console-app-messaging-profile.csproj ├── console-app-messaging ├── .env.sample ├── .vscode │ ├── launch.json │ └── tasks.json ├── Program.cs ├── README.md ├── contentful.md ├── demo-dotnet-telnyx.csproj └── sendMessageQS.md ├── console-app-verify ├── .env.sample ├── .vscode │ ├── launch.json │ └── tasks.json ├── Program.cs ├── README.md └── Verify.csproj └── logo-dark.png /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | .vscode/* 9 | .env 10 | 11 | # Build results 12 | 13 | [Dd]ebug/ 14 | [Rr]elease/ 15 | x64/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | 19 | # MSTest test Results 20 | [Tt]est[Rr]esult*/ 21 | [Bb]uild[Ll]og.* 22 | 23 | *_i.c 24 | *_p.c 25 | *_i.h 26 | *.ilk 27 | *.meta 28 | *.obj 29 | *.pch 30 | *.pdb 31 | *.pgc 32 | *.pgd 33 | *.rsp 34 | *.sbr 35 | *.tlb 36 | *.tli 37 | *.tlh 38 | *.tmp 39 | *.tmp_proj 40 | *.log 41 | *.vspscc 42 | *.vssscc 43 | .builds 44 | *.pidb 45 | *.log 46 | *.svclog 47 | *.scc 48 | 49 | # Visual C++ cache files 50 | ipch/ 51 | *.aps 52 | *.ncb 53 | *.opensdf 54 | *.sdf 55 | *.cachefile 56 | 57 | # Visual Studio profiler 58 | *.psess 59 | *.vsp 60 | *.vspx 61 | 62 | # Guidance Automation Toolkit 63 | *.gpState 64 | 65 | # ReSharper is a .NET coding add-in 66 | _ReSharper*/ 67 | *.[Rr]e[Ss]harper 68 | *.DotSettings.user 69 | 70 | # Click-Once directory 71 | publish/ 72 | 73 | # Publish Web Output 74 | *.Publish.xml 75 | *.pubxml 76 | *.azurePubxml 77 | 78 | # NuGet Packages Directory 79 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 80 | packages/ 81 | ## TODO: If the tool you use requires repositories.config, also uncomment the next line 82 | !packages/repositories.config 83 | 84 | # Windows Azure Build Output 85 | csx/ 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | sql/ 93 | *.Cache 94 | ClientBin/ 95 | [Ss]tyle[Cc]op.* 96 | ![Ss]tyle[Cc]op.targets 97 | ~$* 98 | *~ 99 | *.dbmdl 100 | *.[Pp]ublish.xml 101 | 102 | *.publishsettings 103 | 104 | # RIA/Silverlight projects 105 | Generated_Code/ 106 | 107 | # Backup & report files from converting an old project file to a newer 108 | # Visual Studio version. Backup files are not needed, because we have git ;-) 109 | _UpgradeReport_Files/ 110 | Backup*/ 111 | UpgradeLog*.XML 112 | UpgradeLog*.htm 113 | 114 | # SQL Server files 115 | App_Data/*.mdf 116 | App_Data/*.ldf 117 | 118 | # ========================= 119 | # Windows detritus 120 | # ========================= 121 | 122 | # Windows image file caches 123 | Thumbs.db 124 | ehthumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | # Recycle Bin used on file shares 130 | $RECYCLE.BIN/ 131 | 132 | # Mac desktop service store files 133 | .DS_Store 134 | 135 | _NCrunch* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Telnyx C# Getting Started 4 | 5 | ![Telnyx](logo-dark.png) 6 | 7 | Sample application demonstrating C# SDK Basics 8 | 9 |
10 | 11 | ## Documentation & Tutorial 12 | 13 | The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=dotnet&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 14 | 15 | ## Pre-Reqs 16 | 17 | You will need to set up: 18 | 19 | * [Telnyx Account](https://telnyx.com/sign-up?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 20 | * [Telnyx Phone Number](https://portal.telnyx.com/#/app/numbers/my-numbers?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) enabled with: 21 | * [Telnyx Call Control Application](https://portal.telnyx.com/#/app/call-control/applications?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 22 | * [Telnyx Outbound Voice Profile](https://portal.telnyx.com/#/app/outbound-profiles?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 23 | * Ability to receive webhooks (with something like [ngrok](https://developers.telnyx.com/docs/v2/development/ngrok?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link)) 24 | * [DotNet Core](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=java&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) installed 25 | 26 | ## What you can do 27 | 28 | | Example | Description | 29 | |:-----------------------------------------------|:--------------------------------------------------------------------------------------------------------------------| 30 | | [Console App Messaging](console-app-messaging) | Quick example demonstrating how to send an SMS with Telnyx.net from the dotnet CLI: `dotnet new console` | 31 | | [ASP.NET Messaging](asp.net-messaging) | Example working with inbound MMS & SMS messages, downloading media from inbound MMS, and uploading media to AWS S3. | 32 | 33 | ### Install 34 | 35 | Run the following commands to get started 36 | 37 | ``` 38 | $ git clone https://github.com/d-telnyx/demo-dotnet-telnyx.git 39 | ``` 40 | -------------------------------------------------------------------------------- /asp.net-messaging/.env.sample: -------------------------------------------------------------------------------- 1 | TELNYX_API_KEY= 2 | TELNYX_PUBLIC_KEY= 3 | TELNYX_APP_PORT=8000 4 | AWS_PROFILE= 5 | AWS_REGION= 6 | TELNYX_MMS_S3_BUCKET= 7 | -------------------------------------------------------------------------------- /asp.net-messaging/.vs/ProjectEvaluation/asp.net-messaging.metadata.v5.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Telnyx-API-DotNet/020c22af0d622686c4d88a34031663afef4991df/asp.net-messaging/.vs/ProjectEvaluation/asp.net-messaging.metadata.v5.2 -------------------------------------------------------------------------------- /asp.net-messaging/.vs/ProjectEvaluation/asp.net-messaging.projects.v5.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Telnyx-API-DotNet/020c22af0d622686c4d88a34031663afef4991df/asp.net-messaging/.vs/ProjectEvaluation/asp.net-messaging.projects.v5.2 -------------------------------------------------------------------------------- /asp.net-messaging/.vs/asp.net-messaging/FileContentIndex/e729049c-9518-4f58-873e-14fec2f55004.vsidx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Telnyx-API-DotNet/020c22af0d622686c4d88a34031663afef4991df/asp.net-messaging/.vs/asp.net-messaging/FileContentIndex/e729049c-9518-4f58-873e-14fec2f55004.vsidx -------------------------------------------------------------------------------- /asp.net-messaging/.vs/asp.net-messaging/FileContentIndex/read.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Telnyx-API-DotNet/020c22af0d622686c4d88a34031663afef4991df/asp.net-messaging/.vs/asp.net-messaging/FileContentIndex/read.lock -------------------------------------------------------------------------------- /asp.net-messaging/.vs/asp.net-messaging/v17/.futdcache.v2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Telnyx-API-DotNet/020c22af0d622686c4d88a34031663afef4991df/asp.net-messaging/.vs/asp.net-messaging/v17/.futdcache.v2 -------------------------------------------------------------------------------- /asp.net-messaging/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (web)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/asp.net-messaging.dll", 13 | "args": [], 14 | "cwd": "${workspaceFolder}", 15 | "stopAtEntry": false, 16 | // "serverReadyAction": { 17 | // "action": "openExternally", 18 | // "pattern": "\\bNow listening on:\\s+(https?://\\S+)" 19 | // }, 20 | "env": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "sourceFileMap": { 24 | "/Views": "${workspaceFolder}/Views" 25 | } 26 | }, 27 | { 28 | "name": ".NET Core Attach", 29 | "type": "coreclr", 30 | "request": "attach", 31 | "processId": "${command:pickProcess}" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /asp.net-messaging/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/asp.net-messaging.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/asp.net-messaging.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "${workspaceFolder}/asp.net-messaging.csproj", 36 | "/property:GenerateFullPaths=true", 37 | "/consoleloggerparameters:NoSummary" 38 | ], 39 | "problemMatcher": "$msCompile" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /asp.net-messaging/Controllers/TelnyxMessagingController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Mvc; 3 | using System.Threading.Tasks; 4 | using System.IO; 5 | using Newtonsoft.Json; 6 | using System.Net.Http; 7 | using System.Collections.Generic; 8 | using Telnyx; 9 | using Telnyx.net.Entities; 10 | using Microsoft.AspNetCore.Http; 11 | using dotnet_starter.Models; 12 | using Amazon.S3; 13 | using Amazon.S3.Model; 14 | using Amazon.S3.Transfer; 15 | using Amazon; 16 | 17 | namespace dotnet_starter.Controllers 18 | { 19 | public class WebhookHelpers 20 | { 21 | public static async Task deserializeInboundMessage(HttpRequest request) 22 | { 23 | string json; 24 | using (var reader = new StreamReader(request.Body)) 25 | { 26 | json = await reader.ReadToEndAsync(); 27 | } 28 | InboundWebhook myDeserializedClass = JsonConvert.DeserializeObject(json); 29 | return myDeserializedClass; 30 | } 31 | 32 | public static async Task deserializeOutboundMessage(HttpRequest request) 33 | { 34 | string json; 35 | using (var reader = new StreamReader(request.Body)) 36 | { 37 | json = await reader.ReadToEndAsync(); 38 | } 39 | OutboundWebhook myDeserializedClass = JsonConvert.DeserializeObject(json); 40 | return myDeserializedClass; 41 | } 42 | 43 | public static async Task UploadFileAsync(string filePath) 44 | { 45 | string bucketName = System.Environment.GetEnvironmentVariable("TELNYX_MMS_S3_BUCKET"); 46 | RegionEndpoint bucketRegion = RegionEndpoint.USEast2; 47 | IAmazonS3 s3Client = new AmazonS3Client(bucketRegion); 48 | TransferUtility fileTransferUtility = new TransferUtility(s3Client); 49 | string fileName = System.IO.Path.GetFileName(filePath); 50 | string mediaUrl = ""; 51 | try 52 | { 53 | TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest 54 | { 55 | BucketName = bucketName, 56 | FilePath = filePath, 57 | CannedACL = S3CannedACL.PublicRead 58 | }; 59 | await fileTransferUtility.UploadAsync(fileTransferUtilityRequest); 60 | Console.WriteLine("Upload completed"); 61 | mediaUrl = $"https://{bucketName}.s3.amazonaws.com/{fileName}"; 62 | } 63 | catch (AmazonS3Exception e) 64 | { 65 | Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message); 66 | } 67 | catch (Exception e) 68 | { 69 | Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message); 70 | } 71 | return mediaUrl; 72 | } 73 | 74 | public static async Task downloadMediaAsync(string directoryPath, string fileName, Uri uri) 75 | { 76 | HttpClient httpClient = new HttpClient(); 77 | string uriWithoutQuery = uri.GetLeftPart(UriPartial.Path); 78 | string fileExtension = Path.GetExtension(uriWithoutQuery); 79 | string path = Path.Combine(directoryPath, $"{fileName}{fileExtension}"); 80 | Directory.CreateDirectory(directoryPath); 81 | byte[] imageBytes = await httpClient.GetByteArrayAsync(uri); 82 | await File.WriteAllBytesAsync(path, imageBytes); 83 | return path; 84 | } 85 | } 86 | 87 | [ApiController] 88 | [Route("messaging/[controller]")] 89 | public class OutboundController : ControllerBase 90 | { 91 | // POST messaging/Inbound 92 | [HttpPost] 93 | [Consumes("application/json")] 94 | public async Task MessageDLRCallback() 95 | { 96 | OutboundWebhook webhook = await WebhookHelpers.deserializeOutboundMessage(this.Request); 97 | Console.WriteLine($"Received DLR for message with ID: {webhook.data.payload.id}"); 98 | return ""; 99 | } 100 | } 101 | 102 | [ApiController] 103 | [Route("messaging/[controller]")] 104 | public class InboundController : ControllerBase 105 | { 106 | 107 | private string TELNYX_API_KEY = System.Environment.GetEnvironmentVariable("TELNYX_API_KEY"); 108 | // POST messaging/Inbound 109 | [HttpPost] 110 | [Consumes("application/json")] 111 | public async Task MessageInboundCallback() 112 | { 113 | InboundWebhook webhook = await WebhookHelpers.deserializeInboundMessage(this.Request); 114 | UriBuilder uriBuilder = new UriBuilder(Request.Scheme, Request.Host.ToString()); 115 | uriBuilder.Path = "messaging/outbound"; 116 | string dlrUri = uriBuilder.ToString(); 117 | string to = webhook.data.payload.to[0].phone_number; 118 | string from = webhook.data.payload.from.phone_number; 119 | List media = webhook.data.payload.media; 120 | List files = new List(); 121 | List mediaUrls = new List(); 122 | if (media != null) 123 | { 124 | foreach (var item in media) 125 | { 126 | string path = await WebhookHelpers.downloadMediaAsync("./", item.hash_sha256, new Uri(item.url)); 127 | files.Add(path); 128 | string mediaUrl = await WebhookHelpers.UploadFileAsync(path); 129 | mediaUrls.Add(mediaUrl); 130 | } 131 | } 132 | TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); 133 | MessagingSenderIdService service = new MessagingSenderIdService(); 134 | NewMessagingSenderId options = new NewMessagingSenderId 135 | { 136 | From = to, 137 | To = from, 138 | Text = "Hello, World!", 139 | WebhookUrl = dlrUri, 140 | UseProfileWebhooks = false, 141 | MediaUrls = mediaUrls 142 | }; 143 | MessagingSenderId messageResponse = await service.CreateAsync(options); 144 | Console.WriteLine($"Sent message with ID: {messageResponse.Id}"); 145 | return ""; 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /asp.net-messaging/Models/InboundWebhook.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | 4 | namespace dotnet_starter.Models 5 | { 6 | // InboundWebhook myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); 7 | public class From 8 | { 9 | public string carrier { get; set; } 10 | public string line_type { get; set; } 11 | public string phone_number { get; set; } 12 | } 13 | 14 | public class MediaItem 15 | { 16 | public string content_type { get; set; } 17 | public string hash_sha256 { get; set; } 18 | public int size { get; set; } 19 | public string url { get; set; } 20 | } 21 | 22 | public class To 23 | { 24 | public string carrier { get; set; } 25 | public string line_type { get; set; } 26 | public string phone_number { get; set; } 27 | public string status { get; set; } 28 | } 29 | 30 | public class Payload 31 | { 32 | public List cc { get; set; } 33 | public object completed_at { get; set; } 34 | public object cost { get; set; } 35 | public string direction { get; set; } 36 | public string encoding { get; set; } 37 | public List errors { get; set; } 38 | public From from { get; set; } 39 | public string id { get; set; } 40 | public List media { get; set; } 41 | public string messaging_profile_id { get; set; } 42 | public string organization_id { get; set; } 43 | public int parts { get; set; } 44 | public DateTime received_at { get; set; } 45 | public string record_type { get; set; } 46 | public object sent_at { get; set; } 47 | public List tags { get; set; } 48 | public string text { get; set; } 49 | public List to { get; set; } 50 | public string type { get; set; } 51 | public object valid_until { get; set; } 52 | public object webhook_failover_url { get; set; } 53 | public string webhook_url { get; set; } 54 | } 55 | 56 | public class Data 57 | { 58 | public string event_type { get; set; } 59 | public string id { get; set; } 60 | public DateTime occurred_at { get; set; } 61 | public Payload payload { get; set; } 62 | public string record_type { get; set; } 63 | } 64 | 65 | public class Meta 66 | { 67 | public int attempt { get; set; } 68 | public string delivered_to { get; set; } 69 | } 70 | 71 | public class InboundWebhook 72 | { 73 | public Data data { get; set; } 74 | public Meta meta { get; set; } 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /asp.net-messaging/Models/OutboundWebhook.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System; 3 | 4 | namespace dotnet_starter.Models 5 | { 6 | // Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); 7 | public class OutboundWebhookPayload 8 | { 9 | public object completed_at { get; set; } 10 | public object cost { get; set; } 11 | public string direction { get; set; } 12 | public string encoding { get; set; } 13 | public List errors { get; set; } 14 | public string from { get; set; } 15 | public string id { get; set; } 16 | public List media { get; set; } 17 | public string messaging_profile_id { get; set; } 18 | public string organization_id { get; set; } 19 | public int parts { get; set; } 20 | public object received_at { get; set; } 21 | public string record_type { get; set; } 22 | public object sent_at { get; set; } 23 | public List tags { get; set; } 24 | public string text { get; set; } 25 | public List to { get; set; } 26 | public string type { get; set; } 27 | public DateTime valid_until { get; set; } 28 | public string webhook_failover_url { get; set; } 29 | public string webhook_url { get; set; } 30 | } 31 | 32 | public class OutboundWebhookData 33 | { 34 | public string event_type { get; set; } 35 | public string id { get; set; } 36 | public DateTime occurred_at { get; set; } 37 | public OutboundWebhookPayload payload { get; set; } 38 | public string record_type { get; set; } 39 | } 40 | 41 | public class OutboundWebhook 42 | { 43 | public OutboundWebhookData data { get; set; } 44 | public Meta meta { get; set; } 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /asp.net-messaging/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | using dotenv.net; 10 | 11 | 12 | namespace asp.net_messaging 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | DotEnv.Config(); 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | 22 | public static IHostBuilder CreateHostBuilder(string[] args) => 23 | Host.CreateDefaultBuilder(args) 24 | .ConfigureWebHostDefaults(webBuilder => 25 | { 26 | string Port = Environment.GetEnvironmentVariable("TELNYX_APP_PORT"); 27 | webBuilder.UseStartup(); 28 | string[] urls = new string[] {$"http://localhost:{Port}", "https://localhost:8001"}; 29 | webBuilder.UseUrls(urls); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /asp.net-messaging/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:39276", 7 | "sslPort": 44350 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "asp.net_messaging": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /asp.net-messaging/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Telnyx.net MMS and SMS Getting Started 4 | 5 | ![Telnyx](../logo-dark.png) 6 | 7 | Sample application demonstrating Telnyx.net SMS and MMS attachments 8 | 9 |
10 | 11 | ## Documentation & Tutorial 12 | 13 | The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=dotnet&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 14 | 15 | ## Pre-Reqs 16 | 17 | You will need to set up: 18 | 19 | * [Telnyx Account](https://telnyx.com/sign-up?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 20 | * [Telnyx Phone Number](https://portal.telnyx.com/#/app/numbers/my-numbers?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) enabled with: 21 | * [Telnyx Messaging Profile](https://portal.telnyx.com/#/app/messaging) 22 | * Ability to receive webhooks (with something like [ngrok](https://developers.telnyx.com/docs/v2/development/ngrok?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link)) 23 | * * [DotNet Core](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=net) installed 24 | * AWS Account setup with proper profiles and groups with IAM for S3. See the [Quickstart](https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/quick-start-s3-1-cross.html) for more information. 25 | * Previously created S3 bucket with public permissions available. 26 | 27 | ## What you can do 28 | 29 | * Send an SMS or MMS and recieve a copy of the attachments back to your phone number 30 | * Upload a file to AWS S3 31 | * Send those file as an MMS via Telnyx 32 | 33 | ## Usage 34 | 35 | The following environmental variables need to be set 36 | 37 | | Variable | Description | 38 | |:-----------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------| 39 | | `TELNYX_API_KEY` | Your [Telnyx API Key](https://portal.telnyx.com/#/app/api-keys?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 40 | | `TELNYX_PUBLIC_KEY` | Your [Telnyx Public Key](https://portal.telnyx.com/#/app/account/public-key?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 41 | | `TELNYX_APP_PORT` | **Defaults to `8000`** The port the app will be served | 42 | | `AWS_PROFILE` | Your AWS profile as set in `~/.aws` | 43 | | `AWS_REGION` | The region of your S3 bucket | 44 | | `TELNYX_MMS_S3_BUCKET` | The name of the bucket to upload the media attachments | 45 | 46 | ### .env file 47 | 48 | This app uses the excellent [dotenv.net](https://github.com/bolorundurowb/dotenv.net) package to manage environment variables. 49 | 50 | Make a copy of [`.env.sample`](./.env.sample) and save as `.env` and update the variables to match your creds. 51 | 52 | ``` 53 | TELNYX_API_KEY= 54 | TELNYX_PUBLIC_KEY= 55 | TENYX_APP_PORT=8000 56 | AWS_PROFILE= 57 | AWS_REGION= 58 | TELNYX_MMS_S3_BUCKET= 59 | ``` 60 | 61 | ### Callback URLs For Telnyx Applications 62 | 63 | | Callback Type | URL | 64 | |:---------------------------------|:---------------------------------| 65 | | Inbound Message Callback | `{ngrok-url}/messaging/inbound` | 66 | | Outbound Message Status Callback | `{ngrok-url}/messaging/outbound` | 67 | 68 | ### Install 69 | 70 | Run the following commands to get started 71 | 72 | ``` 73 | $ git clone https://github.com/team-telnyx/demo-dotnet-telnyx.git 74 | ``` 75 | 76 | ### Ngrok 77 | 78 | This application is served on the port defined in the runtime environment (or in the `.env` file). Be sure to launch [ngrok](https://developers.telnyx.com/docs/v2/development/ngrok?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) for that port 79 | 80 | ``` 81 | ./ngrok http 8000 82 | ``` 83 | 84 | > Terminal should look _something_ like 85 | 86 | ``` 87 | ngrok by @inconshreveable (Ctrl+C to quit) 88 | 89 | Session Status online 90 | Account Little Bobby Tables (Plan: Free) 91 | Version 2.3.35 92 | Region United States (us) 93 | Web Interface http://127.0.0.1:4040 94 | Forwarding http://your-url.ngrok.io -> http://localhost:8000 95 | Forwarding https://your-url.ngrok.io -> http://localhost:8000 96 | 97 | Connections ttl opn rt1 rt5 p50 p90 98 | 0 0 0.00 0.00 0.00 0.00 99 | ``` 100 | 101 | At this point you can point your application to generated ngrok URL + path (Example: `http://{your-url}.ngrok.io/messaging/inbound`). 102 | 103 | ### Run 104 | 105 | Open your IDE and run the application 106 | 107 | ## API Docs 108 | 109 | 110 | ## Next Steps -------------------------------------------------------------------------------- /asp.net-messaging/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace asp.net_messaging 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | services.AddControllers().AddNewtonsoftJson(); 20 | } 21 | 22 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 23 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 24 | { 25 | if (env.IsDevelopment()) 26 | { 27 | app.UseDeveloperExceptionPage(); 28 | } 29 | 30 | app.UseRouting(); 31 | 32 | app.UseEndpoints(endpoints => 33 | { 34 | endpoints.MapControllers(); 35 | }); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /asp.net-messaging/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /asp.net-messaging/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /asp.net-messaging/asp.net-messaging.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | asp.net_messaging 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /asp.net-sms-autoresponder/.env.sample: -------------------------------------------------------------------------------- 1 | TELNYX_API_KEY= -------------------------------------------------------------------------------- /asp.net-sms-autoresponder/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | .env 7 | 8 | # User-specific files 9 | *.rsuser 10 | *.suo 11 | *.user 12 | *.userosscache 13 | *.sln.docstates 14 | 15 | # User-specific files (MonoDevelop/Xamarin Studio) 16 | *.userprefs 17 | 18 | # Mono auto generated files 19 | mono_crash.* 20 | 21 | # Build results 22 | [Dd]ebug/ 23 | [Dd]ebugPublic/ 24 | [Rr]elease/ 25 | [Rr]eleases/ 26 | x64/ 27 | x86/ 28 | [Ww][Ii][Nn]32/ 29 | [Aa][Rr][Mm]/ 30 | [Aa][Rr][Mm]64/ 31 | bld/ 32 | [Bb]in/ 33 | [Oo]bj/ 34 | [Ll]og/ 35 | [Ll]ogs/ 36 | 37 | # Visual Studio 2015/2017 cache/options directory 38 | .vs/ 39 | # Uncomment if you have tasks that create the project's static files in wwwroot 40 | #wwwroot/ 41 | 42 | # Visual Studio 2017 auto generated files 43 | Generated\ Files/ 44 | 45 | # MSTest test Results 46 | [Tt]est[Rr]esult*/ 47 | [Bb]uild[Ll]og.* 48 | 49 | # NUnit 50 | *.VisualState.xml 51 | TestResult.xml 52 | nunit-*.xml 53 | 54 | # Build Results of an ATL Project 55 | [Dd]ebugPS/ 56 | [Rr]eleasePS/ 57 | dlldata.c 58 | 59 | # Benchmark Results 60 | BenchmarkDotNet.Artifacts/ 61 | 62 | # .NET Core 63 | project.lock.json 64 | project.fragment.lock.json 65 | artifacts/ 66 | 67 | # Tye 68 | .tye/ 69 | 70 | # ASP.NET Scaffolding 71 | ScaffoldingReadMe.txt 72 | 73 | # StyleCop 74 | StyleCopReport.xml 75 | 76 | # Files built by Visual Studio 77 | *_i.c 78 | *_p.c 79 | *_h.h 80 | *.ilk 81 | *.meta 82 | *.obj 83 | *.iobj 84 | *.pch 85 | *.pdb 86 | *.ipdb 87 | *.pgc 88 | *.pgd 89 | *.rsp 90 | *.sbr 91 | *.tlb 92 | *.tli 93 | *.tlh 94 | *.tmp 95 | *.tmp_proj 96 | *_wpftmp.csproj 97 | *.log 98 | *.vspscc 99 | *.vssscc 100 | .builds 101 | *.pidb 102 | *.svclog 103 | *.scc 104 | 105 | # Chutzpah Test files 106 | _Chutzpah* 107 | 108 | # Visual C++ cache files 109 | ipch/ 110 | *.aps 111 | *.ncb 112 | *.opendb 113 | *.opensdf 114 | *.sdf 115 | *.cachefile 116 | *.VC.db 117 | *.VC.VC.opendb 118 | 119 | # Visual Studio profiler 120 | *.psess 121 | *.vsp 122 | *.vspx 123 | *.sap 124 | 125 | # Visual Studio Trace Files 126 | *.e2e 127 | 128 | # TFS 2012 Local Workspace 129 | $tf/ 130 | 131 | # Guidance Automation Toolkit 132 | *.gpState 133 | 134 | # ReSharper is a .NET coding add-in 135 | _ReSharper*/ 136 | *.[Rr]e[Ss]harper 137 | *.DotSettings.user 138 | 139 | # TeamCity is a build add-in 140 | _TeamCity* 141 | 142 | # DotCover is a Code Coverage Tool 143 | *.dotCover 144 | 145 | # AxoCover is a Code Coverage Tool 146 | .axoCover/* 147 | !.axoCover/settings.json 148 | 149 | # Coverlet is a free, cross platform Code Coverage Tool 150 | coverage*.json 151 | coverage*.xml 152 | coverage*.info 153 | 154 | # Visual Studio code coverage results 155 | *.coverage 156 | *.coveragexml 157 | 158 | # NCrunch 159 | _NCrunch_* 160 | .*crunch*.local.xml 161 | nCrunchTemp_* 162 | 163 | # MightyMoose 164 | *.mm.* 165 | AutoTest.Net/ 166 | 167 | # Web workbench (sass) 168 | .sass-cache/ 169 | 170 | # Installshield output folder 171 | [Ee]xpress/ 172 | 173 | # DocProject is a documentation generator add-in 174 | DocProject/buildhelp/ 175 | DocProject/Help/*.HxT 176 | DocProject/Help/*.HxC 177 | DocProject/Help/*.hhc 178 | DocProject/Help/*.hhk 179 | DocProject/Help/*.hhp 180 | DocProject/Help/Html2 181 | DocProject/Help/html 182 | 183 | # Click-Once directory 184 | publish/ 185 | 186 | # Publish Web Output 187 | *.[Pp]ublish.xml 188 | *.azurePubxml 189 | # Note: Comment the next line if you want to checkin your web deploy settings, 190 | # but database connection strings (with potential passwords) will be unencrypted 191 | *.pubxml 192 | *.publishproj 193 | 194 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 195 | # checkin your Azure Web App publish settings, but sensitive information contained 196 | # in these scripts will be unencrypted 197 | PublishScripts/ 198 | 199 | # NuGet Packages 200 | *.nupkg 201 | # NuGet Symbol Packages 202 | *.snupkg 203 | # The packages folder can be ignored because of Package Restore 204 | **/[Pp]ackages/* 205 | # except build/, which is used as an MSBuild target. 206 | !**/[Pp]ackages/build/ 207 | # Uncomment if necessary however generally it will be regenerated when needed 208 | #!**/[Pp]ackages/repositories.config 209 | # NuGet v3's project.json files produces more ignorable files 210 | *.nuget.props 211 | *.nuget.targets 212 | 213 | # Microsoft Azure Build Output 214 | csx/ 215 | *.build.csdef 216 | 217 | # Microsoft Azure Emulator 218 | ecf/ 219 | rcf/ 220 | 221 | # Windows Store app package directories and files 222 | AppPackages/ 223 | BundleArtifacts/ 224 | Package.StoreAssociation.xml 225 | _pkginfo.txt 226 | *.appx 227 | *.appxbundle 228 | *.appxupload 229 | 230 | # Visual Studio cache files 231 | # files ending in .cache can be ignored 232 | *.[Cc]ache 233 | # but keep track of directories ending in .cache 234 | !?*.[Cc]ache/ 235 | 236 | # Others 237 | ClientBin/ 238 | ~$* 239 | *~ 240 | *.dbmdl 241 | *.dbproj.schemaview 242 | *.jfm 243 | *.pfx 244 | *.publishsettings 245 | orleans.codegen.cs 246 | 247 | # Including strong name files can present a security risk 248 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 249 | #*.snk 250 | 251 | # Since there are multiple workflows, uncomment next line to ignore bower_components 252 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 253 | #bower_components/ 254 | 255 | # RIA/Silverlight projects 256 | Generated_Code/ 257 | 258 | # Backup & report files from converting an old project file 259 | # to a newer Visual Studio version. Backup files are not needed, 260 | # because we have git ;-) 261 | _UpgradeReport_Files/ 262 | Backup*/ 263 | UpgradeLog*.XML 264 | UpgradeLog*.htm 265 | ServiceFabricBackup/ 266 | *.rptproj.bak 267 | 268 | # SQL Server files 269 | *.mdf 270 | *.ldf 271 | *.ndf 272 | 273 | # Business Intelligence projects 274 | *.rdl.data 275 | *.bim.layout 276 | *.bim_*.settings 277 | *.rptproj.rsuser 278 | *- [Bb]ackup.rdl 279 | *- [Bb]ackup ([0-9]).rdl 280 | *- [Bb]ackup ([0-9][0-9]).rdl 281 | 282 | # Microsoft Fakes 283 | FakesAssemblies/ 284 | 285 | # GhostDoc plugin setting file 286 | *.GhostDoc.xml 287 | 288 | # Node.js Tools for Visual Studio 289 | .ntvs_analysis.dat 290 | node_modules/ 291 | 292 | # Visual Studio 6 build log 293 | *.plg 294 | 295 | # Visual Studio 6 workspace options file 296 | *.opt 297 | 298 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 299 | *.vbw 300 | 301 | # Visual Studio LightSwitch build output 302 | **/*.HTMLClient/GeneratedArtifacts 303 | **/*.DesktopClient/GeneratedArtifacts 304 | **/*.DesktopClient/ModelManifest.xml 305 | **/*.Server/GeneratedArtifacts 306 | **/*.Server/ModelManifest.xml 307 | _Pvt_Extensions 308 | 309 | # Paket dependency manager 310 | .paket/paket.exe 311 | paket-files/ 312 | 313 | # FAKE - F# Make 314 | .fake/ 315 | 316 | # CodeRush personal settings 317 | .cr/personal 318 | 319 | # Python Tools for Visual Studio (PTVS) 320 | __pycache__/ 321 | *.pyc 322 | 323 | # Cake - Uncomment if you are using it 324 | # tools/** 325 | # !tools/packages.config 326 | 327 | # Tabs Studio 328 | *.tss 329 | 330 | # Telerik's JustMock configuration file 331 | *.jmconfig 332 | 333 | # BizTalk build output 334 | *.btp.cs 335 | *.btm.cs 336 | *.odx.cs 337 | *.xsd.cs 338 | 339 | # OpenCover UI analysis results 340 | OpenCover/ 341 | 342 | # Azure Stream Analytics local run output 343 | ASALocalRun/ 344 | 345 | # MSBuild Binary and Structured Log 346 | *.binlog 347 | 348 | # NVidia Nsight GPU debugger configuration file 349 | *.nvuser 350 | 351 | # MFractors (Xamarin productivity tool) working folder 352 | .mfractor/ 353 | 354 | # Local History for Visual Studio 355 | .localhistory/ 356 | 357 | # BeatPulse healthcheck temp database 358 | healthchecksdb 359 | 360 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 361 | MigrationBackup/ 362 | 363 | # Ionide (cross platform F# VS Code tools) working folder 364 | .ionide/ 365 | 366 | # Fody - auto-generated XML schema 367 | FodyWeavers.xsd 368 | 369 | ## 370 | ## Visual studio for Mac 371 | ## 372 | 373 | 374 | # globs 375 | Makefile.in 376 | *.userprefs 377 | *.usertasks 378 | config.make 379 | config.status 380 | aclocal.m4 381 | install-sh 382 | autom4te.cache/ 383 | *.tar.gz 384 | tarballs/ 385 | test-results/ 386 | 387 | # Mac bundle stuff 388 | *.dmg 389 | *.app 390 | 391 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore 392 | # General 393 | .DS_Store 394 | .AppleDouble 395 | .LSOverride 396 | 397 | # Icon must end with two \r 398 | Icon 399 | 400 | 401 | # Thumbnails 402 | ._* 403 | 404 | # Files that might appear in the root of a volume 405 | .DocumentRevisions-V100 406 | .fseventsd 407 | .Spotlight-V100 408 | .TemporaryItems 409 | .Trashes 410 | .VolumeIcon.icns 411 | .com.apple.timemachine.donotpresent 412 | 413 | # Directories potentially created on remote AFP share 414 | .AppleDB 415 | .AppleDesktop 416 | Network Trash Folder 417 | Temporary Items 418 | .apdisk 419 | 420 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore 421 | # Windows thumbnail cache files 422 | Thumbs.db 423 | ehthumbs.db 424 | ehthumbs_vista.db 425 | 426 | # Dump file 427 | *.stackdump 428 | 429 | # Folder config file 430 | [Dd]esktop.ini 431 | 432 | # Recycle Bin used on file shares 433 | $RECYCLE.BIN/ 434 | 435 | # Windows Installer files 436 | *.cab 437 | *.msi 438 | *.msix 439 | *.msm 440 | *.msp 441 | 442 | # Windows shortcuts 443 | *.lnk 444 | 445 | # JetBrains Rider 446 | .idea/ 447 | *.sln.iml 448 | 449 | ## 450 | ## Visual Studio Code 451 | ## 452 | .vscode/* 453 | !.vscode/settings.json 454 | !.vscode/tasks.json 455 | !.vscode/launch.json 456 | !.vscode/extensions.json 457 | -------------------------------------------------------------------------------- /asp.net-sms-autoresponder/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | using dotenv.net; 10 | 11 | namespace asp.net_sms_autoresponder 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | DotEnv.Load(); 18 | CreateHostBuilder(args).Build().Run(); 19 | } 20 | 21 | public static IHostBuilder CreateHostBuilder(string[] args) => 22 | Host.CreateDefaultBuilder(args) 23 | .ConfigureWebHostDefaults(webBuilder => 24 | { 25 | webBuilder.UseStartup(); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /asp.net-sms-autoresponder/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:2402", 7 | "sslPort": 44318 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "asp.net_sms_autoresponder": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /asp.net-sms-autoresponder/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Telnyx .NET SMS Autoresponder 4 | 5 | ![Telnyx](../logo-dark.png) 6 | 7 | Sample application demonstrating Telnyx .NET SMS autoresponse 8 | 9 |
10 | 11 | 12 | ## Documentation & Tutorial 13 | 14 | The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=dotnet&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 15 | 16 | ## Setup Telnyx 17 | 18 | - Complete the steps outlined on the [Messaging > Quickstarts > Portal Setup](https://developers.telnyx.com/docs/v2/messaging/quickstarts/portal-setup#mission-control-portal-set-up) developer page 19 | - You will: 20 | - Create a Telnyx account 21 | - Purchase an SMS-capable phone number with Telnyx 22 | - Create a messaging profile 23 | - Assign your phone number to your messaging profile 24 | 25 | ## Setup Localhost App 26 | 27 | - Clone this repository and change directory to this project folder 28 | - Run `cp .env.sample .env` and record the [Telynx API Key](https://portal.telnyx.com/#/app/api-keys) in the `.env` file 29 | - Start the server `dotnet run` 30 | 31 | ## Setup Reverse Proxy to Localhost 32 | 33 | For your localhost app to receive webhooks from Telnyx, we recommend the use of [ngrok](https://ngrok.com/): 34 | - Sign up for a free account and follow the ngrok 'Setup & Installation' guide. When running the `ngrok` tool, be sure to change the port value from `80` to `5000` (the port our app is listening on). 35 | - Once the `ngrok` process is running on your localhost, copy the forwarding https address (e.g., https://4f7e5039ecb9.ngrok.io) 36 | - On your [Telnyx Messaging Profile](https://portal.telnyx.com/#/app/messaging), update the Inbound Settings to "Send a webhook to this URL" with the copied forwarding url and append the defined webhooks path (e.g., https://4f7e5039ecb9.ngrok.io/webhooks) 37 | - Save the changes made to the Messaging Profile 38 | - You should now be able to send texts to your Telnyx number and receive an sms autoresponse from your localhost app 39 | -------------------------------------------------------------------------------- /asp.net-sms-autoresponder/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text.Json; 4 | using System.Collections.Generic; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Telnyx; 8 | 9 | namespace asp.net_sms_autoresponder 10 | { 11 | public class Startup 12 | { 13 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 14 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 15 | { 16 | string TELNYX_API_KEY = System.Environment.GetEnvironmentVariable("TELNYX_API_KEY"); 17 | TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); 18 | 19 | static string GetPreparedReply(string msg) 20 | { 21 | var preparedReplies = new Dictionary 22 | { 23 | { "ice cream", "I prefer gelato" }, 24 | { "pizza", "Chicago pizza is the best" } 25 | }; 26 | var defaultReply = "Please send either the word 'pizza' or 'ice cream' for a different response"; 27 | 28 | bool preparedReplyFound = preparedReplies.TryGetValue(msg.ToLower().Trim(), out string preparedReply); 29 | if (!preparedReplyFound) { 30 | preparedReply = defaultReply; 31 | } 32 | return preparedReply; 33 | } 34 | 35 | app.UseRouting(); 36 | 37 | app.UseEndpoints(endpoints => 38 | { 39 | endpoints.MapPost("/webhooks", async context => 40 | { 41 | using TextReader reader = new StreamReader(context.Request.Body); 42 | string json = await reader.ReadToEndAsync(); 43 | JsonElement body = JsonSerializer.Deserialize(json); 44 | 45 | var data = body.GetProperty("data"); 46 | var eventType = data.GetProperty("event_type"); 47 | var payload = data.GetProperty("payload"); 48 | var direction = payload.GetProperty("direction"); 49 | 50 | if (eventType.ToString() == "message.received" && direction.ToString() == "inbound") { 51 | var message = payload.GetProperty("text"); 52 | Console.WriteLine($"Received message: {message}"); 53 | 54 | var from = payload.GetProperty("from"); 55 | var replyToTN = from.GetProperty("phone_number"); 56 | 57 | var to = payload.GetProperty("to"); 58 | String telnyxNumber = ""; 59 | foreach (var item in to.EnumerateArray()) 60 | { 61 | telnyxNumber = item.GetProperty("phone_number").ToString(); 62 | break; 63 | } 64 | 65 | var preparedReply = GetPreparedReply(message.ToString()); 66 | 67 | MessagingSenderIdService service = new MessagingSenderIdService(); 68 | NewMessagingSenderId options = new NewMessagingSenderId 69 | { 70 | From = telnyxNumber, 71 | To = replyToTN.ToString(), 72 | Text = preparedReply 73 | }; 74 | 75 | try 76 | { 77 | Console.WriteLine($"Will reply with message: {preparedReply}"); 78 | MessagingSenderId messageResponse = await service.CreateAsync(options); 79 | Console.WriteLine(messageResponse); 80 | } 81 | catch (TelnyxException ex) 82 | { 83 | Console.WriteLine(ex); 84 | } 85 | } 86 | }); 87 | }); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /asp.net-sms-autoresponder/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /asp.net-sms-autoresponder/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /asp.net-sms-autoresponder/asp.net-sms-autoresponder.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | asp.net_sms_autoresponder 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /asp_net-IVR/.env.sample: -------------------------------------------------------------------------------- 1 | TELNYX_API_KEY= 2 | TELNYX_PUBLIC_KEY= 3 | PORT=8000 -------------------------------------------------------------------------------- /asp_net-IVR/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "OS-COMMENT1": "Use IntelliSense to find out which attributes exist for C# debugging", 9 | "OS-COMMENT2": "Use hover for the description of the existing attributes", 10 | "OS-COMMENT3": "For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md", 11 | "name": ".NET Core Launch (web)", 12 | "type": "coreclr", 13 | "request": "launch", 14 | "preLaunchTask": "build", 15 | "OS-COMMENT4": "If you have changed target frameworks, make sure to update the program path.", 16 | "program": "${workspaceFolder}/bin/Debug/net5.0/asp_net-IVR.dll", 17 | "args": [], 18 | "cwd": "${workspaceFolder}", 19 | "stopAtEntry": false, 20 | "OS-COMMENT5": "Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser", 21 | "serverReadyAction": { 22 | "action": "openExternally", 23 | "pattern": "\\\\bNow listening on:\\\\s+(https?://\\\\S+)" 24 | }, 25 | "env": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | }, 28 | "sourceFileMap": { 29 | "/Views": "${workspaceFolder}/Views" 30 | } 31 | }, 32 | { 33 | "name": ".NET Core Attach", 34 | "type": "coreclr", 35 | "request": "attach", 36 | "processId": "${command:pickProcess}" 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /asp_net-IVR/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/asp_net-IVR.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/asp_net-IVR.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "${workspaceFolder}/asp_net-IVR.csproj", 36 | "/property:GenerateFullPaths=true", 37 | "/consoleloggerparameters:NoSummary" 38 | ], 39 | "problemMatcher": "$msCompile" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /asp_net-IVR/Controllers/TelnyxCallControlController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Telnyx; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Http; 7 | using System.Text.Json; 8 | using Telnyx.net.Services.Calls.CallCommands; 9 | 10 | namespace asp_net_IVR { 11 | public class WebhookHelpers 12 | { 13 | public static async Task deserializeWebhook(HttpRequest request) 14 | { 15 | string json; 16 | using (var reader = new StreamReader(request.Body)) 17 | { 18 | json = await reader.ReadToEndAsync(); 19 | } 20 | CallControlWebhook myDeserializedClass = JsonSerializer.Deserialize(json); 21 | return myDeserializedClass; 22 | } 23 | public static string Base64Encode(string plainText) 24 | { 25 | var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); 26 | return System.Convert.ToBase64String(plainTextBytes); 27 | } 28 | 29 | public static string Base64Decode(string base64EncodedData) 30 | { 31 | if (base64EncodedData == null) { 32 | return ""; 33 | } 34 | var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); 35 | return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); 36 | } 37 | } 38 | 39 | [ApiController] 40 | [Route("call-control/[controller]")] 41 | public class OutboundController : ControllerBase 42 | { 43 | [HttpPost] 44 | [Consumes("application/json")] 45 | public string CallControlOutboundWebhook(CallControlWebhook webhook) 46 | { 47 | Console.WriteLine($"Received outbound event: {webhook.data.event_type}"); 48 | return ""; 49 | } 50 | } 51 | 52 | [ApiController] 53 | [Route("call-control/[controller]")] 54 | public class InboundController : ControllerBase 55 | { 56 | 57 | [HttpPost] 58 | [Consumes("application/json")] 59 | public async Task CallControlInboundWebhook(CallControlWebhook webhook) 60 | { 61 | String callControlId = webhook.data.payload.call_control_id; 62 | CallControlService callControlService = new CallControlService(); 63 | callControlService.CallControlId = callControlId; 64 | Guid commandId = Guid.NewGuid(); 65 | String webhookClientState = WebhookHelpers.Base64Decode(webhook.data.payload.client_state); 66 | try { 67 | switch (webhook.data.event_type){ 68 | case "call.initiated": 69 | CallControlAnswerOptions answerOptions = new CallControlAnswerOptions() { 70 | CommandId = commandId 71 | }; 72 | CallAnswerResponse answerResponse = await callControlService.AnswerAsync(answerOptions); 73 | Console.WriteLine($"Answer Response: {answerResponse.TelnyxResponse.ResponseJson.ToString()}"); 74 | return "answer-sent"; 75 | case "call.answered": 76 | CallControlGatherUsingSpeakOptions gatherUsingSpeakOptions = new CallControlGatherUsingSpeakOptions(){ 77 | Language = "en-US", 78 | Voice = "female", 79 | Payload = "Please enter the 10 digit phone number you would like to dial, followed by the pound sign", 80 | InvalidPayload = "Sorry, I didn't get that", 81 | MaximumDigits = 11, 82 | MinimumDigits = 10, 83 | ValidDigits = "0123456789", 84 | CommandId = commandId 85 | }; 86 | CallGatherUsingSpeakResponse gatherResponse = await callControlService.GatherUsingSpeakAsync(gatherUsingSpeakOptions); 87 | Console.WriteLine($"Gather Response: {gatherResponse.TelnyxResponse.ResponseJson.ToString()}"); 88 | return "gather-sent"; 89 | case "call.gather.ended": 90 | String reason = webhook.data.payload.status; 91 | if (reason == "call_hangup") { 92 | Console.WriteLine($"Call: {callControlId} hung up during gather"); 93 | } 94 | String digits = webhook.data.payload.digits; 95 | String phoneNumber = $"+1{digits}"; 96 | UriBuilder uriBuilder = new UriBuilder(Request.Scheme, Request.Host.ToString()); 97 | uriBuilder.Path = "call-control/outbound"; 98 | string transferUri = uriBuilder.ToString(); 99 | CallControlTransferOptions transferOptions = new CallControlTransferOptions(){ 100 | To = phoneNumber, 101 | WebhookUrl = transferUri, 102 | CommandId = commandId 103 | }; 104 | CallTransferResponse transferResponse = await callControlService.TransferAsync(transferOptions); 105 | Console.WriteLine($"Transfer Response: {transferResponse.TelnyxResponse.ResponseJson.ToString()}"); 106 | return "transfer-sent"; 107 | default: 108 | Console.WriteLine($"Non-handled Event: {webhook.data.event_type}"); 109 | return "default-non-event"; 110 | } 111 | } 112 | catch (Exception e) 113 | { 114 | Console.Write(e); 115 | } 116 | return ""; 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /asp_net-IVR/Models/CallControlWebhook.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace asp_net_IVR 4 | { 5 | public class Payload 6 | { 7 | public string call_control_id { get; set; } 8 | public string call_leg_id { get; set; } 9 | public string call_session_id { get; set; } 10 | public string client_state { get; set; } 11 | public string connection_id { get; set; } 12 | public string from { get; set; } 13 | public string state { get; set; } 14 | public string to { get; set; } 15 | public string direction { get; set; } 16 | public string digit { get; set; } 17 | public string digits { get; set; } 18 | public string hangup_cause { get; set; } 19 | public string hangup_source { get; set; } 20 | public string status { get; set; } 21 | } 22 | 23 | public class Data 24 | { 25 | public string event_type { get; set; } 26 | public string id { get; set; } 27 | public DateTime occurred_at { get; set; } 28 | public Payload payload { get; set; } 29 | public string record_type { get; set; } 30 | } 31 | 32 | public class CallControlWebhook 33 | { 34 | public Data data { get; set; } 35 | } 36 | 37 | 38 | 39 | } -------------------------------------------------------------------------------- /asp_net-IVR/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | using dotenv.net; 10 | using Telnyx; 11 | 12 | namespace asp_net_IVR 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | DotEnv.Config(); 19 | string TELNYX_API_KEY = System.Environment.GetEnvironmentVariable("TELNYX_API_KEY"); 20 | TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); 21 | 22 | CreateHostBuilder(args).Build().Run(); 23 | } 24 | 25 | public static IHostBuilder CreateHostBuilder(string[] args) => 26 | Host.CreateDefaultBuilder(args) 27 | .ConfigureWebHostDefaults(webBuilder => 28 | { 29 | string Port = Environment.GetEnvironmentVariable("PORT"); 30 | webBuilder.UseStartup(); 31 | string[] urls = new string[] { $"http://localhost:{Port}", "https://localhost:8001" }; 32 | webBuilder.UseUrls(urls); 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /asp_net-IVR/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:10592", 7 | "sslPort": 44377 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "asp_net_IVR": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /asp_net-IVR/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Telnyx.net Call Control Getting Started 4 | 5 | ![Telnyx](../logo-dark.png) 6 | 7 | Sample application demonstrating Telnyx.net Gathering IVR Digits and Transferring a call 8 | 9 |
10 | 11 | ## Documentation & Tutorial 12 | 13 | The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=dotnet&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 14 | 15 | ## Pre-Reqs 16 | 17 | You will need to set up: 18 | 19 | * [Telnyx Account](https://telnyx.com/sign-up?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 20 | * [Telnyx Phone Number](https://portal.telnyx.com/#/app/numbers/my-numbers?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) enabled with: 21 | * [Telnyx Call Control Application](https://portal.telnyx.com/#/app/call-control/applications?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 22 | * [Telnyx Outbound Voice Profile](https://portal.telnyx.com/#/app/outbound-profiles?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 23 | * Ability to receive webhooks (with something like [ngrok](https://developers.telnyx.com/docs/v2/development/ngrok?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link)) 24 | * [DotNet Core](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=net) installed 25 | 26 | ## What you can do 27 | 28 | * Call the Telnyx Number and enter the digits to get transferred. 29 | 30 | ## Usage 31 | 32 | The following environmental variables need to be set 33 | 34 | | Variable | Description | 35 | |:-----------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------| 36 | | `TELNYX_API_KEY` | Your [Telnyx API Key](https://portal.telnyx.com/#/app/api-keys?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 37 | | `TELNYX_PUBLIC_KEY` | Your [Telnyx Public Key](https://portal.telnyx.com/#/app/account/public-key?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 38 | | `PORT` | **Defaults to `8000`** The port the app will be served | 39 | 40 | ### .env file 41 | 42 | This app uses the excellent [dotenv.net](https://github.com/bolorundurowb/dotenv.net) package to manage environment variables. 43 | 44 | Make a copy of [`.env.sample`](./.env.sample) and save as `.env` and update the variables to match your creds. 45 | 46 | ``` 47 | TELNYX_API_KEY= 48 | TELNYX_PUBLIC_KEY= 49 | PORT=8000 50 | ``` 51 | 52 | ### Callback URLs For Telnyx Applications 53 | 54 | | Callback Type | URL | 55 | |:---------------------------------|:---------------------------------| 56 | | Inbound Calls Callback | `{ngrok-url}/call-control/inbound` | 57 | | Outbound Calls Callback | `{ngrok-url}/call-control/outbound` | 58 | 59 | ### Install 60 | 61 | Run the following commands to get started 62 | 63 | ``` 64 | $ git clone https://github.com/team-telnyx/demo-dotnet-telnyx.git 65 | $ cd asp_net-IVR 66 | ``` 67 | 68 | ### Ngrok 69 | 70 | This application is served on the port defined in the runtime environment (or in the `.env` file). Be sure to launch [ngrok](https://developers.telnyx.com/docs/v2/development/ngrok?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) for that port 71 | 72 | ``` 73 | ./ngrok http 8000 74 | ``` 75 | 76 | > Terminal should look _something_ like 77 | 78 | ``` 79 | ngrok by @inconshreveable (Ctrl+C to quit) 80 | 81 | Session Status online 82 | Account Little Bobby Tables (Plan: Free) 83 | Version 2.3.35 84 | Region United States (us) 85 | Web Interface http://127.0.0.1:4040 86 | Forwarding http://your-url.ngrok.io -> http://localhost:8000 87 | Forwarding https://your-url.ngrok.io -> http://localhost:8000 88 | 89 | Connections ttl opn rt1 rt5 p50 p90 90 | 0 0 0.00 0.00 0.00 0.00 91 | ``` 92 | 93 | At this point you can point your [call-control application](https://portal.telnyx.com/#/app/call-control/applications) to generated ngrok URL + path (Example: `http://{your-url}.ngrok.io/call-control/inbound`). 94 | 95 | ### Assign Phone Number to the Application 96 | 97 | Update one of your [phone numbers](https://portal.telnyx.com/#/app/numbers/my-numbers) to point to the [call-control application](https://portal.telnyx.com/#/app/call-control/applications) you've updated with your ngrok URL. 98 | 99 | ### Run 100 | 101 | Open your IDE and run the application within the IDE or using the dotnet CLI 102 | 103 | #### CLI Commands 104 | 105 | ```bash 106 | $ dotnet restore 107 | $ dotnet run 108 | ``` 109 | 110 | #### Call your phone number 111 | 112 | 1. Call the phone number associated you with your call control application. 113 | 2. You'll be prompted to enter a 10 digit phone number then the app will transfer you to the phone number you entered. _Try `9198675309` if you need a demo number_ -------------------------------------------------------------------------------- /asp_net-IVR/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace asp_net_IVR 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | services.AddControllers(); 20 | } 21 | 22 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 23 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 24 | { 25 | if (env.IsDevelopment()) 26 | { 27 | app.UseDeveloperExceptionPage(); 28 | } 29 | 30 | app.UseRouting(); 31 | 32 | app.UseEndpoints(endpoints => 33 | { 34 | endpoints.MapControllers(); 35 | }); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /asp_net-IVR/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /asp_net-IVR/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /asp_net-IVR/asp_net-IVR.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | asp_net_IVR 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /console-app-inventory-management/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "OS-COMMENT1": "Use IntelliSense to find out which attributes exist for C# debugging", 9 | "OS-COMMENT2": "Use hover for the description of the existing attributes", 10 | "OS-COMMENT3": "For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md", 11 | "name": ".NET Core Launch (console)", 12 | "type": "coreclr", 13 | "request": "launch", 14 | "preLaunchTask": "build", 15 | "OS-COMMENT4": "If you have changed target frameworks, make sure to update the program path.", 16 | "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/console-app-inventory-management.dll", 17 | "args": [], 18 | "cwd": "${workspaceFolder}", 19 | "OS-COMMENT5": "For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console", 20 | "console": "internalConsole", 21 | "stopAtEntry": false 22 | }, 23 | { 24 | "name": ".NET Core Attach", 25 | "type": "coreclr", 26 | "request": "attach", 27 | "processId": "${command:pickProcess}" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /console-app-inventory-management/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/console-app-inventory-management.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/console-app-inventory-management.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "${workspaceFolder}/console-app-inventory-management.csproj", 36 | "/property:GenerateFullPaths=true", 37 | "/consoleloggerparameters:NoSummary" 38 | ], 39 | "problemMatcher": "$msCompile" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /console-app-inventory-management/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Telnyx; 3 | using dotenv.net; 4 | using Telnyx.net.Entities; 5 | 6 | namespace console_app_inventory_management 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | DotEnv.Config(); 13 | string TELNYX_API_KEY = System.Environment.GetEnvironmentVariable("TELNYX_API_KEY"); 14 | TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); 15 | 16 | var service = new NumberOrderService(); 17 | NumberOrderListOptions numberOrderListOptions = new NumberOrderListOptions() 18 | { 19 | Status = "success", 20 | PageSize = 250 21 | }; 22 | var requestOptions = new RequestOptions(); 23 | TelnyxList orders = service.List(numberOrderListOptions, requestOptions); 24 | foreach (NumberOrder order in orders) 25 | { 26 | Console.WriteLine(order); 27 | } 28 | 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /console-app-inventory-management/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Telnyx C# List Phone Number Orders 4 | 5 | ![Telnyx](../logo-dark.png) 6 | 7 | Sample application demonstrating C# SDK listing Phone Number orders 8 | 9 |
10 | 11 | ## Documentation & Tutorial 12 | 13 | The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=dotnet&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 14 | 15 | ## Pre-Reqs 16 | 17 | You will need to set up: 18 | 19 | * [Telnyx Account](https://telnyx.com/sign-up?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 20 | * [DotNet Core](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=java&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) installed 21 | 22 | ## What you can do 23 | 24 | * 25 | 26 | ## Usage 27 | 28 | The following environmental variables need to be set 29 | 30 | | Variable | Description | 31 | |:--------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------| 32 | | `TELNYX_API_KEY` | Your [Telnyx API Key](https://portal.telnyx.com/#/app/api-keys?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 33 | 34 | ### .env file 35 | 36 | This app uses the excellent [dotenv.net](https://github.com/bolorundurowb/dotenv.net) package to manage environment variables. 37 | 38 | Make a copy of [`.env.sample`](./.env.sample) and save as `.env` and update the variables to match your creds. 39 | 40 | ``` 41 | TELNYX_API_KEY= 42 | ``` 43 | 44 | ### Install 45 | 46 | Run the following commands to get started 47 | 48 | ``` 49 | $ git clone https://github.com/d-telnyx/demo-dotnet-telnyx.git 50 | ``` 51 | 52 | ### Run 53 | 54 | Open your IDE and run the application 55 | 56 | ## API Docs 57 | 58 | 59 | ## Next Steps -------------------------------------------------------------------------------- /console-app-inventory-management/console-app-inventory-management.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | console_app_inventory_management 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /console-app-messaging-profile/.env.sample: -------------------------------------------------------------------------------- 1 | TELNYX_API_KEY= 2 | TELNYX_PUBLIC_KEY= 3 | TELNYX_APP_PORT=8000 -------------------------------------------------------------------------------- /console-app-messaging-profile/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/console-app-messaging-profile.dll", 13 | "args": [], 14 | "cwd": "${workspaceFolder}", 15 | "console": "internalConsole", 16 | "stopAtEntry": false 17 | }, 18 | { 19 | "name": ".NET Core Attach", 20 | "type": "coreclr", 21 | "request": "attach", 22 | "processId": "${command:pickProcess}" 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /console-app-messaging-profile/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/console-app-messaging-profile.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/console-app-messaging-profile.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "${workspaceFolder}/console-app-messaging-profile.csproj", 36 | "/property:GenerateFullPaths=true", 37 | "/consoleloggerparameters:NoSummary" 38 | ], 39 | "problemMatcher": "$msCompile" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /console-app-messaging-profile/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Telnyx; 3 | using dotenv.net; 4 | using Newtonsoft.Json; 5 | using Telnyx.net.Entities.Messaging.Messaging_Profiles; 6 | using System.Collections.Generic; 7 | 8 | namespace console_app_messaging_profile 9 | { 10 | class Program 11 | { 12 | private const string webhookUrl = ""; 13 | 14 | static void Main(string[] args) 15 | { 16 | DotEnv.Config(); 17 | string TELNYX_API_KEY = System.Environment.GetEnvironmentVariable("TELNYX_API_KEY"); 18 | TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); 19 | UrlShortenerSettings urlShortenerSettings = new UrlShortenerSettings() 20 | { 21 | Domain = "aptrmdr.cc", 22 | ReplaceBlackListOnly = false, 23 | SendWebhooks = false 24 | }; 25 | NewMessagingProfile createOptions = new NewMessagingProfile 26 | { 27 | Name = "Summer Campaign asdf", 28 | WebhookUrl = webhookUrl, 29 | UrlShortenerSettings = urlShortenerSettings 30 | }; 31 | 32 | Console.WriteLine(JsonConvert.SerializeObject(createOptions)); ; 33 | MessagingProfileService service = new MessagingProfileService(); 34 | MessagingProfile messagingProfile = service.Create(createOptions); 35 | Console.WriteLine(JsonConvert.SerializeObject(messagingProfile)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /console-app-messaging-profile/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Telnyx C# Getting Started 4 | 5 | ![Telnyx](../logo-dark.png) 6 | 7 | Sample application demonstrating C# SDK Messaging Profile Settings 8 | 9 |
10 | 11 | ## Documentation & Tutorial 12 | 13 | The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=dotnet&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 14 | 15 | ## Pre-Reqs 16 | 17 | You will need to set up: 18 | 19 | * [Telnyx Account](https://telnyx.com/sign-up?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 20 | * [Telnyx Phone Number](https://portal.telnyx.com/#/app/numbers/my-numbers?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) enabled with: 21 | * [Telnyx Call Control Application](https://portal.telnyx.com/#/app/call-control/applications?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 22 | * [Telnyx Outbound Voice Profile](https://portal.telnyx.com/#/app/outbound-profiles?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 23 | * Ability to receive webhooks (with something like [ngrok](https://developers.telnyx.com/docs/v2/development/ngrok?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link)) 24 | * [DotNet Core](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=java&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) installed 25 | 26 | ## What you can do 27 | 28 | * 29 | 30 | ## Usage 31 | 32 | The following environmental variables need to be set 33 | 34 | | Variable | Description | 35 | |:--------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------| 36 | | `TELNYX_API_KEY` | Your [Telnyx API Key](https://portal.telnyx.com/#/app/api-keys?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 37 | | `TELNYX_PUBLIC_KEY` | Your [Telnyx Public Key](https://portal.telnyx.com/#/app/account/public-key?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 38 | | `TELNYX_APP_PORT` | **Defaults to `8000`** The port the app will be served | 39 | 40 | ### .env file 41 | 42 | This app uses the excellent [dotenv.net](https://github.com/bolorundurowb/dotenv.net) package to manage environment variables. 43 | 44 | Make a copy of [`.env.sample`](./.env.sample) and save as `.env` and update the variables to match your creds. 45 | 46 | ``` 47 | TELNYX_API_KEY= 48 | TELNYX_PUBLIC_KEY= 49 | TENYX_APP_PORT=8000 50 | ``` 51 | 52 | ### Install 53 | 54 | Run the following commands to get started 55 | 56 | ``` 57 | $ git clone https://github.com/d-telnyx/demo-dotnet-telnyx.git 58 | ``` 59 | 60 | ### Run 61 | 62 | Open your IDE and run the application 63 | 64 | ## API Docs 65 | 66 | 67 | ## Next Steps -------------------------------------------------------------------------------- /console-app-messaging-profile/console-app-messaging-profile.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | console_app_messaging_profile 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /console-app-messaging/.env.sample: -------------------------------------------------------------------------------- 1 | TELNYX_API_KEY= 2 | TELNYX_PUBLIC_KEY= 3 | TELNYX_APP_PORT=8000 -------------------------------------------------------------------------------- /console-app-messaging/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/demo-dotnet-telnyx.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}", 16 | // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console 17 | "console": "internalConsole", 18 | "stopAtEntry": false 19 | }, 20 | { 21 | "name": ".NET Core Attach", 22 | "type": "coreclr", 23 | "request": "attach", 24 | "processId": "${command:pickProcess}" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /console-app-messaging/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/demo-dotnet-telnyx.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/demo-dotnet-telnyx.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "${workspaceFolder}/demo-dotnet-telnyx.csproj", 36 | "/property:GenerateFullPaths=true", 37 | "/consoleloggerparameters:NoSummary" 38 | ], 39 | "problemMatcher": "$msCompile" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /console-app-messaging/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Telnyx; 3 | using System.Threading.Tasks; 4 | 5 | namespace demo_dotnet_telnyx 6 | { 7 | class Program 8 | { 9 | private static string TELNYX_API_KEY = System.Environment.GetEnvironmentVariable("TELNYX_API_KEY"); 10 | static async Task Main(string[] args) 11 | { 12 | Console.WriteLine("Hello World!"); 13 | TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); 14 | MessagingSenderIdService service = new MessagingSenderIdService(); 15 | NewMessagingSenderId options = new NewMessagingSenderId 16 | { 17 | From = "+19842550905", // alphanumeric sender id 18 | To = "+19197891146", 19 | Text = "Hello, World!" 20 | }; 21 | MessagingSenderId messageResponse = await service.CreateAsync(options); 22 | Console.WriteLine(messageResponse.Id); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /console-app-messaging/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Telnyx C# Getting Started 4 | 5 | ![Telnyx](../logo-dark.png) 6 | 7 | Sample application demonstrating C# SDK Basics 8 | 9 |
10 | 11 | ## Documentation & Tutorial 12 | 13 | The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=dotnet&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 14 | 15 | ## Pre-Reqs 16 | 17 | You will need to set up: 18 | 19 | * [Telnyx Account](https://telnyx.com/sign-up?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 20 | * [Telnyx Phone Number](https://portal.telnyx.com/#/app/numbers/my-numbers?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) enabled with: 21 | * [Telnyx Call Control Application](https://portal.telnyx.com/#/app/call-control/applications?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 22 | * [Telnyx Outbound Voice Profile](https://portal.telnyx.com/#/app/outbound-profiles?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 23 | * Ability to receive webhooks (with something like [ngrok](https://developers.telnyx.com/docs/v2/development/ngrok?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link)) 24 | * [DotNet Core](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=java&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) installed 25 | 26 | ## What you can do 27 | 28 | * 29 | 30 | ## Usage 31 | 32 | The following environmental variables need to be set 33 | 34 | | Variable | Description | 35 | |:--------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------| 36 | | `TELNYX_API_KEY` | Your [Telnyx API Key](https://portal.telnyx.com/#/app/api-keys?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 37 | | `TELNYX_PUBLIC_KEY` | Your [Telnyx Public Key](https://portal.telnyx.com/#/app/account/public-key?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 38 | | `TELNYX_APP_PORT` | **Defaults to `8000`** The port the app will be served | 39 | 40 | ### .env file 41 | 42 | This app uses the excellent [dotenv.net](https://github.com/bolorundurowb/dotenv.net) package to manage environment variables. 43 | 44 | Make a copy of [`.env.sample`](./.env.sample) and save as `.env` and update the variables to match your creds. 45 | 46 | ``` 47 | TELNYX_API_KEY= 48 | TELNYX_PUBLIC_KEY= 49 | TENYX_APP_PORT=8000 50 | ``` 51 | 52 | ### Install 53 | 54 | Run the following commands to get started 55 | 56 | ``` 57 | $ git clone https://github.com/d-telnyx/demo-dotnet-telnyx.git 58 | ``` 59 | 60 | ### Run 61 | 62 | Open your IDE and run the application 63 | 64 | ## API Docs 65 | 66 | 67 | ## Next Steps -------------------------------------------------------------------------------- /console-app-messaging/contentful.md: -------------------------------------------------------------------------------- 1 | Get up and running with our Client libraries and start developing your Telnyx integration. 2 | 3 | Integrating Telnyx into your app or website can begin as soon as you create a Telnyx account, requiring only two steps: 4 | 1. Obtain your API key so Telnyx can authenticate your integration’s API requests 5 | 2. Install a Client library so your integration can interact with the Telnyx API 6 | 7 | *** 8 | 9 | ## Step 1: Obtain your API keys 10 | 11 | Telnyx authenticates your API requests using your account’s API Key. If you do not include your key when making an API request, or use one that is incorrect or outdated, Telnyx returns an error. 12 | 13 | Your API Keys are available in the ["Auth"](https://portal.telnyx.com/#/app/auth/v2) section of the Portal. Once you create an API Key you must save it for future use. You will only see your API Key once, on creation. 14 | 15 | We include `YOUR_API_KEY` in our code examples. Replace this text with your own API Key. 16 | 17 | If you cannot see your API keys in the Portal, this means you do not have access to them. Only Telnyx account owners can access API Keys. 18 | 19 | 20 | ## Step 2: Install a Client library 21 | 22 | You'll need to ensure that you have DotNet installed on your computer. If DotNet (core or framework) isn’t installed, follow the [official installation instructions](https://dotnet.microsoft.com/download) for your operating system to install it. You can check this by running the following: 23 | 24 | Telnyx targets the [.NET Standard 2.0](https://github.com/dotnet/standard/blob/master/docs/versions/netstandard2.0.md). You should be running a supported verison of dotnet/Xamarin/Mono/Framework to leverage the SDK. 25 | 26 | ```bash 27 | dotnet --version 28 | ``` 29 | 30 | Install the [Telnyx.net SDK](https://github.com/team-telnyx/telnyx-dotnet) by running the following: 31 | 32 | ```bash 33 | dotnet add package Telnyx.net 34 | ``` 35 | 36 | Check out the [dotnet/C# API docs](/docs/api/v2/overview?lang=net), see the source on [GitHub](https://github.com/team-telnyx/telnyx-dotnet), or see Package on [NuGet](https://www.nuget.org/packages/Telnyx.net/) 37 | 38 | ## Send Message Async Example 39 | 40 | The C# SDK supports Task based API calls. 41 | 42 | By updating the Main method to support async calls, we can build a quick example. 43 | 44 | Demo below instanciates the Telnyx client and sends a "Hello, World!" message to the outbound phone number then prints the message ID. 45 | 46 | Be sure to update the `From` & `To` numbers to your Telnyx number and destination phone number respectively. 47 | 48 | ```csharp 49 | using System; 50 | using Telnyx; 51 | using System.Threading.Tasks; 52 | 53 | namespace demo_dotnet_telnyx 54 | { 55 | class Program 56 | { 57 | private static string TELNYX_API_KEY = System.Environment.GetEnvironmentVariable("TELNYX_API_KEY"); 58 | static async Task Main(string[] args) 59 | { 60 | Console.WriteLine("Hello World!"); 61 | TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); 62 | MessagingSenderIdService service = new MessagingSenderIdService(); 63 | NewMessagingSenderId options = new NewMessagingSenderId 64 | { 65 | From = "+19198675309", // alphanumeric sender id 66 | To = "+19198675310", 67 | Text = "Hello, World!" 68 | }; 69 | MessagingSenderId messageResponse = await service.CreateAsync(options); 70 | Console.WriteLine(messageResponse.Id); 71 | } 72 | } 73 | } 74 | ``` 75 | -------------------------------------------------------------------------------- /console-app-messaging/demo-dotnet-telnyx.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | demo_dotnet_telnyx 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /console-app-messaging/sendMessageQS.md: -------------------------------------------------------------------------------- 1 | In this tutorial, you’ll learn how to send SMS and MMS messages using the Telnyx 2 | v2 API 3 | and the [Telnxy.net Library](https://github.com/team-telnyx/telnyx-dotnet). 4 | 5 | --- 6 | 7 | ## Portal Setup 8 | 9 | Follow the [setup guide](/docs/v2/messaging/quickstarts/portal-setup) to 10 | configure your Portal for sending and receiving messages. 11 | 12 | ## Development Environment Setup 13 | 14 | Check out the [Development Environment 15 | Setup](/docs/v2/messaging/quickstarts/dev-env-setup?lang=.net) guide to set up 16 | the Telnyx.net SDK and your development environment for this guide. 17 | 18 | You can paste the below snippets into your Terminal on Mac and Linux computers. 19 | Windows users should install bash on Windows. 20 | 21 | --- 22 | 23 | ## Send an SMS 24 | 25 | Follow the steps below to send SMS messages with dotnet core v3.1+ 26 | 27 | 1. Using the dotnet CLI create a new console application and change directories to the newly created folder. Then add the Telnyx.net package. 28 | 29 | ```bash 30 | $ dotnet new console --output send-sms 31 | $ cd send-sms 32 | $ dotnet add package Telnyx.net 33 | ``` 34 | 35 | 36 | 2. Open the `Program.cs` file created for you in the directory. It should look something like the code below: 37 | 38 | #### Original Program.cs 39 | 40 | ```csharp 41 | using System; 42 | 43 | namespace send_sms 44 | { 45 | class Program 46 | { 47 | static void Main(string[] args) 48 | { 49 | Console.WriteLine("Hello World!"); 50 | } 51 | } 52 | } 53 | 54 | ``` 55 | 56 | 3. Tell the application to use Telnyx.net by adding: `using Telnyx;` before the `namespace` 57 | 58 | 4. In order to use the Asynchronous methods, we need to modify our Main method to return a Task and make it async. 59 | 60 | 4.1. `static void Main(string[] args)` should be `static async Task Main(string[] args)`. 61 | 62 | 4.2. Add `using System.Threading.Tasks;` before the `namespace`. 63 | 64 | 5. Modify the Main method to look something like the following code: 65 | 66 | > **Notes:** 67 | > * Don’t forget to set `YOUR_API_KEY` as an environment variable (or set at runtime) 68 | > * Make sure that the source (`from`) is eligible to send messages towards the destination (`to`) phone number. Read more about this [here](/docs/v2/messaging/features/traffic-type). 69 | > * If sending an alphanumeric message, make sure to specify the `messaging_profile_id` parameter in the body of the request. 70 | 71 | #### Updated Program.cs 72 | 73 | ```csharp 74 | using System; 75 | using Telnyx; 76 | using System.Threading.Tasks; 77 | 78 | namespace send_sms 79 | { 80 | class Program 81 | { 82 | private static string TELNYX_API_KEY = System.Environment.GetEnvironmentVariable("TELNYX_API_KEY"); 83 | private static string telnyxNumber = "+19194150467"; 84 | private static string destinationNumber = "+19198675309"; 85 | 86 | 87 | static async Task Main(string[] args) 88 | { 89 | Console.WriteLine("Hello World!"); 90 | TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); 91 | MessagingSenderIdService service = new MessagingSenderIdService(); 92 | NewMessagingSenderId options = new NewMessagingSenderId 93 | { 94 | From = telnyxNumber, 95 | To = destinationNumber, 96 | Text = "Hello, World!" 97 | }; 98 | try 99 | { 100 | MessagingSenderId messageResponse = await service.CreateAsync(options); 101 | Console.WriteLine(messageResponse.Id); 102 | 103 | } 104 | catch (Exception e) 105 | { 106 | Console.WriteLine(e.Message); 107 | } 108 | } 109 | } 110 | } 111 | ``` 112 | 113 | #### Run the program 114 | 115 | 6. Finally, restore and run the application 116 | 117 | ```bash 118 | $ dotnet restore 119 | $ TELNYX_API_KEY="YOUR_API_KEY" dotnet run 120 | $ TELNYX_API_KEY="YOUR_API_KEY" dotnet run 121 | Hello World! 122 | 4031742c-d288-49f0-b4b9-809931dbd27c 123 | ``` 124 | 125 | > **Notes:** 126 | > * Make sure you’re using the full +E.164 formatted number for your `to` and 127 | > `from` numbers. 128 | > In the US and Canada, this typically means adding +1 to the beginning of your 129 | > 10-digit phone number. 130 | > * The webhook URLs for this message are taken from the messaging profile. 131 | > If you want to override them, use the `webhook_url` and 132 | > `webhook_failover_url` request fields. -------------------------------------------------------------------------------- /console-app-verify/.env.sample: -------------------------------------------------------------------------------- 1 | TELNYX_API_KEY="" 2 | TELNYX_VERIFY_PROFILE_ID="" -------------------------------------------------------------------------------- /console-app-verify/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | // Use IntelliSense to find out which attributes exist for C# debugging 6 | // Use hover for the description of the existing attributes 7 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/bin/Debug/net5.0/Verify.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}", 16 | // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console 17 | "console": "externalTerminal", 18 | "stopAtEntry": false 19 | }, 20 | { 21 | "name": ".NET Core Attach", 22 | "type": "coreclr", 23 | "request": "attach", 24 | "processId": "${command:pickProcess}" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /console-app-verify/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/Verify.csproj", 11 | "/property:GenerateFullPaths=true", 12 | "/consoleloggerparameters:NoSummary" 13 | ], 14 | "problemMatcher": "$msCompile" 15 | }, 16 | { 17 | "label": "publish", 18 | "command": "dotnet", 19 | "type": "process", 20 | "args": [ 21 | "publish", 22 | "${workspaceFolder}/Verify.csproj", 23 | "/property:GenerateFullPaths=true", 24 | "/consoleloggerparameters:NoSummary" 25 | ], 26 | "problemMatcher": "$msCompile" 27 | }, 28 | { 29 | "label": "watch", 30 | "command": "dotnet", 31 | "type": "process", 32 | "args": [ 33 | "watch", 34 | "run", 35 | "${workspaceFolder}/Verify.csproj", 36 | "/property:GenerateFullPaths=true", 37 | "/consoleloggerparameters:NoSummary" 38 | ], 39 | "problemMatcher": "$msCompile" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /console-app-verify/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Telnyx.net.Services.VerifyAPI; 3 | 4 | namespace Verify 5 | { 6 | class Program 7 | { 8 | private static string TELNYX_API_KEY = DotNetEnv.Env.GetString("TELNYX_API_KEY", "VarNotFound"); 9 | private static string TELNYX_VERIFY_PROFILE_ID = DotNetEnv.Env.GetString("TELNYX_VERIFY_PROFILE_ID", "VarNotFound"); 10 | static void Main(string[] args) 11 | { 12 | // DotNetEnv load and paste some of our variables, check if fetching correctly 13 | DotNetEnv.Env.Load(); 14 | if (TELNYX_API_KEY == "VarNotFound" || TELNYX_VERIFY_PROFILE_ID == "VarNotFound") 15 | { 16 | Console.WriteLine("Variable not found, check your .env"); 17 | Environment.Exit(-1); 18 | } 19 | 20 | // Configure Telnyx API Key 21 | Telnyx.TelnyxConfiguration.SetApiKey(TELNYX_API_KEY); 22 | VerificationService verifyService = new VerificationService(); 23 | 24 | GetAppInfo(); // Runs GetAppInfo, generic header ahoy 25 | 26 | Console.WriteLine("Phone Number (+E164 Format) to Verify?: "); 27 | string numberInput = Console.ReadLine(); 28 | 29 | Console.WriteLine(numberInput); 30 | 31 | SendVerificationCode(numberInput); // Sends verification code to specified number 32 | 33 | CodeVerify(numberInput); // Submits verification code 34 | } 35 | 36 | static void PrintColorMessage(ConsoleColor color, string message){ 37 | Console.ForegroundColor = color; 38 | Console.WriteLine(message); 39 | Console.ResetColor(); 40 | } 41 | // Telnyx Header (Arbitrary) 42 | static void GetAppInfo() { 43 | string appName = "Telnyx Console Verify-er"; 44 | string appVersion = "1.0.0"; 45 | 46 | Console.ForegroundColor = ConsoleColor.DarkGreen; 47 | Console.WriteLine("{0}: Version {1}", appName, appVersion); 48 | Console.ResetColor(); 49 | } 50 | 51 | // Telnyx create verification request 52 | static void SendVerificationCode(string numberInput) { 53 | VerificationService verifyService = new VerificationService(); 54 | VerifyOptions verifyOptions = new VerifyOptions 55 | { 56 | PhoneNumber = numberInput, 57 | VerifyProfileId = Guid.Parse(TELNYX_VERIFY_PROFILE_ID), 58 | Type = "sms", 59 | TimeoutSecs = 300, 60 | }; 61 | try 62 | { 63 | verifyService.CreateVerification(verifyOptions); 64 | PrintColorMessage(ConsoleColor.Green, "Verification code sent to " + numberInput); 65 | } 66 | catch (Exception e) 67 | { 68 | PrintColorMessage(ConsoleColor.Red, e.Message); 69 | } 70 | } 71 | 72 | static void CodeVerify (string phoneNumber){ 73 | int attempts = 0; 74 | int maxAttempts = 5; 75 | VerificationService verifyService = new VerificationService(); 76 | while(attempts < maxAttempts){ 77 | //Get input, increment attempts 78 | Console.WriteLine("Verification code?: "); 79 | string inputVerify = Console.ReadLine(); 80 | attempts++; 81 | try 82 | { 83 | VerifyCodeOptions codeOptions = new VerifyCodeOptions 84 | { 85 | Code = inputVerify 86 | }; 87 | var verification = verifyService.SubmitVerificationCode(phoneNumber, codeOptions); 88 | if (verification.ResponseCode == "accepted") 89 | { 90 | PrintColorMessage(ConsoleColor.Green, "Success! Code Verified!"); 91 | break; 92 | } 93 | else 94 | { 95 | PrintColorMessage(ConsoleColor.Red, "Verification failed"); 96 | if (attempts >= maxAttempts){ 97 | PrintColorMessage(ConsoleColor.Red, "Verification max attempts reached"); 98 | } 99 | }; 100 | } 101 | catch (Exception e) 102 | { 103 | PrintColorMessage(ConsoleColor.Red, "Error verifying code"); 104 | Console.WriteLine(e); 105 | } 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /console-app-verify/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # Telnyx C# Getting Started 4 | 5 | ![Telnyx](../logo-dark.png) 6 | 7 | Sample application demonstrating C# SDK Messaging Profile Settings 8 | 9 |
10 | 11 | ## Documentation & Tutorial 12 | 13 | The full documentation and tutorial is available on [developers.telnyx.com](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=dotnet&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 14 | 15 | ## Pre-Reqs 16 | 17 | You will need to set up: 18 | 19 | * [Telnyx Account](https://telnyx.com/sign-up?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) 20 | * [Verifty Profile](https://portal.telnyx.com/#/app/verify/profiles) 21 | * [DotNet Core](https://developers.telnyx.com/docs/v2/development/dev-env-setup?lang=java&utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) installed 22 | 23 | ## What you can do 24 | 25 | * Input phone number to send verification code to 26 | * Verify said number with verification code 27 | 28 | ## Usage 29 | 30 | The following environmental variables need to be set 31 | 32 | | Variable | Description | 33 | |:--------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------| 34 | | `TELNYX_API_KEY` | Your [Telnyx API Key](https://portal.telnyx.com/#/app/api-keys?utm_source=referral&utm_medium=github_referral&utm_campaign=cross-site-link) | 35 | | `TELNYX_VERIFY_PROFILE_ID` | Your [Telnyx Verify Profile Key](https://portal.telnyx.com/#/app/verify/profiles) | 36 | 37 | ### .env file 38 | 39 | This app uses the excellent [dotnet-env](https://github.com/tonerdo/dotnet-env) package to manage environment variables. 40 | 41 | Make a copy of [`.env.sample`](./.env.sample) and save as `.env` and update the variables to match your creds. 42 | 43 | ``` 44 | TELNYX_API_KEY= 45 | TELNYX_VERIFY_PROFILE_ID= 46 | ``` 47 | 48 | ### Install 49 | 50 | Run the following commands to get started 51 | 52 | ``` 53 | $ git clone https://github.com/d-telnyx/demo-dotnet-telnyx.git 54 | ``` 55 | 56 | ### Run 57 | 58 | Open your IDE and run the application 59 | 60 | When the application is started: 61 | * Enter your phone number to send the verification code. 62 | * ⚠️ (Note: You must enter phone number in E.164 format (i.e. +12345678910) for the code to be sent correctly.) 63 | * Receive the verification code 64 | * Enter the code into the console app, you'll have 5 tries to get it right! -------------------------------------------------------------------------------- /console-app-verify/Verify.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Exe 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /logo-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Telnyx-API-DotNet/020c22af0d622686c4d88a34031663afef4991df/logo-dark.png --------------------------------------------------------------------------------