/// <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());
        }
    }
Example #2
0
        public TwilioResponse Message(string body, string[] mediaUrls, object attributes)
        {
            var message = new Message(attributes);
            Current.Push(message);

            if (!string.IsNullOrEmpty(body)) { Add(new Body(body)); }

            foreach (var m in mediaUrls)
            {
                Add(new Media(m));
            }

            Add(Current.Pop());

            return this;
        }
Example #3
0
 public MessagingResponse Message(Message message)
 {
     this.Append(message);
     return(this);
 }