├── .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 | 
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