Exemple #1
0
        public ActionResult Recieve([FromUri] SMS.SMSInbound response)
        {
            if (null != response.to && null != response.msisdn)
            {
                //Write the incoming message
                Debug.WriteLine("From: " + response.msisdn);
                Debug.WriteLine(" Message: " + response.text);
                Debug.WriteLine(" ");

                //send the message in UDP
                string IPAd = "127.0.0.1";
                int    port = 5677;

                byte[] packetData = System.Text.ASCIIEncoding.ASCII.GetBytes(response.msisdn + response.text);

                IPEndPoint ep     = new IPEndPoint(IPAddress.Parse(IPAd), port);
                Socket     client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                client.SendTo(packetData, ep);

                return(new HttpStatusCodeResult(200));
            }
            else
            {
                return(new HttpStatusCodeResult(200));
            }
        }
Exemple #2
0
 public ActionResult Receive([FromQuery] SMS.SMSInbound response)
 {
     if (null != response.to && null != response.msisdn)
     {
         Debug.WriteLine("------------------------------------");
         Debug.WriteLine("INCOMING TEXT");
         Debug.WriteLine("From: " + response.msisdn);
         Debug.WriteLine(" Message: " + response.text);
         Debug.WriteLine("------------------------------------");
         return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status200OK));
     }
     else
     {
         Debug.WriteLine("------------------------------------");
         Debug.WriteLine("Endpoint was hit.");
         Debug.WriteLine("------------------------------------");
         return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status200OK));
     }
 }
 public ActionResult Receive([FromUri] SMS.SMSInbound response)
 {
     if (null != response.to && null != response.msisdn)
     {
         Debug.WriteLine("------------------------------------");
         Debug.WriteLine("INCOMING TEXT");
         Debug.WriteLine("From: " + response.msisdn);
         Debug.WriteLine(" Message: " + response.text);
         Debug.WriteLine("------------------------------------");
         return(new HttpStatusCodeResult(200));
     }
     else
     {
         Debug.WriteLine("------------------------------------");
         Debug.WriteLine("Endpoint was hit.");
         Debug.WriteLine("------------------------------------");
         return(new HttpStatusCodeResult(200));
     }
 }
Exemple #4
0
        public ActionResult Validate([FromQuery] SMS.SMSInbound response)
        {
            var queryDictionary            = HttpContext.Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString());
            var signatureString            = SMS.SMSInbound.ConstructSignatureStringFromDictionary(queryDictionary);
            var NEXMO_SECRET_SIGNATURE_KEY = "NEXMO_SECRET_SIGNATURE_KEY";
            var method  = SmsSignatureGenerator.Method.md5hash;
            var testSig = SmsSignatureGenerator.GenerateSignature(signatureString, NEXMO_SECRET_SIGNATURE_KEY, method);
            var match   = response.sig == testSig;

            if (match)
            {
                Debug.WriteLine("Valid Signature");
            }
            else
            {
                Debug.WriteLine("Invalid Signature");
            }

            return(StatusCode(StatusCodes.Status200OK));
        }
Exemple #5
0
        public ActionResult Get([FromUri] SMS.SMSInbound response)
        {
            // Upon initial setup with Nexmo, this action will be tested up to 5 times. No response data will be included. Just accept the empty request with a 200.
            if (null == response.to && null == response.msisdn)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            lock (_cacheLock)
            {
                var          receipts = new List <SMS.SMSInbound>();
                const string cachekey = "sms_inbounds";
                if (MemoryCache.Default.Contains(cachekey))
                {
                    receipts = (List <SMS.SMSInbound>)MemoryCache.Default.Get(cachekey);
                }
                receipts.Add(response);
                MemoryCache.Default.Set(cachekey, receipts, DateTimeOffset.MaxValue);
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public ActionResult Get([FromQuery] SMS.SMSInbound response)
        {
            // Upon initial setup with Nexmo, this action will be tested up to 5 times. No response data will be included. Just accept the empty request with a 200.
            if (null == response.to && null == response.msisdn)
            {
                return(new OkResult());
            }

            lock (_cacheLock)
            {
                List <SMS.SMSInbound> receipts;
                const string          cachekey = "sms_inbounds";
                _cache.TryGetValue(cachekey, out receipts);
                if (null == receipts)
                {
                    receipts = new List <SMS.SMSInbound>();
                }
                receipts.Add(response);
                _cache.Set(cachekey, receipts, DateTimeOffset.MaxValue);
            }

            return(new OkResult());
        }
 public IActionResult ReceiveMessage([FromQuery] SMS.SMSInbound response)
 {
     _chatHub.Clients.All.SendAsync("ReceiveMessage", response.msisdn, response.text);
     return(StatusCode(204));
 }
Exemple #8
0
 public HttpStatusCode InboundSms([FromQuery] SMS.SMSInbound inboundMessage)
 {
     _ = Questioner.AskQuestion(inboundMessage.msisdn, inboundMessage.to, "sms", inboundMessage.text, _config);
     return(HttpStatusCode.NoContent);
 }