public RequestHandle CreateRequest(ServiceRequest instance) { // process the new request RequestHandle reqHandle = commLogic.HandleNewRequest(instance); if (null != reqHandle) { // add it to the store instance.Handle = reqHandle; requestStore.Add(reqHandle.Id, instance); } return reqHandle; }
public RequestHandle HandleNewRequest(ServiceRequest request) { Debug.Assert(null != request); if (request.Channel == ChannelChoice.EMAIL_EMAIL) { return twoWayEmail(request); } else if (request.Channel == ChannelChoice.EMAIL_DOODLE) { return emailToDoodle(request); } else if (request.Channel == ChannelChoice.TWILIO) { return twilioComm(request); } return null; }
public void Add(string requestId, ServiceRequest newRequest) { if ((null != newRequest) && (null != requestId)) { requestDict.Add(requestId, newRequest); } }
public ServiceRequest UpdateOrDelete(string id, ServiceRequest instance, string method) { if ((null != method)) { // implement update as delete + insert requestStore.Delete(id); } if ((null != method) && method.Equals("update") && (null != instance)) { requestStore.Add(id, instance); return instance; } return null; }
private RequestHandle twoWayEmail(ServiceRequest request) { Debug.Assert(null != request); Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add(QUESTION_KEY, request.Question); parameters.Add(EMAIL_FORM_SUFFIX_KEY, "TwoWayEmail"); return new RequestHandle { Id = sendEmailMessage(request, parameters), Channel = request.Channel, Metadata = null }; }
private RequestHandle twilioComm(ServiceRequest request) { // start a phone call to the request recipient twilioClient.MakeCall(request.Recipient, request.Subject, request.Question); return null; }
private string sendEmailMessage(ServiceRequest request, Dictionary<string, string> parameters) { // for two-way email, we can generate random IDs string requestId = generateNewId(); // construct a mail message from the service request MailMessage newMsg = new MailMessage( mailClient.Smtp.Credentials.GetCredential(mailClient.Smtp.Host, mailClient.Smtp.Port, "SSL").UserName, request.Recipient); newMsg.Subject = request.Subject + "[id=" + requestId + "]"; newMsg.Body = constructEmailMsgBody(request, parameters); newMsg.IsBodyHtml = true; // send the mail message : for now, keep it simple with a synchronous send. Make it async later mailClient.Smtp.Send(newMsg); return requestId; }
private RequestHandle emailToDoodle(ServiceRequest request) { // set up a Doodle poll CreatePollResponse createPollResponse = createDoodlePoll(request); string doodlePollUrl; if (null == createPollResponse) { // TODO: handle this: for now, continue with a dummy url doodlePollUrl = doodleClient.ConstructUrl("ErrorPollId"); } else { doodlePollUrl = doodleClient.ConstructUrl(createPollResponse.PollId); } // send an email message with the link to the poll Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add(DOODLE_LINK_KEY, doodlePollUrl); parameters.Add(EMAIL_FORM_SUFFIX_KEY, "EmailToDoodle"); sendEmailMessage(request, parameters); return new RequestHandle { Id = createPollResponse.PollId, Channel = request.Channel, Metadata = createPollResponse.PollKey }; }
/// <summary> /// returns an ID for the constructed Doodle poll /// </summary> /// <param name="request"></param> /// <returns></returns> private CreatePollResponse createDoodlePoll(ServiceRequest request) { PollType newPoll = new PollType(PollTypeType.TEXT, false, "Please answer this!", "2", request.Question); newPoll.initiator = new InitiatorType(); newPoll.initiator.name = "Praveen"; newPoll.options = new OptionsTypeOption[3]; newPoll.options[0] = new OptionsTypeOption(); newPoll.options[0].Value = "Three?"; newPoll.options[1] = new OptionsTypeOption(); newPoll.options[1].Value = "Four?"; newPoll.options[2] = new OptionsTypeOption(); newPoll.options[2].Value = "Five?"; CreatePollResponse createPollResponse = doodleClient.CreatePoll(newPoll); return createPollResponse; ; }
private string constructEmailMsgBody(ServiceRequest request, Dictionary<string, string> parameters) { string msgBody; string emailFormSuffix = parameters[EMAIL_FORM_SUFFIX_KEY]; Debug.Assert(null != emailFormSuffix); string myFormFilename = HostingEnvironment.MapPath(@"/App_Data/EmailForm." + emailFormSuffix + ".htm"); if (null != myFormFilename) { // open the file msgBody = File.ReadAllText(myFormFilename); if (null != msgBody) { foreach (var entry in parameters) { // TODO: pravse: yes it is grungy to use the parameters to also pass the form name. msgBody = msgBody.Replace("%%"+entry.Key+"%%", entry.Value); } } } else { msgBody = request.Question; } return msgBody; }