Exemplo n.º 1
0
        public async Task <IActionResult> Get([FromQuery] string body)
        {
            var spotify = new SpotifyClient(SPOTIFY_ID, SPOTIFY_SECRET);
            var song    = await spotify.GetSong(body);

            var messagingResponse = new MessagingResponse();

            if (song == null)
            {
                messagingResponse.Message("Sending back a sample message since Spotify couldn't find our results!");
            }
            else
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.AppendLine($"Artist: {song["artist"].ToString()}");
                stringBuilder.AppendLine($"Title: {song["title"].ToString()}");
                var previewUrl = song["previewUrl"].ToString();
                if (string.IsNullOrEmpty(previewUrl))
                {
                    stringBuilder.AppendLine("Sorry we couldn't find a preview. But try visiting Spotify to listen to the full track");
                }
                else
                {
                    stringBuilder.AppendLine($"Here's the preview: {previewUrl}");
                }
                var message = new Message();
                message.Body(stringBuilder.ToString());
                message.Media(new Uri(song["image"].ToString()));
                messagingResponse.Append(message);
            }

            return(new ContentResult {
                Content = messagingResponse.ToString(), ContentType = "application/xml"
            });
        }
Exemplo n.º 2
0
        // GET: Sms
        public ActionResult ReceiveSms(string From, string Body)
        {
            var response = new MessagingResponse();
            var message  = new Message();

            message.Body($"Harvest{From}. Plus{Body}");
            response.Append(message);
            // response.Redirect(url: new Uri(""));
            return(TwiML(response));
        }
        public async Task <IActionResult> PostSmsRequest()
        {
            var response = new MessagingResponse();
            var msg      = new Message();

            msg.Body("SO you reached this eh... You shouldn't have");

            response.Append(msg);
            return(await Task.FromResult(Content(response.ToString(), "application/xml")));
        }
Exemplo n.º 4
0
    static void Main()
    {
        var response = new MessagingResponse();
        var message  = new Message();

        message.Body("Store Location: 123 Easy St.");
        message.Media(new Uri("https://demo.twilio.com/owl.png"));
        response.Append(message);

        Console.WriteLine(response.ToString());
    }
    static void Main()
    {
        var response = new MessagingResponse();
        var message  = new Message();

        message.Body("Hello World!");
        response.Append(message);
        response.Redirect(url: new Uri("https://demo.twilio.com/welcome/sms/"));

        Console.WriteLine(response.ToString());
    }
Exemplo n.º 6
0
    static void Main()
    {
        var response = new MessagingResponse();
        var message  = new Message();

        message.Body("Hello Jenny");
        message.Media(new Uri("https://demo.twilio.com/owl.png"));
        response.Append(message);

        Console.WriteLine(response.ToString());;
    }
Exemplo n.º 7
0
        public ActionResult Index()
        {
            var response = new MessagingResponse();
            var message  = new Message();

            message.Body("Hello World!");
            response.Append(message);
            response.Redirect(url: new Uri("https://demo.twilio.com/welcome/sms/"));

            return(View(response));
        }
Exemplo n.º 8
0
        public HttpResponseMessage PostMessage([FromBody] TwilioMessagingRequest messagingRequest)
        {
            var message =
                $"Your text to me was {messagingRequest.Body.Length} characters long. " +
                "Webhooks are neat :)";

            var response = new MessagingResponse();

            response.Append(new Message(message));

            return(ToResponseMessage(response.ToString()));
        }
Exemplo n.º 9
0
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            var twilioResponse = new MessagingResponse();

            twilioResponse.Append(new Message("Thanks for sending your request. We will reply to your request shortly"));

            return(new ContentResult {
                Content = twilioResponse.ToString(), ContentType = "application/xml"
            });
        }
Exemplo n.º 10
0
        public MessagingResponse ResponseSMS()
        {
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
            TwilioClient.Init(accountSid, authToken);

            var response = new MessagingResponse();
            var message  = new Message();

            message.Body("Hello World!");
            response.Append(message);
            //response.Redirect(url: new Uri("http://tchapi.thecloudhealth.com/API/Sms/GenTwiML?Text='hii sameer, How are you?'"));
            return(response);
        }
Exemplo n.º 11
0
        private MessagingResponse GenerateTwilioResponse(WhatsappResponse response)
        {
            var twiml        = new MessagingResponse();
            var twimlMessage = new Message();

            twimlMessage.Body(response.ResponseMessage);
            if (!string.IsNullOrEmpty(response.ImageUrl))
            {
                twimlMessage.Media(new Uri(response.ImageUrl));
            }
            twiml.Append(twimlMessage);
            return(twiml);
        }
Exemplo n.º 12
0
        //When Message comes from Twilio this method will be fired. [site url]/Webhooks/Index
        public TwiMLResult Index(SmsRequest incomingMessage)
        {
            SaveIncomingWhatsappMessage(incomingMessage);
            var response = SmartReply(incomingMessage);

            if (response != null)
            {
                var messagingResponse = new MessagingResponse();
                messagingResponse.Append(response);
                SaveSmartReplyMessage(response.BodyAttribute);

                return(TwiML(messagingResponse));
            }
            return(null);
        }
Exemplo n.º 13
0
        public async Task <IActionResult> Get([FromQuery] string body)
        {
            var yummly = new YummlyClient(Configuration["YummlyAppId"], Configuration["YummlyAppKey"]);
            var recipe = await yummly.GetRecipe(body);

            var json = JObject.Parse(recipe);

            var response = new MessagingResponse();
            var message  = new Message();

            message.Body($"Here's your recipe.\nName: {json["Name"].ToString()}\nCook Time:{json["TotalTime"].ToString()}\nRecipe URL:{json["RecipeUrl"].ToString()}\n\n{json["Attribution"].ToString()}");
            message.Media(new Uri(json["ImageUrl"].ToString()));
            response.Append(message);

            return(new ContentResult {
                Content = response.ToString(), ContentType = "application/xml"
            });
        }
Exemplo n.º 14
0
        public async Task <APIGatewayProxyResponse> ReceiveSmsAsync(APIGatewayProxyRequest proxyRequest, ILambdaContext context)
        {
            Dictionary <string, string> payload = QueryHelpers.ParseQuery(proxyRequest.Body)
                                                  .ToDictionary(pair => pair.Key, pair => pair.Value.FirstOrDefault());

            LogJson(new
            {
                Event     = "Request",
                RequestId = context.AwsRequestId,
                Headers   = proxyRequest.Headers,
                Body      = proxyRequest.Body,
                Message   = payload["Body"],
                Payload   = payload,
            });

            DisableRuleRequest request = new DisableRuleRequest
            {
                Name = SendEventRuleId,
            };
            await CweClient.DisableRuleAsync(request);

            MessagingResponse response = new MessagingResponse();
            Message           message  = new Message(body: "Waker Upper stopped!");

            response.Append(message);
            string responseBody = response.ToString();

            LogJson(new
            {
                Event     = "Response",
                RequestId = context.AwsRequestId,
                Body      = responseBody,
            });

            return(new APIGatewayProxyResponse
            {
                StatusCode = (int)System.Net.HttpStatusCode.OK,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", "application/xml" },
                },
                Body = responseBody,
            });
        }
Exemplo n.º 15
0
        public HttpResponseMessage GenTwiML(string Text)
        {
            var response = new MessagingResponse();
            var res      = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var message = new Message();
                message.Body(Text);
                response.Append(message);
                File.WriteAllText(HttpContext.Current.Server.MapPath("~/XML/voice.xml"), response.ToString(), Encoding.ASCII);
                res.Content = new StringContent(response.ToString(), Encoding.UTF8, "text/xml");
                return(res);
            }
            catch (Exception)
            {
                return(res);
            }
        }
Exemplo n.º 16
0
        public TwiMLResult Create(FormCollection formCollection)
        {
            var numMedia = int.Parse(formCollection["NumMedia"]);

            var response = new MessagingResponse();

            if (numMedia > 0)
            {
                var message = new Message();
                message.Body("Thanks for the image! Here's one for you!");
                message.Media(GOOD_BOY_URL);
                response.Append(message);
            }
            else
            {
                response.Message("Send us an image!");
            }

            return(TwiML(response));
        }
Exemplo n.º 17
0
        public void IndexWithAnImage_SendsBackAnImage()
        {
            // Arrange
            string requestData = "{\n  \"MediaContentType0\": \"image/jpeg\",\n  \"SmsMessageSid\": \"MM19df5a6293470c5e309890648740986a\"," +
                                 "\n  \"NumMedia\": \"1\",\n  \"SmsSid\": \"MM19df5a6293470c5e309890648740986a\",\n  \"SmsStatus\": \"received\",\n  " +
                                 "\"Body\": \"\",\n  \"To\": \"whatsapp:+14155238886\",\n  \"NumSegments\": \"1\",\n  " +
                                 "\"MessageSid\": \"MM19df5a6293470c5e309890648740986a\",\n  \"AccountSid\": \"AC4ee8a4bf66c95837fc46316395718baa\",\n  " +
                                 "\"From\": \"whatsapp:+5213321678083\",\n  " +
                                 "\"MediaUrl0\": \"https://api.twilio.com/2010-04-01/Accounts/AC4ee8a4bf66c95837fc46316395718baa/Messages/MM19df5a6293470c5e309890648740986a/Media/ME456a12de2891e2a69bc11a23aab6b9c5\",\n  " +
                                 "\"ApiVersion\": \"2010-04-01\",\n  \"ALL_HTTP\": \"HTTP_CACHE_CONTROL:max-age=259200\\r\\nHTTP_CONNECTION:close\\r\\nHTTP_CONTENT_LENGTH:540\\r\\nHTTP_CONTENT_TYPE:application/x-www-form-urlencoded\\r\\nHTTP_ACCEPT:*/*\\r" +
                                 "\\nHTTP_HOST:localhost:8081\\r\\nHTTP_USER_AGENT:TwilioProxy/1.1\\r\\nHTTP_X_FORWARDED_FOR:54.225.17.109\\r\\nHTTP_X_ORIGINAL_HOST:b924869a.ngrok.io\\r\\nHTTP_X_TWILIO_SIGNATURE:WctwS3sxSyuCNpIBxIRYE0sCYpY=\\r\\n\",\n  " +
                                 "\"ALL_RAW\": \"Cache-Control: max-age=259200\\r\\nConnection: close\\r\\nContent-Length: 540\\r\\nContent-Type: application/x-www-form-urlencoded\\r\\nAccept: */*\\r" +
                                 "\\nHost: localhost:8081\\r\\nUser-Agent: TwilioProxy/1.1\\r\\nX-Forwarded-For: 54.225.17.109\\r\\nX-Original-Host: b924869a.ngrok.io\\r" +
                                 "\\nX-Twilio-Signature: WctwS3sxSyuCNpIBxIRYE0sCYpY=\\r\\n\",\n  \"APPL_MD_PATH\": \"/LM/W3SVC/3/ROOT\",\n  " +
                                 "\"APPL_PHYSICAL_PATH\": \"C:\\\\Users\\\\Jose Oliveros\\\\source\\\\repos\\\\WhatsappMediaTutorial\\\\WhatsappMediaTutorial\\\\\",\n  \"AUTH_TYPE\": \"\",\n  \"AUTH_USER\": \"\",\n  " +
                                 "\"AUTH_PASSWORD\": \"\",\n  \"LOGON_USER\": \"\",\n  \"REMOTE_USER\": \"\",\n  \"CERT_COOKIE\": \"\",\n  \"CERT_FLAGS\": \"\",\n  \"CERT_ISSUER\": \"\",\n  \"CERT_KEYSIZE\": \"\",\n  " +
                                 "\"CERT_SECRETKEYSIZE\": \"\",\n  \"CERT_SERIALNUMBER\": \"\",\n  \"CERT_SERVER_ISSUER\": \"\",\n  \"CERT_SERVER_SUBJECT\": \"\",\n  \"CERT_SUBJECT\": \"\",\n  " +
                                 "\"CONTENT_LENGTH\": \"540\",\n  \"CONTENT_TYPE\": \"application/x-www-form-urlencoded\",\n  \"GATEWAY_INTERFACE\": \"CGI/1.1\",\n  \"HTTPS\": \"off\",\n  \"HTTPS_KEYSIZE\": \"\",\n  " +
                                 "\"HTTPS_SECRETKEYSIZE\": \"\",\n  \"HTTPS_SERVER_ISSUER\": \"\",\n  \"HTTPS_SERVER_SUBJECT\": \"\",\n  \"INSTANCE_ID\": \"3\",\n  \"INSTANCE_META_PATH\": \"/LM/W3SVC/3\",\n  " +
                                 "\"LOCAL_ADDR\": \"::1\",\n  \"PATH_INFO\": \"/WhatsAppMedia/Create\",\n  " +
                                 "\"PATH_TRANSLATED\": \"C:\\\\Users\\\\Jose Oliveros\\\\source\\\\repos\\\\WhatsappMediaTutorial\\\\WhatsappMediaTutorial\\\\WhatsAppMedia\\\\Create\",\n  \"QUERY_STRING\": \"\",\n  " +
                                 "\"REMOTE_ADDR\": \"::1\",\n  \"REMOTE_HOST\": \"::1\",\n  \"REMOTE_PORT\": \"50371\",\n  \"REQUEST_METHOD\": \"POST\",\n  \"SCRIPT_NAME\": \"/WhatsAppMedia/Create\",\n  " +
                                 "\"SERVER_NAME\": \"localhost\",\n  \"SERVER_PORT\": \"8081\",\n  \"SERVER_PORT_SECURE\": \"0\",\n  \"SERVER_PROTOCOL\": \"HTTP/1.1\",\n  \"SERVER_SOFTWARE\": \"Microsoft-IIS/10.0\",\n  " +
                                 "\"URL\": \"/WhatsAppMedia/Create\",\n  \"HTTP_CACHE_CONTROL\": \"max-age=259200\",\n  \"HTTP_CONNECTION\": \"close\",\n  \"HTTP_CONTENT_LENGTH\": \"540\",\n  " +
                                 "\"HTTP_CONTENT_TYPE\": \"application/x-www-form-urlencoded\",\n  \"HTTP_ACCEPT\": \"*/*\",\n  \"HTTP_HOST\": \"localhost:8081\",\n  \"HTTP_USER_AGENT\": \"TwilioProxy/1.1\",\n  " +
                                 "\"HTTP_X_FORWARDED_FOR\": \"54.225.17.109\",\n  \"HTTP_X_ORIGINAL_HOST\": \"b924869a.ngrok.io\",\n  \"HTTP_X_TWILIO_SIGNATURE\": \"WctwS3sxSyuCNpIBxIRYE0sCYpY=\"\n}";

            var rawParams      = JsonConvert.DeserializeObject <Dictionary <string, string> >(requestData);
            var _params        = new NameValueCollection();
            var formCollection = new FormCollection();

            foreach (var pair in rawParams)
            {
                _params.Add(pair.Key, pair.Value);
                formCollection.Add(pair.Key, pair.Value);
            }

            var request = new Mock <HttpRequestBase>();

            request.SetupGet(x => x.Params).Returns(_params);
            var context = new Mock <HttpContextBase>();

            context.SetupGet(x => x.Request).Returns(request.Object);

            var controllerMock = new Mock <WhatsAppMediaController>()
            {
                CallBase = true
            };

            // Mock WebClient
            var webClientMock = new Mock <SystemWebClient>();

            webClientMock.Setup(w => w.DownloadFile(It.IsAny <string>(), It.IsAny <string>()));
            controllerMock.Setup(c => c.webClient()).Returns(webClientMock.Object);

            controllerMock.Object.ControllerContext = new ControllerContext(context.Object, new RouteData(), controllerMock.Object);

            // Act
            TwiMLResult result = controllerMock.Object.Create(formCollection)
                                 as TwiMLResult;

            var response = new MessagingResponse();
            var message  = new Message();

            message.Body("Thanks for the image! Here's one for you!");
            message.Media(WhatsAppMediaController.GOOD_BOY_URL);
            response.Append(message);

            var expectedTwimlResult = new TwiMLResult(response);

            // Assert
            Assert.AreEqual(expectedTwimlResult.Data.ToString(), result.Data.ToString());
        }
