Example #1
0
        private async Task ResumeAfterPromptAsync(IDialogContext context, IAwaitable <string> result)
        {
            var response = await result;

            if (!string.IsNullOrEmpty(response))
            {
                // if the response contains an '@', then assume it is an email address, otherwise assume it is a phone number
                Applicant a = null;
                if (response.Contains("@"))
                {
                    a = await ApplicantFactory.GetApplicantByEmail(response.Trim());
                }
                else
                {
                    a = await ApplicantFactory.GetApplicantByPhone(response.Replace("-", string.Empty).Replace("+", string.Empty).Replace(" ", string.Empty).Trim());
                }

                if (a == null)
                {
                    await context.PostAsync("I'm sorry. I was not able to find your account. Please contact your Express recruiter.");

                    context.Done <string>(null);
                }
                else
                {
                    context.UserData.SetValue <Applicant>("applicant", a);
                    await context.PostAsync($"Welcome back, {a.Name}!");

                    // TODO: persist the connection between the context.From.Id and the applicant

                    await ForwardToDialog(context, null, a);
                }
            }
        }
        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));
        }
        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));
        }
        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));
        }