Ejemplo n.º 1
0
        public async Task ChangeName(IDialogContext context, LuisResult result)
        {
            List <EntityRecommendation> nameEntities = null;

            if (result.TryFindEntities("Name", out nameEntities))
            {
                var name     = "";
                var nameList = nameEntities.ConcatEntities(" ").Split(' ').ToList <string>();
                nameList.ForEach(str =>
                {
                    name += string.Concat(str[0].ToString().ToUpper(), str.Substring(1), " ");
                });
                name = name.Trim();

                // attempt to save applicant info
                var a = await ApplicantFactory.GetApplicantByContext(context);

                a.Name = name;
                await ApplicantFactory.PersistApplicant(a);

                await context.PostAsync(string.Format(Resources.msgIWillCallYou, name));

                context.Done <string>(null);
            }
            else
            {
                // prompt for the user's name
                PromptDialog.Text(context, ResumeAfterNameChangeAsync, Resources.msgWhatShouldICallYou);
            }
        }
        public async Task None(IDialogContext context, LuisResult result)
        {
            var textAnalyticsClient = new TextAnalyticsClient(ConfigurationManager.AppSettings["CognitiveServices_TextAnalyticsKey"]);
            var sentiment           = await textAnalyticsClient.GetSentimentForTextAsync(result.Query);

            // attempt to obtain applicant info
            var a = await ApplicantFactory.GetApplicantByContext(context);

            var app = a.Applications.First().Value;

            app.SentimentData.Add(new Common.Models.Sentiment()
            {
                AdvisorContacted = false,
                SentimentScore   = sentiment,
                SentimentTaken   = DateTime.Now
            });
            await ApplicantFactory.PersistApplicant(a);

            if (sentiment < 0.45)
            {
                PromptDialog.Text(context, ResumeAfterEmailPromptAsync, string.Format("I'm sorry to hear that. Would you like me to email your recruiter, {0}, so that you can discuss the matter?", app.Recrutier.Name));
            }
            else if (sentiment >= 0.45 && sentiment <= 0.75)
            {
                await context.PostAsync(string.Format("Ok. Contact your recruiter, {0}, if there is anything you would like to discuss regarding your placement.", app.Recrutier.Name));

                context.Done <string>(null);
            }
            else
            {
                await context.PostAsync("Great! That's good to hear. I'll check back in with you toward the end of your contract.");

                context.Done <string>(null);
            }
        }
