Пример #1
0
        public async Task ContactNumberHandler(IDialogContext context, IAwaitable <string> argument)
        {
            var contactNumber = await argument;

            testDriveDetail.PhoneNumber = contactNumber;

            await context.PostAsync($@"Thank you for your interest, your request has been logged. Our sales team will get back to you shortly.
                                    {Environment.NewLine}Your test drive request summary:
                                    {Environment.NewLine}Car Make: {testDriveDetail.CarMake},
                                    {Environment.NewLine}Car Model: {testDriveDetail.CarModel},
                                    {Environment.NewLine}Requested Time: {testDriveDetail.RequestedTime},
                                    {Environment.NewLine}Customer Name: {testDriveDetail.CustomerName},
                                    {Environment.NewLine}Phone Number: {testDriveDetail.PhoneNumber}");

            //CrmLead.CreateTestDrive(testDriveDetail, CrmDataConnection.GetAPI());

            CrmLead.CreateTestDrive(testDriveDetail, CrmDataConnection.GetOrgService());

            PromptDialog.Confirm(
                context: context,
                resume: AnythingElseHandler,
                prompt: "Is there anything else that I could help?",
                retry: "Sorry, I don't understand that."
                );
        }
Пример #2
0
        public async Task AddEventToCalendar(RecognizerResult luisResult, ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken, IStatePropertyAccessor <UserProfileState> userStateAccessor, ILogger Logger)
        {
            bool eventAdded = false;

            object entitydate = null;

            entitydate = luisResult.GetEntity <object>("datetime", "text");
            if (entitydate != null)
            {
                DateTime currentDate;
                if (entitydate != null)
                {
                    if (DateTime.TryParse(entitydate.ToString(), out currentDate))
                    {
                        eventAdded = true;
                        Logger.LogInformation($"[Inside the Calendar.Event Intent success event] " + turnContext.Activity.AsMessageActivity()?.Text, turnContext.Activity.Conversation.Id);
                        await CrmDataConnection.AddEventToCalendar(turnContext, userStateAccessor, currentDate);

                        await turnContext.SendActivityAsync(MessageFactory.Text($"Added event to your calendar for : {currentDate.ToLongDateString()}"), cancellationToken);
                    }
                    else if (Enum.TryParse <DayOfWeek>(entitydate.ToString(), out DayOfWeek currentDay))
                    {
                        //var dayOfWeek = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), entitydate.ToString(), true);
                        currentDate = DateTime.Now.ClosestWeekDay(currentDay);
                        eventAdded  = true;
                        Logger.LogInformation($"[Inside the Calendar.Event Intent success event] " + turnContext.Activity.AsMessageActivity()?.Text, turnContext.Activity.Conversation.Id);
                        await CrmDataConnection.AddEventToCalendar(turnContext, userStateAccessor, currentDate);

                        await turnContext.SendActivityAsync(MessageFactory.Text($"Added event to your calendar for : {currentDate.ToLongDateString()}"), cancellationToken);
                    }
                    else
                    {
                        try
                        {
                            var dayOfWeek = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), entitydate.ToString(), true);
                            currentDate = DateTime.Now.ClosestWeekDay(currentDay);
                            eventAdded  = true;
                            Logger.LogInformation($"[Inside the Calendar.Event Intent success event] " + turnContext.Activity.AsMessageActivity()?.Text, turnContext.Activity.Conversation.Id);
                            await CrmDataConnection.AddEventToCalendar(turnContext, userStateAccessor, currentDate);

                            await turnContext.SendActivityAsync(MessageFactory.Text($"Added event to your calendar for : {currentDate.ToLongDateString()}"), cancellationToken);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            if (!eventAdded)
            {
                Logger.LogInformation($"[Inside the Calendar.Event Intent success event] " + turnContext.Activity.AsMessageActivity()?.Text, turnContext.Activity.Conversation.Id);
                await CrmDataConnection.AddEventToCalendar(turnContext, userStateAccessor);

                await turnContext.SendActivityAsync(MessageFactory.Text($"Added event to your calendar for : 9th Dec 2017"), cancellationToken);
            }
        }
Пример #3
0
        public async Task ContactNumberHandler(IDialogContext context, IAwaitable <string> argument)
        {
            var contactNumber = await argument;

            testDriveDetail.PhoneNumber = contactNumber;

            await context.PostAsync($@"Thank you for your interest, your request has been logged. Our sales team will get back to you shortly.
                                    {Environment.NewLine}Your test drive request summary:
                                    {Environment.NewLine}Car Make: {testDriveDetail.CarMake},
                                    {Environment.NewLine}Car Model: {testDriveDetail.CarModel},
                                    {Environment.NewLine}Requested Time: {testDriveDetail.RequestedTime},
                                    {Environment.NewLine}Customer Name: {testDriveDetail.CustomerName},
                                    {Environment.NewLine}Phone Number: {testDriveDetail.PhoneNumber}");

            //CrmLead.CreateTestDrive(testDriveDetail, CrmDataConnection.GetAPI());

            CrmLead.CreateTestDrive(testDriveDetail, CrmDataConnection.GetOrgService());

            context.Done <string>("Test drive has been logged");
        }
Пример #4
0
        public static IForm <CarInquiryFormFlow> BuildForm()
        {
            OnCompletionAsyncDelegate <CarInquiryFormFlow> processRequest = async(context, state) =>
            {
                await context.PostAsync($@"Your test drive request summary:
                                    {Environment.NewLine}Car Make: {state.CarMake.ToString()},
                                    {Environment.NewLine}Car Model: {state.CarModel.ToString()},
                                    {Environment.NewLine}Requested Time: {state.PreferredTime},
                                    {Environment.NewLine}Customer Name: {state.Name},
                                    {Environment.NewLine}Phone Number: {state.ContactNumber}");

                var testDriveDetail = new TestDriveDetail
                {
                    CarMake       = state.CarMake.ToString(),
                    CarModel      = state.CarModel.ToString(),
                    RequestedTime = state.PreferredTime,
                    CustomerName  = state.Name,
                    PhoneNumber   = state.ContactNumber
                };

                // save the data to CRM
                CrmLead.CreateTestDrive(testDriveDetail, CrmDataConnection.GetOrgService());
            };

            return(new FormBuilder <CarInquiryFormFlow>()
                   .Message("Welcome to the car test drive bot!")
                   .Field(nameof(CarMake))
                   .Field(nameof(CarModel))
                   .Field(nameof(PreferredTime))
                   .Field(nameof(Name))
                   .Field(nameof(ContactNumber))
                   .AddRemainingFields()
                   .Message("Thank you for your interest, your request has been logged. Our sales team will get back to you shortly.")
                   .OnCompletion(processRequest)
                   .Build());
        }
Пример #5
0
        private async Task ProcessLuisIntent(CRMLuisModel.Intent intent, ITurnContext turnContext, RecognizerResult luisResult0, CancellationToken cancellationToken = default(CancellationToken))
        {
            var msgContext = turnContext as ITurnContext <IMessageActivity>;

            switch (intent)
            {
            case CRMLuisModel.Intent.Greet_Welcome:
                var usrState = await _userProfileStateAccessor.GetAsync(turnContext);

                if (usrState == null)
                {
                    usrState = new UserProfileState();
                }
                usrState.CurrentDialog = "mainDialog";
                await _userProfileStateAccessor.SetAsync(turnContext, usrState);

                if (msgContext != null)
                {
                    Logger.LogInformation($"[Inside the Greet.Welcome Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                }
                var dialogResult = await Dialog.Run(turnContext, _mainDialogStateAccessor, cancellationToken);

                if (dialogResult.Result != null && !string.IsNullOrWhiteSpace(dialogResult.Result.ToString()))
                {
                    turnContext.Activity.Text = dialogResult.Result.ToString();
                    var luisResult = await _recognizer.RecognizeAsync <CRMLuisModel>(turnContext, cancellationToken);

                    var luisResultRaw = await _recognizer.RecognizeAsync(turnContext, cancellationToken);
                    await ProcessLuisIntent(luisResult.TopIntent().intent, turnContext, luisResultRaw, cancellationToken);
                }
                break;

            case CRMLuisModel.Intent.Accounts_Total:
                Logger.LogInformation($"[Inside the Accounts.Total Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await CrmLead.GetAccountCounts(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext);

                break;

            case CRMLuisModel.Intent.Accounts_AllAccounts:
                Logger.LogInformation($"[Inside the Accounts.AllAccounts Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await CrmLead.GetAllAccountCounts(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext);

                break;

            case CRMLuisModel.Intent.Accounts_Top5:
                Logger.LogInformation($"[Inside the Accounts.Top5 Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var count = GetNumber(luisResult0.Text);
                await CrmLead.GetTopAccounts(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext, count);

                break;

            case CRMLuisModel.Intent.Products_Top5:
                Logger.LogInformation($"[Inside the Products.Top5 Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await CrmLead.GetTopProducts(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext);

                break;

            case CRMLuisModel.Intent.Calendar_Event:
                var usrState1 = await _userProfileStateAccessor.GetAsync(turnContext);

                if (usrState1 == null)
                {
                    usrState1 = new UserProfileState();
                }
                usrState1.CurrentDialog = "graphDialog";
                await _userProfileStateAccessor.SetAsync(turnContext, usrState1);

                var dialogResult1 = await CalDialog.Run(turnContext, _calDialogStateAccessor, cancellationToken);

                if (dialogResult1 != null && dialogResult1.Status == DialogTurnStatus.Complete && luisResult0.GetTopScoringIntent().intent.ToLower() != "none")
                {
                    var crmCalendar = new CRMCalendar();
                    Logger.LogInformation($"[Inside the Calendar.Event Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                    await crmCalendar.AddEventToCalendar(luisResult0, msgContext, cancellationToken, _userProfileStateAccessor, Logger);
                }
                break;

            case CRMLuisModel.Intent.Greet_Farewell:
                Logger.LogInformation($"[Inside the Greet.Farewell Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var botAdapter = (BotFrameworkAdapter)turnContext.Adapter;
                await botAdapter.SignOutUserAsync(turnContext, "crm", null, cancellationToken);

                await botAdapter.SignOutUserAsync(turnContext, "graph", null, cancellationToken);

                await turnContext.SendActivityAsync(MessageFactory.Text("b'bye \U0001F44B Take care"), cancellationToken);

                await turnContext.SendActivityAsync(MessageFactory.Text("You have been signed out."), cancellationToken);

                break;

            case CRMLuisModel.Intent.QueryProduct:
                var product = luisResult0.GetEntity <string>("Product_Name");
                Logger.LogInformation($"[Inside the QueryProduct Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await CrmLead.GetProductInfo(await CrmDataConnection.GetAPI2(msgContext, _configuration, _userProfileStateAccessor), msgContext, product);

                break;

            case CRMLuisModel.Intent.Lead_Registration:
                var leadDialogState = await _leadDialogStateAccessor.GetAsync(turnContext);

                if (leadDialogState == null || leadDialogState.DialogStack.Count == 0)
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text($"A new Lead is now being registered in the system."), cancellationToken);
                }
                Logger.LogInformation($"[Inside the Lead.Registration Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var dialogResult2 = await MakeRootDialog(msgContext.Activity.ChannelId).Run(turnContext, _leadDialogStateAccessor, cancellationToken);

                if (dialogResult2 != null && dialogResult2.Result != null)
                {
                    if (dialogResult2.Result is LeadRegisterForm completedForm)
                    {
                        CrmLead.CreateNewLead(CrmDataConnection.GetAPIStaging(_configuration), completedForm);
                        await turnContext.SendActivityAsync(MessageFactory.Text($"The Lead has been registered in the System"), cancellationToken);
                    }
                }
                break;

            case CRMLuisModel.Intent.Report_ActiveCases:
                Logger.LogInformation($"[Inside the Report.ActiveCases Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var actionUrl3 = "https://app.powerbi.com/view?r=eyJrIjoiODk3ODQxNDgtMzU2Ni00YTRkLThjMGMtOTliMzNiMDBhMjc4IiwidCI6Ijc0YzNhNGIxLWEyYTUtNGU0OC05ZDdiLTQzNGYzNmQzMzVlZCIsImMiOjF9";
                await CrmLead.ShowReport(msgContext, actionUrl3, "Active Cases");

                break;

            case CRMLuisModel.Intent.Report_PerformanceKpi:
                Logger.LogInformation($"[Inside the Report.PerformanceKpi Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var actionUrl2 = "https://app.powerbi.com/view?r=eyJrIjoiZWVjODlhNjktZTcwYy00ZDU3LTllYjAtOTRlMjY1MTk0NGQwIiwidCI6Ijc0YzNhNGIxLWEyYTUtNGU0OC05ZDdiLTQzNGYzNmQzMzVlZCIsImMiOjF9";
                await CrmLead.ShowReport(msgContext, actionUrl2, "Org Performance KPIs");

                break;

            case CRMLuisModel.Intent.Report_SalesAnalytics:
                Logger.LogInformation($"[Inside the Report.SalesAnalytics Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var actionUrl1 = "https://app.powerbi.com/view?r=eyJrIjoiZTljNDg5MjctNjljYi00MTQ2LWJiMTktM2M1OTBkMzQ0OWVkIiwidCI6Ijc0YzNhNGIxLWEyYTUtNGU0OC05ZDdiLTQzNGYzNmQzMzVlZCIsImMiOjF9";
                await CrmLead.ShowReport(msgContext, actionUrl1, "Sales Analytics Reports");

                break;

            case CRMLuisModel.Intent.Report_SalesLeaderboard:
                Logger.LogInformation($"[Inside the Report.SalesLeaderboard Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var actionUrl = "https://app.powerbi.com/view?r=eyJrIjoiNzMxZmRlNjEtYmFkMy00NDMyLThlY2MtMzI3ZDc2ODE5MTdiIiwidCI6Ijc0YzNhNGIxLWEyYTUtNGU0OC05ZDdiLTQzNGYzNmQzMzVlZCIsImMiOjF9";
                await CrmLead.ShowReport(msgContext, actionUrl, "Sales Leaderboard Reports");

                break;

            case CRMLuisModel.Intent.SharePoint_TopLists:
                Logger.LogInformation($"[Inside the SharePoint.TopLists Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var count2   = GetNumber(luisResult0.Text);
                var siteName = luisResult0.GetEntity <string>("Site_Name");
                if (string.IsNullOrEmpty(siteName))
                {
                    siteName = "DBS";
                }
                string siteUrl = "https://atidan2.sharepoint.com/sites/myrazor";
                if (siteName.ToLower().Contains("dbs"))
                {
                    siteUrl += "/" + siteName;
                }
                if (siteName.ToLower().Contains("elwyn"))
                {
                    siteUrl += "/RazorPMO/Elwyn/ElwynCRM";
                }
                if (siteName.ToLower().Contains("elwyncrm"))
                {
                    siteUrl += "/RazorPMO/Elwyn/ElwynCRM";
                }
                await QuerySharePoint.GetTopLists(siteUrl, count2, msgContext, siteName, _configuration);

                break;

            case CRMLuisModel.Intent.SharePoint_ListItems:
                Logger.LogInformation($"[Inside the SharePoint.ListItems Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                var count1   = GetNumber(luisResult0.Text);
                var listName = luisResult0.GetEntity <string>("List_Name");
                if (string.IsNullOrEmpty(listName))
                {
                    listName = "Documents";
                }
                if (listName.ToLower() == "status" || listName.ToLower() == "statusreports")
                {
                    listName = "Status Reports";
                }
                if (listName.ToLower() == "billing" || listName.ToLower() == "billingreports")
                {
                    listName = "Billing Reports";
                }
                await QuerySharePoint.GetListContents("https://atidan2.sharepoint.com/sites/myrazor/DBS", listName, count1, msgContext, _configuration);

                break;

            case CRMLuisModel.Intent.SharePoint_AddTask:
                Logger.LogInformation($"[Inside the SharePoint.AddTask Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await QuerySharePoint.AddTask("https://atidan2.sharepoint.com/sites/ManufacturingICS1", msgContext, _configuration, luisResult0);

                break;

            case CRMLuisModel.Intent.None:
            default:
                Logger.LogInformation($"[Inside the None Intent] " + msgContext.Activity.AsMessageActivity()?.Text, msgContext.Activity.Conversation.Id);
                await turnContext.SendActivityAsync(MessageFactory.Text($"Sorry, I did not understand you. \U0001F44D"), cancellationToken);

                await turnContext.SendActivityAsync(MessageFactory.Text($"I don't know what you want to do"), cancellationToken);

                break;
            }
        }