public ActionResult Index(SmsRequest request)
    {
        var counter = 0;

        // get the session varible if it exists
        if (Session["counter"] != null)
        {
            counter = (int) Session["counter"];
        }

        // increment it
        counter++;

        // save it
        Session["counter"] = counter;

        // make an associative array of senders we know, indexed by phone number
        var people = new Dictionary<string, string>()
        {
            {"+14158675309", "Rey"},
            {"+14158675310", "Finn"},
            {"+14158675311", "Chewy"}
        };

        // if the sender is known, then greet them by name
        var name = "Friend";
        if (people.ContainsKey(request.From))
        {
            name = people[request.From];
        }

        var response = new TwilioResponse();
        response.Message($"{name} has messaged {request.To} {counter} times");
        return TwiML(response);
    }
        public TwilioResponse ResponseToSms(SmsRequest request)
        {
            var response = new TwilioResponse();

              try
              {
            string outboundPhoneNumber = request.From;

            var client = new TwilioRestClient(accountSid, authToken);

            var call = client.InitiateOutboundCall(
              twilioPhoneNumber,
              outboundPhoneNumber,
              "http://refuniteivr.azurewebsites.net/api/IVREntry");

            if (call.RestException == null)
            {
              response.Sms("starting call to " + outboundPhoneNumber);
            }
            else
            {
              response.Sms("failed call to " + outboundPhoneNumber + " " + call.RestException.Message);
            }

            return response;
              }
              catch (Exception ex)
              {
            response.Sms("exception: " + ex.Message);
            return response;
              }
        }
 public ActionResult Index(SmsRequest request)
 {
     var response = new TwilioResponse();
     response.Message("The Robots are coming! Head for the hills!",
         new [] { "https://farm8.staticflickr.com/7090/6941316406_80b4d6d50e_z_d.jpg" },
         null);
     return TwiML(response);
 }
 public ActionResult Index(SmsRequest request)
 {
     // Log the message id and status
     var logMessage = "\"" + request.SmsSid + "\", " +
                      "\"" + request.MessageStatus + "\"";
     Trace.WriteLine(logMessage);
     return Content("Handled");
 }
 public ActionResult Index(SmsRequest request)
 {
     var response = new TwilioResponse();
       if(request.body == "hello")
       {
     response.Message("Hi!");
       }
       else if(request.body == "bye")
       {
     response.Message("Goodbye");
       }
       return TwiML(response);
 }
        public TwiMLResult ReceiveText(SmsRequest request)
        {
            var response = new TwilioResponse()
                .Sms(string.Format("Hello from {0}, {1}. Hope you're enjoying the session!",
                        request.FromCity,
                        request.FromState));

            _textReceiver.ReceiveText(new TextData
            {
                Body = string.Format("{0}, {1}: {2}",
                        request.FromCity,
                        request.FromState,
                        request.Body),
                City = request.FromCity,
                ZipCode = request.FromZip
            });

            return new TwiMLResult(response);
        }
 private HttpResponseMessage GetResponse(SmsRequest req)
 {
     try
     {
         using (TreasureContext db = new TreasureContext())
         {
             User user = _userService.GetUserFromPhoneNo(req.From, db);
             if (user==null) return Request.CreateResponse(HttpStatusCode.OK, IDontKnowYou().Element, new XmlMediaTypeFormatter());
             TwilioResponse result = _storyTellerService.ReadStory(user, req.Body, req.To);
             db.SaveChanges();
             return Request.CreateResponse(HttpStatusCode.OK, result.Element, new XmlMediaTypeFormatter());
         }
     }
     catch (Exception e)
     {
         TwilioResponse resp = new TwilioResponse();
         resp.Say(e.Message);
         return Request.CreateResponse(HttpStatusCode.OK, resp.Element, new XmlMediaTypeFormatter());
     }
 }
        public HttpResponseMessage Incoming(SmsRequest message)
        {
            var response = new TwilioResponse();

            var parsedMessage = message.Body.ToLower().Trim();

                switch (parsedMessage)
                {
                    case "play":
                        if (GameManager.IsPlaying(message.From) && !GameManager.GameInProgress)
                        {
                            response.Sms("You're already in the game...");
                        }
                        else if (!GameManager.GameInProgress)
                        {
                            response.Sms("Entering the game...");
                            GameManager.AddToGame(message.From);
                        }
                        else
                        {
                            response.Sms("Sorry, please wait until game is over.");
                        }
                        break;
                    case "wat":
                        response.Sms(
                            "This game is the brain-child of Kevin Griffin.  Follow Kevin on Twitter at http://twitter.com/1kevgriff");
                        response.Sms("You can also email Kevin at [email protected]");
                        break;
                    default:
                        if (GameManager.GameInProgress)
                        {
                            GameManager.ProcessRequest(message.From, message.Body, response);
                        }
                        else
                            response.Sms("I want to play a game.  Text 'play' to get in the game.");
                        break;
                }

            return Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter());
        }
