<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: ToeFrog</title>
    <description>The latest articles on Forem by ToeFrog (@toefrog).</description>
    <link>https://forem.com/toefrog</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F560437%2Fd654492a-314c-4768-a475-412a74493eee.png</url>
      <title>Forem: ToeFrog</title>
      <link>https://forem.com/toefrog</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/toefrog"/>
    <language>en</language>
    <item>
      <title>How to use Twilio SMS and Voice with a .NET 6 Minimal API</title>
      <dc:creator>ToeFrog</dc:creator>
      <pubDate>Fri, 25 Feb 2022 12:24:12 +0000</pubDate>
      <link>https://forem.com/twilio/how-to-use-twilio-sms-and-voice-with-a-net-6-minimal-api-12a4</link>
      <guid>https://forem.com/twilio/how-to-use-twilio-sms-and-voice-with-a-net-6-minimal-api-12a4</guid>
      <description>&lt;p&gt;With the release of .NET 6, ASP.NET Core introduced a new feature called &lt;a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis" rel="noopener noreferrer"&gt;Minimal APIs&lt;/a&gt;. Minimal APIs give you the ability to create HTTP APIs with minimal code. This is ideal for developers who want to build applications or microservices with the minimum amount of files and code possible. In this tutorial, you will learn how to build a Minimal API and use it with Twilio to respond to SMS messages and voice calls.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;You will need these items to follow along:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OS that supports .NET (Windows/Mac/Linux)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dotnet.microsoft.com/en-us/download/dotnet/6.0" rel="noopener noreferrer"&gt;.NET 6 SDK&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A code editor or IDE (Recommended: &lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; with &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp" rel="noopener noreferrer"&gt;C# Plugin&lt;/a&gt;, &lt;a href="https://visualstudio.microsoft.com/downloads/" rel="noopener noreferrer"&gt;Visual Studio&lt;/a&gt;, or &lt;a href="https://www.jetbrains.com/rider/" rel="noopener noreferrer"&gt;JetBrains Rider&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;A free Twilio account (If you &lt;a href="https://www.twilio.com/referral/OhKZOM" rel="noopener noreferrer"&gt;register here&lt;/a&gt;, you’ll receive $10 in Twilio credit when you upgrade to a paid account!)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ngrok.com/download" rel="noopener noreferrer"&gt;Install Ngrok&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Web Browser of your choice.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find &lt;a href="https://github.com/ToeFrog/AspNetTwilioMinAPI" rel="noopener noreferrer"&gt;the source code for this tutorial on GitHub&lt;/a&gt;. Use the source code if you run into any issues, or submit an issue on this GitHub repo if you run into problems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get started with Twilio
&lt;/h2&gt;

&lt;p&gt;In order to get started with Twilio, you will need a few things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you don’t already have a Twilio phone number, go and buy a new phone number. &lt;strong&gt;Make sure you keep track of your Twilio phone number to use later on!&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;If you are using a trial Twilio account, you can only send text messages to Verified Caller IDs. Verify your phone number or the phone number you want to SMS if it is not on the list of Verified Caller IDs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Preparing your .NET 6 Minimal API Project
&lt;/h2&gt;

&lt;p&gt;To set up your .NET 6 Minimal API project, you will create a new project using the .NET CLI. In the command line or terminal window, navigate to the folder you want your project to be created in, and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new web &lt;span class="nt"&gt;-o&lt;/span&gt; TwilioMinApi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will create a new empty .NET Web project in a folder called &lt;em&gt;TwilioMinApi&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Navigate to the new folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;TwilioMinApi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Out of the box, your new project will contain one C# file, named &lt;em&gt;Program.cs&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapGet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This program creates a new web application with a single endpoint responding with “Hello World”. You can run this by using the .NET CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a SMS Endpoint
&lt;/h2&gt;

&lt;p&gt;You need to create an endpoint for a POST request called “sms”. This endpoint is where Twilio will send an HTTP request when a message is sent to your Twilio phone number. Our sms endpoint will be configured as the webhook URL in the Twilio Console. Check out &lt;a href="https://www.twilio.com/docs/usage/webhooks" rel="noopener noreferrer"&gt;this article&lt;/a&gt; for a better understanding of webhooks.&lt;/p&gt;

&lt;p&gt;The following code creates an endpoint handling HTTP POST requests to /sms. This endpoint returns &lt;a href="https://www.twilio.com/docs/glossary/what-is-twilio-markup-language-twiml" rel="noopener noreferrer"&gt;TwiML or Twilio Markup Language&lt;/a&gt; to tell Twilio how to respond to the incoming message. You can do this in a number of ways. First, you can simply write the TwiML by hand like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/sms"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;@"
       &amp;lt;Response&amp;gt;
           &amp;lt;Message&amp;gt;Hello from a .NET Minimal API!&amp;lt;/Message&amp;gt;
       &amp;lt;/Response&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"application/xml"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, you create a TwiML response to send back a message that says “Hello from a .NET Minimal API!”. Next, you are telling the application to return the response text as XML. Another way you can achieve this is by using the &lt;a href="https://www.twilio.com/docs/libraries/csharp-dotnet" rel="noopener noreferrer"&gt;Twilio SDK for C# and .NET&lt;/a&gt;. The Twilio SDK has APIs to build the TwiML for us. To add the SDK, you need to add the &lt;a href="https://www.nuget.org/packages/Twilio" rel="noopener noreferrer"&gt;Twilio NuGet package&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can install the NuGet package with the .NET CLI using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package Twilio
dotnet add package Twilio.AspNet.Core
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following using statements at the top of the &lt;em&gt;Program.cs&lt;/em&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Twilio.TwiML&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Twilio.AspNet.Core.MinimalApi&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can write the endpoint this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/sms"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;MessagingResponse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
   &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello from a .NET Minimal API!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Extensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TwiML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run ngrok
&lt;/h2&gt;

&lt;p&gt;In your command prompt or terminal window, start the website using the .NET CLI by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7149
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5118
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running the ngrok CLI tool on your machine will tunnel the local URL to a public URL. Every time you start a new tunnel using ngrok, the subdomain will be different.&lt;/p&gt;

&lt;p&gt;You want to start ngrok using the following command and replacing [YOUR_HTTP_SERVER_URL] with the web server URL starting with &lt;a href="http://localhost" rel="noopener noreferrer"&gt;http://localhost&lt;/a&gt;. In this instance, I will be using port 5118. This will start a new tunnel to a new public URL that you can find in the displayed output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ngrok http &lt;span class="o"&gt;[&lt;/span&gt;YOUR_HTTP_SERVER_URL]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can navigate to one of the &lt;strong&gt;Forwarding URLs&lt;/strong&gt; listed followed by &lt;em&gt;/sms&lt;/em&gt;. Some browsers may warn you that this is a deceptive site, which you can disregard in this case. The browser should return the TwiML that was created by our sms endpoint.&lt;/p&gt;

&lt;p&gt;You can also tunnel HTTPS URLs, but you need to sign up for &lt;a href="https://ngrok.com/" rel="noopener noreferrer"&gt;an ngrok account&lt;/a&gt; (free) and &lt;a href="https://ngrok.com/docs#getting-started-authtoken" rel="noopener noreferrer"&gt;authenticate your ngrok CLI tool&lt;/a&gt;. Once you have done that, you can also run the ngrok https command with the URL starting with &lt;strong&gt;&lt;a href="https://localhost" rel="noopener noreferrer"&gt;https://localhost&lt;/a&gt;&lt;/strong&gt; instead.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Forwarding URL&lt;/strong&gt; that starts with &lt;strong&gt;https&lt;/strong&gt; in the session details is what you will need to configure your phone number in the Twilio Console.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Your Twilio Phone Number
&lt;/h2&gt;

&lt;p&gt;Now you need to configure your Twilio Phone Number, the one you purchased during the &lt;em&gt;Getting Started with Twilio&lt;/em&gt; section, to send HTTP requests to your server. Navigate to Phone Numbers &amp;gt; Manage &amp;gt; Active Numbers. Select the number you purchased earlier. Then scroll down to the Messaging section to configure what happens when a message comes to our Twilio number. Update the section that says &lt;strong&gt;When a Message Comes In&lt;/strong&gt;. Make sure &lt;strong&gt;Webhook&lt;/strong&gt; is selected, and paste your ngrok HTTPS Forwarding followed by &lt;em&gt;/sms&lt;/em&gt; URL in the text box to send webhook HTTP requests to the &lt;em&gt;/sms&lt;/em&gt; endpoint. Make sure the far right drop down has HTTP POST selected, and save your changes to the phone number configuration. Now, try sending a message to your Twilio Phone Number from your cell phone. Did you get a message back saying “Thanks for messaging my dotnet minimal api!”? If so, great job! If not, here are a few things you can check.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Double-check your ngrok URL in the Twilio Console where you configured your Active Number and make sure that you saved your changes.&lt;/li&gt;
&lt;li&gt;Look at your ngrok window to see if your local server received a request.&lt;/li&gt;
&lt;li&gt;Verify that your local project is compiled and running.&lt;/li&gt;
&lt;li&gt;Check the Messages Log tab where you configured your Twilio Phone Number.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create a Voice Endpoint
&lt;/h2&gt;

&lt;p&gt;Creating a voice endpoint is very similar to the SMS endpoint. First, create the voice endpoint writing the TwiML by hand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/voice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;@"
       &amp;lt;Response&amp;gt;
           &amp;lt;Say&amp;gt;Thanks for calling my .NET Minimal API!&amp;lt;/Say&amp;gt;
       &amp;lt;/Response&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"application/xml"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also utilize the Twilio SDK to build the TwiML for you. Both of these code examples will have the same response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/voice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;VoiceResponse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
   &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Say&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Thanks for calling my .NET Minimal API!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Extensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TwiML&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, you need to navigate to Phone Numbers &amp;gt; Manage &amp;gt; Active Numbers. Select the number that you purchased earlier. Then scroll down to the Voice section to configure what happens when a call comes to your Twilio Phone Number. Update the section that says &lt;strong&gt;When a Call Comes In&lt;/strong&gt;. Make sure &lt;strong&gt;Webhook&lt;/strong&gt; is selected and paste your ngrok HTTPS Forwarding followed by &lt;em&gt;/voice&lt;/em&gt; in the text box to send webhook HTTP requests to the &lt;em&gt;/voice&lt;/em&gt; endpoint. Make sure the far right drop down has HTTP POST selected, and save your changes to the phone number configuration. Now, try calling your Twilio Phone Number. You should hear a voice saying “Thanks for calling my dotnet minimal api!”.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;.NET 6 gives us a quick and easy way to set up a minimal API and use it with Twilio to respond to SMS messages and voice calls. If you’re a JavaScript developer and you’ve used the Express framework this should feel very familiar. There is a lot more that you can do with TwiML, check out the &lt;a href="https://www.twilio.com/docs/messaging/twiml" rel="noopener noreferrer"&gt;TwiML Messaging&lt;/a&gt; and &lt;a href="https://www.twilio.com/docs/voice/twiml" rel="noopener noreferrer"&gt;TwiML Voice&lt;/a&gt; docs to learn more!&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Resources
&lt;/h2&gt;

&lt;p&gt;Check out these other great .NET resources on the Twilio Blog!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.twilio.com/blog/send-emails-using-the-sendgrid-api-with-dotnetnet-6-and-csharp" rel="noopener noreferrer"&gt;Send Emails with C# and .NET 6 using the SendGrid API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.twilio.com/blog/send-scheduled-sms-with-csharp-dotnet-and-twilio-programmable-messaging" rel="noopener noreferrer"&gt;Send Scheduled SMS with C# .NET and Twilio Programmable Messaging&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Chris Gargotta is a Developer Evangelist who works primarily with Enterprise Developers at Twilio. Get in touch with Chris on Twitter &lt;a href="https://twitter.com/TheToeFrog" rel="noopener noreferrer"&gt;@TheToeFrog&lt;/a&gt;, find him on &lt;a href="https://twitch.tv/ToeFrog" rel="noopener noreferrer"&gt;Twitch&lt;/a&gt;, and follow Chris’ personal blog at &lt;a href="https://toefrog.com" rel="noopener noreferrer"&gt;ToeFrog.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>twilio</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Gmail Tips to Tame Your Inbox</title>
      <dc:creator>ToeFrog</dc:creator>
      <pubDate>Tue, 10 Aug 2021 21:43:57 +0000</pubDate>
      <link>https://forem.com/toefrog/gmail-tips-to-tame-your-inbox-53b1</link>
      <guid>https://forem.com/toefrog/gmail-tips-to-tame-your-inbox-53b1</guid>
      <description>&lt;h1&gt;
  
  
  Managing Inbox Overload
&lt;/h1&gt;

&lt;p&gt;Managing my inbox is a useful productivity hack that I learned years ago from a &lt;a href="https://www.hanselman.com/blog/the-three-most-important-outlook-rules-for-processing-mail" rel="noopener noreferrer"&gt;blog post&lt;/a&gt; written by &lt;a href="https://twitter.com/shanselman" rel="noopener noreferrer"&gt;Scott Hanselman&lt;/a&gt;. As Scott points out in his post, just because an email comes to your inbox doesn't necessarily mean that it needs your immediate attention. One of the best ways to manage this is by creating rules to automatically sort your email for you. This inbox triage is a great way to easily identify emails that need your attention vs the emails that can wait till later. &lt;/p&gt;

&lt;p&gt;The problem is that this post was written primarily for Outlook users. Outlook gives users the ability to create complex rules and even have those rules processed in a specific order which is great for filtering incoming mail and organizing it into specific folders. However, Gmail doesn't have a notion of subfolders or rules. Gmail uses labels and filters. So how can we utilize these labels and filters to accomplish the same goal?&lt;/p&gt;

&lt;h1&gt;
  
  
  Gmail Filters
&lt;/h1&gt;

&lt;h2&gt;
  
  
  How To Create A Filter
&lt;/h2&gt;

&lt;p&gt;Gmail offers a page showing &lt;a href="https://support.google.com/mail/answer/6579?hl=en" rel="noopener noreferrer"&gt;how to create filters&lt;/a&gt; that are fairly basic. There are also some helpful pages that help you organize your inbox. My issue is that these basic guides do not get me quite to where I want to be. &lt;/p&gt;

&lt;h2&gt;
  
  
  Common Filters
&lt;/h2&gt;

&lt;p&gt;There is also a document that offers a few &lt;a href="https://support.google.com/a/users/answer/9300019?hl=en" rel="noopener noreferrer"&gt;common Gmail filters&lt;/a&gt;. I decided to use a few of these, but there are some categories that I felt were missing from this list. The filters that I decided to use from this list are below. &lt;/p&gt;

&lt;p&gt;To use these filters you can simply copy and paste this into the search box in Gmail.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftoefrog.com%2F_next%2Fimage%3Furl%3Dhttps%253A%252F%252Fimages.ctfassets.net%252Fdjszyqtpyrsk%252F5szATResIk2foGWGU5LBS5%252F624073311e3b65f27dac1295389e4c07%252FScreen_Shot_2021-08-06_at_7.10.25_PM.png%26w%3D3840%26q%3D75" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftoefrog.com%2F_next%2Fimage%3Furl%3Dhttps%253A%252F%252Fimages.ctfassets.net%252Fdjszyqtpyrsk%252F5szATResIk2foGWGU5LBS5%252F624073311e3b65f27dac1295389e4c07%252FScreen_Shot_2021-08-06_at_7.10.25_PM.png%26w%3D3840%26q%3D75" title="Creating filters step 1" alt="creating filters step 1" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Configure and save this filter by clicking on the &lt;em&gt;Show Search Options&lt;/em&gt; button on the right hand side of the cancel button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftoefrog.com%2F_next%2Fimage%3Furl%3Dhttps%253A%252F%252Fimages.ctfassets.net%252Fdjszyqtpyrsk%252F7G92swwRrZmx3vtKl9NKen%252Fc63994864ff7191e816958436d13ab21%252FScreen_Shot_2021-08-06_at_7.12.27_PM.png%26w%3D3840%26q%3D75" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftoefrog.com%2F_next%2Fimage%3Furl%3Dhttps%253A%252F%252Fimages.ctfassets.net%252Fdjszyqtpyrsk%252F7G92swwRrZmx3vtKl9NKen%252Fc63994864ff7191e816958436d13ab21%252FScreen_Shot_2021-08-06_at_7.12.27_PM.png%26w%3D3840%26q%3D75" title="Creating filters step 2" alt="creating filters step 2" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select &lt;em&gt;Create Filter&lt;/em&gt; to create a new filter for your inbox. We also want to create a label to associate these emails with. So we will create a new label called &lt;em&gt;External&lt;/em&gt;. Select the Apply the label checkbox. Then using the drop down select &lt;em&gt;New label…&lt;/em&gt; Enter the name External and click &lt;em&gt;Create&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftoefrog.com%2F_next%2Fimage%3Furl%3Dhttps%253A%252F%252Fimages.ctfassets.net%252Fdjszyqtpyrsk%252F4ImK2HS1WavuXXFDgwEiYI%252F478ca23ebf5f01ffcf3234a7d0ff290d%252FScreen_Shot_2021-08-06_at_7.20.41_PM.png%26w%3D3840%26q%3D75" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftoefrog.com%2F_next%2Fimage%3Furl%3Dhttps%253A%252F%252Fimages.ctfassets.net%252Fdjszyqtpyrsk%252F4ImK2HS1WavuXXFDgwEiYI%252F478ca23ebf5f01ffcf3234a7d0ff290d%252FScreen_Shot_2021-08-06_at_7.20.41_PM.png%26w%3D3840%26q%3D75" title="Creating filters step 3" alt="creating filters step 3" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now all emails that match this filter will be associated with the External label. Choose the option &lt;em&gt;Skip the Inbox (Archive It)&lt;/em&gt; if you would like emails that match this filter to skip your inbox and be categorized using the filter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftoefrog.com%2F_next%2Fimage%3Furl%3Dhttps%253A%252F%252Fimages.ctfassets.net%252Fdjszyqtpyrsk%252F4JJOIfoBFVDidCQje1KDeT%252F95d16d17741cfba9b4765c64d15c27d9%252FScreen_Shot_2021-08-06_at_7.22.14_PM.png%26w%3D3840%26q%3D75" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ftoefrog.com%2F_next%2Fimage%3Furl%3Dhttps%253A%252F%252Fimages.ctfassets.net%252Fdjszyqtpyrsk%252F4JJOIfoBFVDidCQje1KDeT%252F95d16d17741cfba9b4765c64d15c27d9%252FScreen_Shot_2021-08-06_at_7.22.14_PM.png%26w%3D3840%26q%3D75" title="Creating filters step 4" alt="creating filters step 4" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;em&gt;Create filter&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This process can be followed for each of these filters&lt;/p&gt;

&lt;h3&gt;
  
  
  External
&lt;/h3&gt;

&lt;p&gt;Filters email that doesn’t match the entered domain. I use this to identify any emails that are coming from outside the company.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-@domain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Notice the - before the @ symbol. This operator removes those results so it will remove anything that matches &lt;a class="mentioned-user" href="https://dev.to/domain"&gt;@domain&lt;/a&gt;.com&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Calendar
&lt;/h3&gt;

&lt;p&gt;Filters all calendar invites&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;invite.ics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  VIP
&lt;/h3&gt;

&lt;p&gt;Filters emails that come from a specific address. In this case it is being used to filter emails coming from managers or bosses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from:vip@domain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;In order to have the VIP tag apply to multiple emails you can use the OR operator (ex. from:(&lt;a href="mailto:vip1@domain.com"&gt;vip1@domain.com&lt;/a&gt; OR &lt;a href="mailto:vip2@domain.com"&gt;vip2@domain.com&lt;/a&gt;))&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Drive Share
&lt;/h3&gt;

&lt;p&gt;Filters emails that are Google Drive share notifications&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from:drive-shares-dm-noreply@google.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Urgent
&lt;/h3&gt;

&lt;p&gt;Filters emails that have an urgent flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;email+urgent@domain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have also added a few rules that I felt were important but were missing from the common items listed in the Google link above.&lt;/p&gt;

&lt;h3&gt;
  
  
  CC
&lt;/h3&gt;

&lt;p&gt;Filters any email where the address is in the CC&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cc:email@domain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Team
&lt;/h3&gt;

&lt;p&gt;Filters any email where the address is included in the list&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from:(teammate1@domain.com OR teammate2@domain.com OR teammate3@domain.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also have specific filters for emails that come from automated systems such as our helpdesk system or other automated emails that are common.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things to Look Out For
&lt;/h2&gt;

&lt;p&gt;Gmail filters are simply applied to your inbox and showing you the resulting messages that match the search. In order to properly filter your inbox you will most likely want to make sure that your rules exclude items that match other filters.&lt;/p&gt;

&lt;p&gt;For example, if you have a VIP filter and a Calendar filter, any new calendar invite from a VIP will show under both filters. This is not the desired behavior.In order to make sure that VIP calendar invites don't show in both labels, we need to update to the VIP rule to exclude calendar items. To do this we have to add to the filter to exclude calendar invites.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from:vip@domain.com -invite.ics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This update will include items from the vip email while excluding items that are calendar invites. &lt;/p&gt;

&lt;p&gt;Getting all of these filters ironed out may take some tweaking here and there, but having filters that will do some preliminary filtering will hopefully help save you valuable time and effort.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>tutorial</category>
      <category>gmail</category>
    </item>
  </channel>
</rss>
