예제 #1
0
        private static void MergeAndSend(Event e, MessageTemplate template)
        {
            if (e.Status == EventStatus.InActive)
            {
                throw new ArgumentException("Cannot send an inactive event");
            }

            object templateObject = GetTemplateObject(e);


            if (template == null)
            {
                throw new ArgumentNullException("Could not find a message template for the given media and type");
            }

            MergeToTemplate(e, template, templateObject);
            bool   overrideUnsubscribe = template.Type == MessageTemplateType.RECALL;
            string uniqueSendId        = CommunicationsService.Send(e, template, overrideUnsubscribe);

            if (!string.IsNullOrWhiteSpace(uniqueSendId))
            {
                if (e.Status == EventStatus.ToSend)
                {
                    RemoveScheduledEvent(e);
                }
                UpdateEventStatus(e, uniqueSendId);
                using (var service = new EventService())
                {
                    service.Update(e);
                }
            }
        }
예제 #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);
            }
        }
예제 #3
0
        public static List <TwilioGatherOption> GetGatherOptions(MessageTemplateType type)
        {
            List <MessageResponseOption> respOpts = CommunicationsService.GetResponseOptions(type);

            respOpts = respOpts.FindAll(o => { return(!string.IsNullOrWhiteSpace(o.LongDescription)); });

            //Func<string, string, object>[] handlerFuncs = null;

            var opts = new List <TwilioGatherOption>();

            for (int i = 0; respOpts != null && i < respOpts.Count; i++)
            {
                TwilioGatherOption opt = new TwilioGatherOption()
                {
                    Digits         = i.ToString(),
                    Description    = respOpts[i].LongDescription,
                    ResponseOption = respOpts[i]
                };
                opts.Add(opt);
            }

            return(opts);
        }