Beispiel #9
0
        public TwilioResponse ManageSms(SmsRequest request)
        {
            int controlNumber;
            string type;
            if (Int32.TryParse(request.Body, out controlNumber))
            {
                switch (controlNumber)
                {
                    case 1:
                    case 2:
                    case 3:
                        var materials = new AvailableMaterials();
                        type = materials.GetTop3MaterialsForId(1)[controlNumber-1];
                        break;
                    default:
                        throw new Exception("Response contained other characters that were not numbers");
                        break;
                }
            }
            else
            {
                //TODO:Handle This prettier
                throw new Exception("Response contained other characters that were not numbers");
            }
            //TODO: Save The information of what type is and create and output for it.

            var blockBlob = CloudBlockBlob();
            byte[] byteArray = Encoding.UTF8.GetBytes(type);

            using (var stream = new MemoryStream(byteArray))
            {
                blockBlob.UploadFromStream(stream);
            }

            //System.IO.File.WriteAllText("holdData.txt", type);
            var re = new TwilioResponse();
            re.Sms("Message Received");
            return re;
        }
 public ActionResult Index(SmsRequest request)
 {
     var response = new TwilioResponse();
     response.Message("The Robots are coming! Head for the hills!");
     return TwiML(response);
 }
Beispiel #11
0
        public ActionResult Sms(SmsRequest request)
        {
            var response = new TwilioResponse();

            string[] validNumbers = new string[] { "+18508032974", "+13237071329" };

            if (!validNumbers.Contains<string>(request.From))
            {
                response.Sms("Hi, I'm not allowed to talk to strangers. Please visit http://dareme.to.");
                return new TwiMLResult(response);
            }

            string[] parsed=request.Body.Split(new char[] { ' ' });
            if (parsed==null || parsed.Length < 2)
            {
                response.Sms("That's not a valid command. :-/");
                return new TwiMLResult(response);
            }

            DareManager dareMgr = new DareManager();

            switch (parsed[0].ToUpper())
            {
                case "MOD":
                    dareMgr.Takedown(Convert.ToInt64(parsed[1]));
                    break;
                default:
                    response.Sms("That's not a valid command. :-\\");
                    break;
            }

            return new TwiMLResult(response);
        }
Beispiel #12
0
        public HttpResponseMessage ProcessVoiceTicketRequest(SmsRequest twilioRequest)
        {
            var invalidRequestMessage = "We could not understand the key you entered.";

            var error = false;
            var message = default(String);
            var responseContext = default(ConversationContext);
            var conversationState = ConvoCookieHelper.Parse<ConversationState>(ConvoCookieHelper.CONVO_COOKIE_NAME_PHONE, Request.Headers);

            if (conversationState == null)
                conversationState = new ConversationState() { ConversationStep = 1, ConversationName = twilioRequest.Body ?? "voice" };

            var conversation = ConversationRegistry.Get(conversationState.ConversationName);

            if(conversation != null)
            {
                try
                {
                    responseContext = conversation.RunStep(conversationState, twilioRequest.Body ?? "voice");
                    message = responseContext.ResponseMessage;
                }
                catch(Exception ex)
                {
                    message = invalidRequestMessage;
                    error = true;
                    //clearCookie = true;
                }
            }
            else
            {
                message = invalidRequestMessage;
                error = true;
            }

            var twilioResponse = new TwilioResponse();

            if (responseContext.Gather)
            {
                twilioResponse.BeginGather(new { finishOnKey = "#", action = "/api/twilio/voicecontinuation" })
                    .Say(message)
                    .EndGather();
            }
            else
            {
                twilioResponse.Say(message);
            }
            
            var response = TwilioHelper.WrapTwilioResponseInHttpResponse(this, twilioResponse);

            if(conversation.ConvoEnded(conversationState.ConversationStep))
            {
                ConvoCookieHelper.EndConvoCookie(ConvoCookieHelper.CONVO_COOKIE_NAME_PHONE, response.Headers);
            }
            else if (!error)
            {
                // update cookie
                var newCookie = ConvoCookieHelper.GetCookieHeaderValue(ConvoCookieHelper.CONVO_COOKIE_NAME_PHONE, new ConversationState()
                {
                    Context = responseContext,
                    ConversationName = conversationState.ConversationName,
                    ConversationStep = conversationState.ConversationStep + 1
                });

                response.Headers.AddCookies(new CookieHeaderValue[] { newCookie });
            }

            return response;
        }
 public ActionResult Index(SmsRequest request)
 {
     return View();
 }
 public HttpResponseMessage Post(SmsRequest request)
 {
     TwilioResponse response = smsLogic.ResponseToSms(request);
       return this.Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter());
 }