Ejemplo n.º 3
0
        private static async Task SendCalendarInvite(IDialogContext context, ScheduleInterviewForm state)
        {
            Applicant a = null;

            context.UserData.TryGetValue <Applicant>("applicant", out a);
            var applicationKey = a.Applications.Keys.First();

            a.Applications[applicationKey].Interview = state.ChoosenDate;
            a.Applications[applicationKey].State     = ConversationType.None;
            await ApplicantFactory.PersistApplicant(a);

            await context.PostAsync($"Please click here to add the invitation to your calendar: http://x-bot-first-class.azurewebsites.net/api/ics?apptDateTime={state.ChoosenDate:s}");

            context.Done <string>(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Callback for name change.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        private async Task ResumeAfterNameChangeAsync(IDialogContext context, IAwaitable <string> result)
        {
            var name = await result;

            if (!string.IsNullOrEmpty(name))
            {
                // attempt to save applicant info
                var a = await ApplicantFactory.GetApplicantByContext(context);

                a.Name = name;
                await ApplicantFactory.PersistApplicant(a);

                await context.PostAsync(string.Format(Resources.msgIWillCallYou, name));

                context.Done <string>(null);
            }
        }
Ejemplo n.º 5
0
        public async Task <HttpResponseMessage> ApplicantAccepted(string phoneNumber, string jobId)
        {
            if (string.IsNullOrEmpty(phoneNumber) || string.IsNullOrEmpty(jobId))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            // find application
            Application app = null;
            Applicant   a   = await ApplicantFactory.GetApplicantByPhone(phoneNumber);

            if (a == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            if (!a.Applications.Keys.Contains(jobId))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            app = a.Applications[jobId];

            if (!phoneNumber.StartsWith("+"))
            {
                phoneNumber = string.Concat("+", phoneNumber);
            }
            var payload = new MessagePayload()
            {
                FromId = ConfigurationManager.AppSettings["Twilio_PhoneNumber"],
                ToId   = phoneNumber,
                Text   = string.Format("Hello, {0}. This is Rachel from Express. It is my pleasure to inform you that you have been accepted for the position '{1}' at {2}. I'd like to walk you through filling out your IRS W-4 form. We are required to get this information from you before you can start your position. To get started, please add me to your contacts in skype.",
                                       a.Name, app.Title, app.Company),
                ServiceUrl = ConfigurationManager.AppSettings["BotFramework_SmsServiceUrl"]
            };
            var credentials = new MicrosoftAppCredentials(ConfigurationManager.AppSettings["MicrosoftAppId"], ConfigurationManager.AppSettings["MicrosoftAppPassword"]);
            var response    = await Bot.SendMessage(payload, credentials);

            app.State = ConversationType.FillOutW4;
            await ApplicantFactory.PersistApplicant(a);

            // save the conversation state so when the recipient responds we know in what context they replied in
            app.State = ConversationType.FillOutW4;
            await ApplicantFactory.PersistApplicant(a);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Ejemplo n.º 6
0
        public async Task <HttpResponseMessage> FirstDayReview(string phoneNumber, string jobId)
        {
            if (string.IsNullOrEmpty(phoneNumber) || string.IsNullOrEmpty(jobId))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            // find application
            Application app = null;
            Applicant   a   = await ApplicantFactory.GetApplicantByPhone(phoneNumber);

            if (a == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            if (!a.Applications.Keys.Contains(jobId))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            app = a.Applications[jobId];

            if (!phoneNumber.StartsWith("+"))
            {
                phoneNumber = string.Concat("+", phoneNumber);
            }
            var payload = new MessagePayload()
            {
                FromId     = ConfigurationManager.AppSettings["Twilio_PhoneNumber"],
                ToId       = phoneNumber,
                Text       = string.Format("Hello, {0}!. This is Rachel from Express. How was your first day at {1}?", a.Name, app.Company),
                ServiceUrl = ConfigurationManager.AppSettings["BotFramework_SmsServiceUrl"]
            };
            var credentials = new MicrosoftAppCredentials(ConfigurationManager.AppSettings["MicrosoftAppId"], ConfigurationManager.AppSettings["MicrosoftAppPassword"]);
            var response    = await Bot.SendMessage(payload, credentials);

            // save the conversation state so when the recipient responds we know in what context they replied in
            app.State = ConversationType.FirstDayReview;
            await ApplicantFactory.PersistApplicant(a);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        /// <summary>
        /// Resumes the after email prompt asynchronous.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        private async Task ResumeAfterEmailPromptAsync(IDialogContext context, IAwaitable <string> result)
        {
            var response = await result;

            if (Regex.Match(response, "(Yes|yes|yea|yeah|ok|sure)").Success)
            {
                // attempt to obtain applicant info
                var a = await ApplicantFactory.GetApplicantByContext(context);

                var app = a.Applications.First().Value;
                app.SentimentData.Last().AdvisorContacted = true;
                await ApplicantFactory.PersistApplicant(a);

                await context.PostAsync(string.Format("Ok. I have sent {0} an email and you should be contacted soon.", app.Recrutier.Name));

                context.Done <string>(null);
            }
            else
            {
                await context.PostAsync("Ok. If you would like to discuss this in the future, please do not hesitate to reach out to us.");

                context.Done <string>(null);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Builds the conversation form.
        /// </summary>
        /// <returns>IForm instance.</returns>
        public static IForm <W4Info> BuildForm()
        {
            OnCompletionAsyncDelegate <W4Info> processW4 = async(context, state) =>
            {
                Applicant a = null;
                context.UserData.TryGetValue <Applicant>("applicant", out a);
                if (a == null)
                {
                    throw new ArgumentNullException("applicant");
                }
                a.W4Info = state;
                a.Applications.First().Value.State = Common.ConversationType.None;
                context.UserData.SetValue <Applicant>("applicant", a);
                await ApplicantFactory.PersistApplicant(a);

                await context.PostAsync("Please hold a moment while I create your form...");

                string W4Uri = FillW4Dialog.FillForm(a);
                //IMessageActivity m = context.MakeMessage();
                //m.Attachments.Add(new Attachment()
                //{
                //    ContentUrl = W4Uri,
                //    ContentType = "application/pdf",
                //    Name = "w4.pdf"
                //});
                //m.Text = "Please save this form for future reference!Thanks and I hope we'll talk again soon.";
                //try
                //{
                //    await context.PostAsync(m);
                //}
                //catch (Exception ex) {
                //    Exception e = ex;
                //    throw;
                //}
                await context.PostAsync($"You can find your W4 at {W4Uri}. Please save this form for future reference!Thanks and I hope we'll talk again soon.");

                context.Done <Applicant>(a);
            };

            IForm <W4Info> b = new FormBuilder <W4Info>()
                               .Message($"Ok, let's fill out the W4 form. I'll ask you some question, simply type the answers and I'll assemble the form.")
                               .Message("We'll start by confirming some basic information about you.")
                               .Field(nameof(W4Info.FirstName))
                               .Field(nameof(W4Info.LastName))
                               .Field(nameof(W4Info.FirstNameDiffers),
                                      validate: async(state, value) =>
            {
                Task <ValidateResult> task = Task.Factory.StartNew(() =>
                {
                    if (value == null)
                    {
                        value = false;
                    }
                    var r = new ValidateResult {
                        IsValid = true, Value = value
                    };
                    if ((bool)value == true)
                    {
                        r.Feedback = "Ok, we can proceed, but you must call 1-800-772-1213 to obtain a replacement social security card with your correct legal name.";
                    }
                    return(r);
                });
                var result = await task;
                return(result);
            })
                               .Field(nameof(W4Info.Street))
                               .Field(nameof(W4Info.City))
                               .Field(nameof(W4Info.SSN),
                                      validate: async(state, value) =>
            {
                Task <ValidateResult> task = Task.Factory.StartNew(() =>
                {
                    var r = new ValidateResult {
                        IsValid = false, Value = value
                    };
                    Regex regex = new Regex(@"^(?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4}$", RegexOptions.IgnoreCase);
                    if (regex.IsMatch((string)value))
                    {
                        r.IsValid  = true;
                        r.Feedback = "Your social security number has been validated with DHS e-Verify.";
                    }
                    else
                    {
                        r.Feedback = "Your social security number has an invalid format. Please correct and try again.";
                    }
                    // make call to DHS employee validation endpoint
                    // this is just fake.
                    // add some delay to simulate elapsed time
                    Task.Delay(1500);
                    return(r);
                });
                var result = await task;
                return(result);
            })
                               .Field(nameof(W4Info.Exempt))
                               .Field(new FieldReflector <W4Info>(nameof(W4Info.MariageStatus))
                                      .SetActive((s) => !s.Exempt)
                                      )
                               .Field(new FieldReflector <W4Info>(nameof(W4Info.Allowances))
                                      .SetActive((s) => !s.Exempt)
                                      )
                               .Field(new FieldReflector <W4Info>(nameof(W4Info.AdditionalAmountToWithold))
                                      .SetActive((s) => !s.Exempt)
                                      .SetValidate(async(state, value) =>
            {
                Task <ValidateResult> task = Task.Factory.StartNew(() =>
                {
                    if (value == null)
                    {
                        value = 0;
                    }
                    var r = new ValidateResult {
                        IsValid = true, Value = value
                    };
                    if ((Int64)value > 0)
                    {
                        r.Feedback = $"Ok, we'll withhold an additional ${value} from each paycheck.";
                    }
                    return(r);
                });
                var result = await task;
                return(result);
            })
                                      )
                               .Confirm("Please review the data before I proceed. I have captured: {*} \r\n Is this correct?")
                               .Message("Thanks for helping me to get this information captured!")
                               .OnCompletion(processW4)
                               .Build();

            return(b);
        }
Ejemplo n.º 9
0
        public async Task <HttpResponseMessage> ScheduleInterview(string phoneNumber, string email, string name, string jobId, string jobTitle, string company, string jobDescription)
        {
            if (string.IsNullOrEmpty(phoneNumber))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            if (string.IsNullOrEmpty(email))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            if (string.IsNullOrEmpty(jobId))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }


            // find application
            Application app = null;
            Applicant   a   = await ApplicantFactory.GetApplicantByPhone(phoneNumber);

            if (a == null)
            {
                a = new Applicant()
                {
                    Phone = phoneNumber, Email = email, Name = name
                }
            }
            ;
            if (!a.Applications.Keys.Contains(jobId))
            {
                app = new Application()
                {
                    Id = jobId, Applied = DateTime.Parse("1/1/2017"), State = ConversationType.None, Title = jobTitle, Company = company, Description = jobDescription
                };
                a.Applications.Add(jobId, app);
            }
            else
            {
                app = a.Applications[jobId];
            }

            if (!phoneNumber.StartsWith("+"))
            {
                phoneNumber = string.Concat("+", phoneNumber);
            }
            var payload = new MessagePayload()
            {
                FromId     = ConfigurationManager.AppSettings["Twilio_PhoneNumber"],
                ToId       = phoneNumber,
                Text       = $"Hello, {a.Name}. This is Rachel from Express. Your recruiter would like to schedule an interview with you. Would you like to schedule the interview?",
                ServiceUrl = ConfigurationManager.AppSettings["BotFramework_SmsServiceUrl"]
            };
            var credentials = new MicrosoftAppCredentials(ConfigurationManager.AppSettings["MicrosoftAppId"], ConfigurationManager.AppSettings["MicrosoftAppPassword"]);
            var response    = await Bot.SendMessage(payload, credentials);

            // save the conversation state so when the recipient responds we know in what context they replied in
            app.State = ConversationType.ScheduleInterview;
            await ApplicantFactory.PersistApplicant(a);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Ejemplo n.º 10
0
        public async Task <HttpResponseMessage> RejectionNotice(string phoneNumber, string email, string name, string jobId, string jobTitle, string company)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(jobId))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            // find application
            Application app = null;
            Applicant   a   = await ApplicantFactory.GetApplicantByEmail(email);

            if (a == null)
            {
                if (!string.IsNullOrEmpty(phoneNumber) && !string.IsNullOrEmpty(name))
                {
                    a = new Applicant()
                    {
                        Phone = phoneNumber, Email = email, Name = name
                    };
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            if (!a.Applications.Keys.Contains(jobId))
            {
                if (!string.IsNullOrEmpty(jobTitle) && !string.IsNullOrEmpty(company))
                {
                    app = new Application()
                    {
                        Id = jobId, Applied = DateTime.Parse("1/1/2017"), State = ConversationType.None, Title = jobTitle, Company = company
                    };
                    a.Applications.Add(jobId, app);
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            app = a.Applications[jobId];

            // do job matching
            var jobTitles = Express.GetJobSuggestions(app.Title);

            var jobSuggestionHtml = new StringBuilder();
            var filteredJobTitles = jobTitles.Take(3).ToList <string>();

            foreach (var title in filteredJobTitles)
            {
                jobSuggestionHtml.Append("<li><a href='#'>" + title + "</a>");
            }

            // send the email
            dynamic channelData = new ExpandoObject();

            channelData.HtmlBody = string.Format(Resources.rejectionEmailTemplate, a.Name, app.Title, filteredJobTitles.Count, jobSuggestionHtml.ToString());
            channelData.Subject  = string.Format("Job Application Response: {0}", app.Title);

            var payload = new MessagePayload()
            {
                FromId      = ConfigurationManager.AppSettings["Office356_Email"],
                ToId        = email,
                ChannelData = channelData,
                ServiceUrl  = ConfigurationManager.AppSettings["BotFramework_EmailServiceUrl"]
            };
            var credentials = new MicrosoftAppCredentials(ConfigurationManager.AppSettings["MicrosoftAppId"], ConfigurationManager.AppSettings["MicrosoftAppPassword"]);
            var response    = await Bot.SendMessage(payload, credentials);

            // save the conversation state so when the recipient responds we know in what context they replied in
            app.State = ConversationType.RejectionNotice;
            await ApplicantFactory.PersistApplicant(a);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }