void SetupRoutes()
{
//this route is unique to Twilio to help them know where to send the data from the incoming SMS message
Post["/message/TwiML"] =
_ =>
{
const string url = "/message";
return @"<?xml version=""1.0"" encoding=""UTF-8""?><Response><Redirect>" + url +
"</Redirect></Response>";
};
Post["/message"] =
_ =>
{
//new message coming in
var incomingMessage = this.Bind<IncomingMessage>();
if (string.IsNullOrEmpty(incomingMessage.Body))
{
return Response.AsJson(new { Error = "'Body' was null." });
}
if (string.IsNullOrEmpty(incomingMessage.From))
{
return Response.AsJson(new { Error = "'From' was null." });
}
incomingMessage.Received = SystemDateTime.Now();
//decide what to do with the message here
_incominMessageProcessor.Process(incomingMessage);
//always return a successful response
return Response.AsJson(new {Status = "Ok"});
};
}
}