public async Task<TwiMLResult> Index(string ServiceKey, string From, string To, string Body, string SmsSid)
        {
            var msg = "From: " + From + "\r\n" + Body;
            var pdEvent = new PagerDutyEvent() {
                service_key = ServiceKey,
                event_type = "trigger",
                description = msg.Substring(0,Math.Min(1024, msg.Length))
            };

            var tResp = new TwilioResponse();
            try
            {
                using (var response = await _httpclient.PostAsJsonAsync<PagerDutyEvent>("https://events.pagerduty.com/generic/2010-04-15/create_event.json", pdEvent))
                {
                    
                    if (response.IsSuccessStatusCode)
                    {
                        tResp.Sms("PagerDuty incident created.");
                    }
                    else
                    {
                        tResp.Sms("failed to create PagerDuty incident - statusCode " + response.StatusCode.ToString());
                    }
                }
            }
            catch
            {
                tResp.Sms("failed to create PagerDuty incident");
            }
            return new TwiMLResult(tResp);
        }
Beispiel #2
0
        public async Task<ActionResult> Index(string from, string body)
        {
            var request = new LightsRequest
            {
                Source = "twilio",
                From = from,
                Text = body
            };

            var lightsResponse = await _lightsService.HandleRequestAsync(request);

            var response = new TwilioResponse();

            if (_smsSettings.AllowResponses && lightsResponse.IsSuccess)
            {
                if (lightsResponse.IsScheduled && lightsResponse.ScheduledForUtc.HasValue)
                {
                    response.Sms(string.Format("Ooops, you're in a queue! Don't worry, your lights have been scheduled for {0}. Merry Christmas from #157!",
                        lightsResponse.ScheduledForUtc.Value.ToString("HH:mm")));
                }
                else
                {
                    response.Sms("Thanks! Your lights will be shown shortly. Merry Christmas from #157!");                    
                }
            }

            return new TwiMLResult(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(VoiceRequest request)
 {
     var response = new TwilioResponse();
     response.Say("Hello! You will get an SMS message soon.");
     response.Sms("This is the ship that made the Kessel Run in fourteen parsecs?");
     return TwiML(response);
 }
 public HttpResponseMessage Incoming()
 {
     var twilioResponse = new TwilioResponse();
     twilioResponse.Sms("Hello");
     SendEmail(null, null);
     return Request.CreateResponse(HttpStatusCode.OK, twilioResponse.Element);
 }
        public ActionResult txt1(SmsRequest request)
        {
            Demo.LogNumber(request);

            var response = new TwilioResponse();
            response.Sms(string.Format("You said '{0}'", request.Body));

            Demo.Log("{0} says '{1}'", request.From, request.Body);

            return TwiML(response);
        }
        public ActionResult chuck(SmsRequest request)
        {
            Demo.LogNumber(request);

            var roundhouse = ChuckNorris.API.Random(null, new string[] { "explicit" });
            var joke = roundhouse.Result.Text;

            var response = new TwilioResponse();
            response.Sms(joke);

            Demo.Log("{0} got roundhoused '{1}'", request.From, joke);

            return TwiML(response);
        }
        public HttpResponseMessage Incoming(SMSMessage sms)
        {
            var cnam = TelcoData.TelcoData.GetExchange(sms.From);

            var message = String.Format("Hello {0}, how is {1}, {2} today?", sms.Status, cnam.City,
                                        cnam.State);
            var response = new TwilioResponse();
            try
            {
                SendEmail(sms, cnam);
            }
            catch (Exception ex)
            {
                response.Sms(ex.Message);
            }

            return Request.CreateResponse(HttpStatusCode.OK, response.Element);
        }
        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 #10
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 #11
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;
        }
Beispiel #12
0
        public HttpResponseMessage ProcessTicketRequest(SMSMessage twilioRequest)
        {
            var invalidRequestMessage = "We could not understand your text.";

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

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

            // Get Conversation by name
            var conversation = ConversationRegistry.Get(conversationState.ConversationName);

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

            var twilioResponse = new TwilioResponse();

            twilioResponse.Sms(message);

            var response = TwilioHelper.WrapTwilioResponseInHttpResponse(this, twilioResponse);

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

            return response;
        }
Beispiel #13
0
 //
 // GET: /Sms/
 public ActionResult Index()
 {
     var twiml = new TwilioResponse();
     twiml.Sms("Hello World");
     return TwiML(twiml);
 }
Beispiel #14
0
        public static void ProcessRequest(string fromNumber, string body, TwilioResponse response)
        {
            var player = Players.FirstOrDefault(p => p.PhoneNumber.Equals(fromNumber));
            if (player == null)
            {
                response.Sms("You're not playing the game...");
                return;
            }

            if (player.GuessedWord.Equals(player.CurrentWord, StringComparison.InvariantCultureIgnoreCase))
            {
                response.Sms("You've already won.  Good for you!");
                return;
            }

            var checkWrongGuesses = player.PreviousGuesses.Count - player.CurrentWord.Count(p => player.PreviousGuesses.Contains(p));
            if (checkWrongGuesses >= 5)
            {
                response.Sms("You already lost.. sorry!");
                return;
            }

            var guess = body.Trim().ToUpper();
            if (guess.Length > 1)
            {
                response.Sms("No way, buddy. SINGLE CHARACTERS ONLY");
                return;
            }

            if (player.PreviousGuesses.Any(p => p.Equals(guess[0])))
            {
                response.Sms("You already guessed that letter.");
                return;
            }

            StringBuilder newGuessed = new StringBuilder(player.GuessedWord);
            bool foundLetter = false;
            for (var x = 0; x < player.CurrentWord.Length; x++)
            {
                if (player.CurrentWord[x] == guess[0])
                {
                    foundLetter = true;
                    newGuessed[x] = guess[0];
                }
            }
            player.PreviousGuesses.Add(guess[0]);
            player.GuessedWord = newGuessed.ToString();

            if (player.GuessedWord.Equals(player.CurrentWord, StringComparison.InvariantCultureIgnoreCase))
            {
                response.Sms("WINNER!  Your word was " + player.CurrentWord);
                player.Score++;
            }
            else
            {
                if (foundLetter)
                {
                    response.Sms($"Yes!  Found the {guess[0]}." + Environment.NewLine + "Guess again: " +
                                 player.GuessedWord);
                }
                else
                {
                    var wrongGuesses = player.PreviousGuesses.Count - player.CurrentWord.Count(p => player.PreviousGuesses.Contains(p));

                    if (wrongGuesses >= 5)
                    {
                        response.Sms("SORRY!  You lose.  Your word was " + player.CurrentWord);
                    }
                    else
                    {
                        response.Sms($"Nope, sorry.  No {guess[0]}'s" + Environment.NewLine + "Guess again: " +
                                     player.GuessedWord);
                    }
                }
            }
        }