-
WhatsApp Media with C#, .NET Core and the Pho.to API
When the WhatsApp API for Twilio launched last year it only supported text.
Not anymore!
The WhatsApp API for Twilio now supports media, including images and files.
So let's build an app that receives an image from WhatsApp, processes the image using one of the many options available on the Pho.to API and then returns the processed image.
What we'll need to get started.
- A Twilio account (sign up for a free Twilio account here)
- The .NET Core 2.2 SDK and runtime
- The WhatsApp Sandbox Channel installed in your account (go through this process to activate the sandbox)
- A developer account on the Pho.to API
- Visual Studio Code or similar code editor or IDE
Create a new folder for your project and navigate into it.
>mkdir PhotoFiddler >cd PhotoFiddler
Once in your new folder, we can make a new .NET Core WebAPI project using the command below ...
-
Send a WhatsApp media message with C# in 30 Seconds
When the Twilio API for WhatsApp was launched in Summer 2018 it could only handle text-based messages. Now, the API can send and receive media 🎉. Sending a media message with WhatsApp is just as quick as sending a text message, here's how in just 30 seconds!
To make this even quicker to get started, below is all the code and a link to the completed project on GitHub.
To code along with this post, make sure the following are set up:
- A Twilio account (sign up for a free Twilio account here)
- The .NET Core 2.2 SDK
- The WhatsApp Sandbox Channel installed (go through this process to activate the sandbox)
After creating a new .NET Console application, add the Twilio NuGet package to the solution. If unsure on how to do this, check out this post.
Open the
Program.cs
file and add in the Twiliousing
statement. Initialise ... -
Build a Video Chat App with ASP.NET Core, Angular, and Twilio
Realtime user interaction is a great way to enhance the communication and collaboration capabilities of a web application. Video chat is an obvious choice for sales, customer support, and education sites, but how can you quickly implement it? Twilio Programmable Video enables you to efficiently add robust video chat to your applications, whether you are using a JavaScript Model-View-Controller framework like Angular or server-side templates.
This post will show you how to create a video chat application using the Twilio JavaScript SDK in your Angular single page application (SPA) and the Twilio SDK for C# and .NET in your ASP.NET Core server code. You’ll build the interactions required to create and join video chat rooms, and to publish and subscribe to participant audio and video tracks.
Prerequisites to a Angular and ASP.NET Core Video App
You’ll need the following technologies and tools to build the video ...
-
Validating Phone Numbers in ASP.NET Core Identity Razor Pages with Twilio Lookup
ASP.NET Core Identity is a membership system that adds login and user functionality to ASP.NET Core apps. It includes many features out of the box and has basic support for storing a phone number for a user. You can improve the robustness of ASP.NET Core’s phone number validation and provide a better user experience by integrating Twilio’s telephony features in your application.
By default the phone number in ASP.NET Core Identity is validated with a regular expression, but that's too basic to confirm whether the number is really valid, whether it includes the country dialling code, or whether it can receive SMS messages. You could implement improved validation using the library libphonenumber-csharp, as described in a previous Twilio blog post. Alternatively you could use various Twilio APIs to thoroughly validate the phone number, lookup details about the number (such as carrier or type), and ...
-
Getting Started with ASP.NET Core Razor Pages
Razor Pages is a new aspect of ASP.NET Core MVC introduced in ASP.NET Core 2.0. It offers a "page-based" approach for building server-side rendered apps in ASP.NET Core and can coexist with "traditional" MVC or Web API controllers. In this post I provide an introduction to Razor Pages, the basics of getting started, and how Razor Pages differs from MVC.
Razor Pages vs MVC
If you've used ASP.NET Core for building server-side rendered apps, then you'll be familiar with the traditional Model-View-Controller (MVC) pattern. Razor Pages provides an abstraction over the top of MVC, which can make it better suited to some page-based apps.
In MVC, controllers are used to group similar actions together. When a request is received, routing directs the request to a single action method. This method typically performs some processing, and returns an
IActionResult
, commonly aViewResult
or aRedirectResult
. If ... -
Generating music with Python and Neural Networks using Magenta for TensorFlow
Machine Learning is all the rage these days, and with open source frameworks like TensorFlow developers have access to a range of APIs for using machine learning in their projects. Magenta, a Python library built by the TensorFlow team, makes it easier to process music and image data in particular.
Since I started learning how to code, one of the things that has always fascinated me was the concept of computers artificially creating music. I even published a paper talking about it in an undergrad research journal my freshman year of college.
Let's walk through the basics of setting up Magenta and programmatically generating some simple melodies in MIDI file format.
Installing Magenta
First we need to install Magenta, which can be done using pip. Make sure you create a virtual environment before installing. I am using Python 3.6.5, but Magenta is compatible with both Python 2 and ...
-
Using Dependency Injection with Twilio SMS and ASP.NET Core 2.1
ASP.NET Core is built with first-class support for dependency injection (DI). It's used heavily by the framework, but you can also use it with your own classes. The Twilio C# helper libraries are largely
static
, so you don't have to use DI, but sometimes you might want to. For example, you might want to create a customTwilioRestClient
that uses theHttpClientFactory
features of .NET Core 2.1. In this post, I describe how to create a customITwilioRestClient
, register it with the ASP.NET Core DI container, and inject it into a web API controller, so you can use it to send an SMS.Prerequisites
To follow along with this post you'll need:
- A Twilio account (sign up for a free Twilio account here)
- .NET Core 2.1 SDK (version 2.1.300 or greater)
- VS Code, Visual Studio, or other editor
- Postman for testing your API
You ...
-
Texting emojis and non-Latin characters with C#, .NET and Twilio SMS
As technology expands the reach of our products and services it’s important for us to create content to suit users from all over the world. As we primarily use Latin characters for programming, creating content for languages like Japanese or Arabic that have a different alphabet is not as easy as typing them on a standard keyboard. This post will show you how to send non-Latin characters, including emoji, in text messages with C# and Twilio Programmable SMS.
Prerequisites
You should have the following tools installed to complete the program described in this post:
- Windows 7 or Windows 10
- Basic knowledge of C# and .NET
- Visual Studio 2017 or Visual Studio Code
- Microsoft .NET Core SDK, which includes the .NET Runtime
Why UTF-8?
The problem started when people realized that the character encoding standard of the time, ASCII, needed to be extended to accommodate the alphabets of other languages ...
-
Use Azure Functions and Twilio SMS to know: Will it Rain Today?
Will you need an umbrella today? Don't know? That's easy to fix by looking out the window or by using Azure Functions and its Twilio SMS output binding. In this post, I'll show you how with just a few lines of code you can have a text message arrive each morning which lets you know if it might rain that day.
You can build along with me by signing up for free Azure and free Twilio accounts.
Create an Azure Function
We'll start by creating a new Azure Function App in the Azure Portal.
Once created continue configuring the Function App by adding environment variables to hold our Twilio credentials. Open the Applications Settings for the Function App.
Add two new keys named
TwilioAccountSid
andTwilioAuthToken
, setting their values to your Twilio AccountSid and AuthToken respectively. You can find your Twilio credentials in the Twilio Console.Save the Application Settings ...
-
Translator via SMS with C# and Azure Functions
Ahoy and yo-ho-ho! In celebration o' International Talk Like A Pirate Day, let's build a SMS Pirate Speak translator with Azure Functions, the Fun Translations API and, of course, Twilio.
What you’ll need:
- A Twilio account (sign up for a free Twilio account here)
- An SMS enabled Twilio number (find one here)
- An Azure account (sign up for a free Azure account here)
- Optional: pieces o' eight!
Azure Functions allow you to write code without having to worry about infrastructure or servers, so they are perfect for setting up a simple webhook for an incoming SMS or call from Twilio.
Create an Azure Function
From the Azure portal, click the Create a resource button, found at the top of the menu on the left. Search for a Serverless Function App and then click on the matching result.
Give your app a name, I called mine
twilio-sms-translator
, create or reuse ...