Ejemplo n.º 1
0
        public ActionResult OnPost()
        {
            string sFrom    = Request.Form["From"];
            string sBody    = Request.Form["Body"];
            var    oMessage = new Twilio.TwiML.MessagingResponse();

            if (aUsers == null)
            {
                aUsers = new Dictionary <string, User>();
            }
            if (!aUsers.ContainsKey(sFrom))
            {
                aUsers[sFrom] = new User();
            }
            oMessage.Message(aUsers[sFrom].OnMessage(sBody));
            return(Content(oMessage.ToString(), "application/xml"));
        }
    /// <summary>
    /// Messages the received.
    /// </summary>
    private void MessageReceived()
    {
        var request = _context.Request;

        string fromPhone = string.Empty;
        string toPhone   = string.Empty;
        string body      = string.Empty;

        if (!string.IsNullOrEmpty(request.Form["To"]))
        {
            toPhone = request.Form["To"];
        }

        if (!string.IsNullOrEmpty(request.Form["From"]))
        {
            fromPhone = request.Form["From"];
        }

        if (!string.IsNullOrEmpty(request.Form["Body"]))
        {
            body = request.Form["Body"];
        }

        Twilio.TwiML.Message twilioMessage = null;
        if (toPhone.IsNotNullOrWhiteSpace() && fromPhone.IsNotNullOrWhiteSpace())
        {
            twilioMessage = ProcessMessage(request, toPhone, fromPhone, body);
        }

        if (twilioMessage != null)
        {
            var messagingResponse = new Twilio.TwiML.MessagingResponse();
            messagingResponse.Message(twilioMessage);

            var response = _context.Response;
            response.ContentType = "application/xml";

            response.Write(messagingResponse.ToString());
        }
    }