Build a Group Messaging Application with ASP.NET MVC

February 24, 2014
Written by

Twilio Bug Logo

Back in 2010 we wrote a post that detailed how to build a simple group messaging application with Twilio and ASP.NET MVC. Well a lot has changed in four years and we wanted to update that post, so in this post I’ll show you how you can use the latest versions of Twilio and ASP.NET MVC to build a simple group messaging application.

I’ll show you how to process incoming messages, handle subscribe and unsubscribe requests, and most importantly, forward messages from group members to the rest of the group.

Note that although I’m be using ASP.NET MVC to build my application, the concepts I’m showing can be easily applied to just about other programming language or framework.

Group Messaging Concepts

Our simple group messaging application has three basic concepts: group members, commands and messages. In our app, members can join the group by texting the command START to the groups Twilio phone number. After joining the group, any messages sent to the group number will be forwarded to all of the other members. To leave room for the sender’s number in the forwarded message, messages are limited to 140 characters in length. To leave the group, members can send the command STOP.

As users send messages to the groups Twilio phone number, Twilio will initiate a POST request to my ASP.NET MVC application. It is the job of that application to process those messages, either adding or removing members from the group based on the commands outlined above or broadcasting text messages to group members via the REST API. In either case my application will return a response the the original message sender by responding to Twilio’s POST request with a set of TwiML commands.

The image below show the basic flow of the application: