Beispiel #1
0
        private static string GetTextOptions(List <MessageResponseOption> options)
        {
            options = options.FindAll(o => { return(!(string.IsNullOrWhiteSpace(o.Verb) || string.IsNullOrWhiteSpace(o.ShortDescription))); });
            if (options.Count == 0)
            {
                return("");
            }

            StringBuilder sb = new StringBuilder(" Reply with ");

            for (int i = 0; i < options.Count; i++)
            {
                MessageResponseOption opt = options[i];
                sb.Append(opt.Verb.ToUpper());
                sb.Append(" to ");
                sb.Append(opt.ShortDescription);
                if (i + 1 < options.Count)
                {
                    sb.Append(", ");
                }
                else
                {
                    sb.Append(".");
                }
            }
            return(sb.ToString());
        }
Beispiel #2
0
        public static void HandleSMSResponse(string fromNumber, string fromBody, string messageSid)
        {
            string responseString = "";

            //unsubscribe
            if (twilioUnsubscribeVerbs.Find(v => v.ToLower().Equals(fromBody)) != null)
            {
                Patient p = GetPatientFromPhone(fromNumber);
                if (p != null)
                {
                    responseString = EventProcessingService.UnsubscribePatient(p);
                }
            }

            //subscribe
            if (twilioSubscribeVerbs.Find(v => v.ToLower().Equals(fromBody)) != null)
            {
                Patient p = GetPatientFromPhone(fromNumber);
                if (p != null && p.ContactPreference == ContactPreference.NONE)
                {
                    responseString = EventProcessingService.Subscribe(p);
                }
            }

            //system-specific responses
            if (responseString.Length == 0)
            {
                List <Event> openEvents = GetOpenSMSEventsFor(fromNumber);

                foreach (Event e in openEvents)
                {
                    MessageTemplateType          templateType = EventProcessingService.GetTemplateType(e);
                    List <MessageResponseOption> opts         = CommunicationsService.GetResponseOptions(templateType);
                    MessageResponseOption        opt          = opts.Find(o => { return(o.Verb.ToLower().Equals(fromBody)); });

                    var response = EventProcessingService.HandleResponse(opt, e);
                    if (response.GetType() == typeof(string))
                    {
                        responseString = (string)response;
                    }
                }
            }

            if (responseString.Length > 0)
            {
                SendSMSMessage(fromNumber, responseString);
            }
            else
            {
                throw new ArgumentException("Unexpected response: " + fromBody + " from message: " + messageSid);
            }
        }
Beispiel #3
0
        private static string GetUnsubscribeHTML(Event e, List <MessageResponseOption> options)
        {
            MessageResponseOption unsubscriber = options.Find(o => o.ShortDescription != null && o.ShortDescription.ToLower().Equals(unsubscribeKeyword));

            if (unsubscriber == null)
            {
                return("");
            }
            string url        = GetURL(unsubscriber, e);
            string htmlString = "Don't want to hear from " + e.Patient.Pharmacy.Name + "? | <a href=\"" + url + "\" >Unsubscribe</a>";

            return(htmlString);
        }
Beispiel #4
0
        public static object HandleResponse(MessageResponseOption opt, Event e)
        {
            if (opt == null)
            {
                return(null);
            }
            string name = opt.CallbackFunction;

            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }
            object[] paramArray = new object[] { e };
            var      result     = (typeof(EventProcessingService)).GetMethod(name).Invoke(null, paramArray);

            return(result);
        }
Beispiel #5
0
 private static string GetURL(MessageResponseOption opt, Event e)
 {
     return(ExternalUrl + relativeEmailUrl + "optCode=" + opt.Code + "&eventCode=" + e.Code);;
 }