Exemplo n.º 18
0
        public MessagingResponse GetResponse(string messageBody, string messagePhone)
        {
            //Recoit Un message et le numero de telephone, Si le message correspont au norme et est trouver,
            //un MessageStatus.Closed/MessageStatus.Follow  est appliquer sinon envoie un erreur

            var answer = new Message();

            if (messageBody.Length > 5 &&
                (messageBody.ToUpper().StartsWith(_InputMessages[0]) || messageBody.ToUpper().StartsWith(_InputMessages[1])))
            {
                string flight_id = messageBody.ToUpper().Substring(5);
                if (Regex.IsMatch(flight_id, NotificationApp.NumVolRegex))
                {
                    Notification notif = DB2.Aeroport().Notifications.SingleOrDefault(m => m.Num_Phone == messagePhone);

                    MessageStatus status = (notif != null) ? MessageStatus.Closed : MessageStatus.Error;
                    string        result = MessageDistributor(status, notif);
                    answer.Body(result);

                    //If status is Closed then set to True
                    if (status == MessageStatus.Closed)
                    {
                        db.Entry(notif).Property(u => u.Statut).CurrentValue = true;
                    }
                }
                else
                {
                    answer.Body(MessageDistributor(MessageStatus.Error));
                }
            }
            else if (messageBody.Length > 5 &&
                     (messageBody.ToUpper().StartsWith(_InputMessages[2]) || messageBody.ToUpper().StartsWith(_InputMessages[3])))
            {
                string flight_id = messageBody.ToUpper().Substring(5);
                if (Regex.IsMatch(flight_id, NotificationApp.NumVolRegex))
                {
                    Notification notif = db.Notifications.SingleOrDefault(m => m.Num_Phone == messagePhone);

                    MessageStatus status = (notif != null) ? MessageStatus.Followed : MessageStatus.Error;
                    string        result = MessageDistributor(status, notif);
                    answer.Body(result);

                    //If status is Followed then set to False
                    if (status == MessageStatus.Followed)
                    {
                        db.Entry(notif).Property(u => u.Statut).CurrentValue = false;
                    }
                }
                else
                {
                    answer.Body(MessageDistributor(MessageStatus.Error));
                }
            }
            else
            {
                answer.Body(MessageDistributor(MessageStatus.Error));
            }


            var messageResponce = new MessagingResponse();

            messageResponce.Append(answer);
            return(messageResponce);
        }