Example #1
0
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(Configuration["LuisAppId"]) || string.IsNullOrEmpty(Configuration["LuisAPIKey"]) || string.IsNullOrEmpty(Configuration["LuisAPIHostName"]))
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the appsettings.json file."), cancellationToken);


                return(await stepContext.NextAsync(null, cancellationToken));
            }
            else
            {
                var bookingDetails = stepContext.Result == null
                  ?
                                     await LuisHelper.ExecuteLuisQuery(Configuration, Logger, stepContext.Context, /*Recognizerresult,*/ cancellationToken)
                  :
                                     new BookingDetails();

                //await stepContext.Context.SendActivityAsync(
                //  MessageFactory.Text("Incident Created..!"), cancellationToken);
                //return await stepContext.EndDialogAsync(null, cancellationToken);
                //  return await stepContext.BeginDialogAsync(nameof(BookingDialog), bookingDetails, cancellationToken);



                //   return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on March 22, 2020\"") }, cancellationToken);


                if (bookingDetails.Create_incident.Equals("true"))
                {
                    //     var bookingDetails = stepContext.Result != null
                    //    ?
                    //await LuisHelper.ExecuteLuisQuery(Configuration, Logger, stepContext.Context, cancellationToken)
                    //    :
                    //new BookingDetails();

                    //await stepContext.Context.SendActivityAsync(
                    //  MessageFactory.Text("Incident Created..!"), cancellationToken);
                    //return await stepContext.EndDialogAsync(null, cancellationToken);

                    return(await stepContext.BeginDialogAsync(nameof(BookingDialog), bookingDetails, cancellationToken));
                }
                else if (bookingDetails.None.Equals("true"))
                {
                    bookingDetails.None = "false";
                    CoreBot.models.apiresult incidentno = null;
                    SNOWLogger nOWLogger = new SNOWLogger(Configuration);
                    string     concat    = "";
                    String     userinput = stepContext.Context.Activity.Text.Trim();
                    if (!(userinput.ToUpper().Contains("KB0")))
                    {
                        incidentno = nOWLogger.KBSearchServiceNow("GOTO123TEXTQUERY321=" + stepContext.Context.Activity.Text.Trim());

                        if (incidentno.result != null)
                        {
                            if (incidentno.result.Count != 0)
                            {
                                for (int i = 0; i < incidentno.result.Count; i++)
                                {
                                    concat += "\n" + incidentno.result[i].number + " : " + incidentno.result[i].short_description + "\n";
                                }


                                await stepContext.Context.SendActivityAsync(
                                    MessageFactory.Text(concat), cancellationToken);
                            }
                            else


                            {
                                //                        return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(" Sorry no details found for " + stepContext.Context.Activity.Text) }, cancellationToken);

                                await stepContext.Context.SendActivityAsync(
                                    MessageFactory.Text(" Sorry no details found for: " + stepContext.Context.Activity.Text.Trim()), cancellationToken);

                                return(await stepContext.EndDialogAsync(null, cancellationToken));
                            }
                        }
                        else
                        {
                            await stepContext.Context.SendActivityAsync(
                                MessageFactory.Text(" Sorry no details found"), cancellationToken);

                            return(await stepContext.EndDialogAsync(null, cancellationToken));
                        }
                    }



                    // string concat = string.Join(" ", myList.ToArray());

                    //  return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(incidentno.SelectToken("result[" + i + "].number").ToString() + incidentno.SelectToken("result[" + i + "].short_description").ToString()) }, cancellationToken);
                    // return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(concat) }, cancellationToken);


                    stepContext.Context.TurnState.Add("incID", bookingDetails);

                    return(await stepContext.NextAsync(bookingDetails, cancellationToken));
                }

                else
                {
                    stepContext.Context.TurnState.Add("incID", bookingDetails);

                    return(await stepContext.NextAsync(bookingDetails, cancellationToken));
                }
            }
        }
Example #2
0
        private async Task <DialogTurnResult> OriginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var bookingDetails = (BookingDetails)stepContext.Options;

            if (((BookingDetails)stepContext.Options).Incident_No == null)
            {
                bookingDetails.Incident_No = (string)stepContext.Result;
            }


            string concat = "";


            SNOWLogger nOWLoggerforinc = new SNOWLogger(Configuration);


            if ((bookingDetails.Incident_No != null))
            {
                if (!(bookingDetails.Incident_No.Equals("")))


                {
                    CoreBot.models.Incident_api_result incident_Api_Result = nOWLoggerforinc.GetIncident(bookingDetails.Incident_No);

                    CoreBot.models.apiresult apiresult = nOWLoggerforinc.GetIncidentDetails(bookingDetails.Incident_No);



                    if (incident_Api_Result != null && apiresult != null)
                    {
                        if (incident_Api_Result.Result.Count != 0 && apiresult.result.Count != 0)
                        {
                            for (int i = 0; i < incident_Api_Result.Result.Count; i++)
                            {
                                concat += " \n " + apiresult.result[i].number + ":" + apiresult.result[i].short_description + " \n Status: " + incident_Api_Result.Result[i].value + " \n Active:" + apiresult.result[i].active;
                            }


                            // Cards are sent as Attachments in the Bot Framework.
                            // So we need to create a list of attachments for the reply activity.
                            var attachments = new List <Attachment>();

                            // Reply to the activity we received with an activity.
                            var reply = MessageFactory.Attachment(attachments);

                            reply.Attachments.Add(Cards.GetHeroCardforStatus(apiresult.result[0].number, apiresult.result[0].short_description, incident_Api_Result.Result[0].value).ToAttachment());

                            await stepContext.Context.SendActivityAsync(reply, cancellationToken);



                            //await stepContext.Context.SendActivityAsync(MessageFactory.Text(concat), cancellationToken);
                            return(await stepContext.EndDialogAsync(null, cancellationToken));
                        }
                        else
                        {
                            if (incident_Api_Result.Result.Count == 0)
                            {
                                await stepContext.Context.SendActivityAsync(
                                    MessageFactory.Text(" Incident is not yet updated by team"), cancellationToken);

                                return(await stepContext.EndDialogAsync(null, cancellationToken));
                            }
                            else if (apiresult.result.Count == 0)
                            {
                                await stepContext.Context.SendActivityAsync(
                                    MessageFactory.Text("No Incident update Found:"), cancellationToken);

                                return(await stepContext.EndDialogAsync(null, cancellationToken));
                            }
                        }
                    }
                    else
                    {
                        await stepContext.Context.SendActivityAsync(
                            MessageFactory.Text(" Sorry no incident update found"), cancellationToken);

                        return(await stepContext.EndDialogAsync(null, cancellationToken));
                    }


                    //        {

                    //            //                        return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(" Sorry no details found for " + stepContext.Context.Activity.Text) }, cancellationToken);
                    //            if (incident_Api_Result == null)
                    //            {
                    //                await stepContext.Context.SendActivityAsync(
                    //          MessageFactory.Text(" Sorry no incident update found"), cancellationToken);

                    //                return await stepContext.EndDialogAsync(null, cancellationToken);
                    //            }
                    //            else

                    //            if (incident_Api_Result != null)
                    //            {

                    //                if (incident_Api_Result.Result.Count != 0)
                    //                {
                    //                    await stepContext.Context.SendActivityAsync(
                    //                    MessageFactory.Text(" Sorry no update found for: " + incident_Api_Result.Result[0].number.ToString()), cancellationToken);

                    //                    return await stepContext.EndDialogAsync(null, cancellationToken);
                    //                }
                    //                else
                    //                {
                    //                    await stepContext.Context.SendActivityAsync(
                    //                MessageFactory.Text(" Sorry no incident update found"), cancellationToken);

                    //                    return await stepContext.EndDialogAsync(null, cancellationToken);
                    //                }

                    //            }
                    //        }
                    //        return await stepContext.EndDialogAsync(null, cancellationToken);
                    //    }
                    //}
                    //else
                    //{

                    //    await stepContext.Context.SendActivityAsync(
                    //           MessageFactory.Text(" Sorry no incident update found"), cancellationToken);

                    //    return await stepContext.EndDialogAsync(null, cancellationToken);

                    //}



                    //return await stepContext.EndDialogAsync(null, cancellationToken);

                    //  return await stepContext.ContinueDialogAsync(cancellationToken);

                    // return await stepContext.ReplaceDialogAsync("MainDialog",bookingDetails,cancellationToken);
                }
            }
            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }
Example #3
0
        private async Task <DialogTurnResult> ConfirmStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            //   var bookingDetails = (BookingDetails)stepContext.Options;

            // bookingDetails.TravelDate = (string)stepContext.Result;

            //            var msg = $"Please confirm, I have you traveling to: {bookingDetails.Destination} from: {bookingDetails.Origin} on: {bookingDetails.TravelDate}";
            // CoreBot.models.apiresult incidentno = null;
            SNOWLogger nOWLogger = new SNOWLogger(Configuration);
            String     userinput = stepContext.Context.Activity.Text.Trim();

            //  var bookingDetails = (BookingDetails)stepContext.Options;

            if ((BookingDetails)stepContext.Result != null)
            {
                var bookingDetails = (BookingDetails)stepContext.Context.TurnState["incID"];



                if ((userinput.ToUpper().Contains("KB0")))
                {
                    CoreBot.models.apiresult kbresult = nOWLogger.KBSearchByNumber(stepContext.Context.Activity.Text.Trim());



                    string concatkb = "";

                    if (kbresult.result.Count != 0)
                    {
                        for (int i = 0; i < kbresult.result.Count; i++)
                        {
                            concatkb += kbresult.result[i].number + " : " + kbresult.result[i].short_description + "\n" + kbresult.result[i].text + "\n";
                        }
                    }
                    else


                    {
                        //return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(" Sorry no detials found for KB No: " + stepContext.Context.Activity.Text) }, cancellationToken);
                        await stepContext.Context.SendActivityAsync(
                            MessageFactory.Text(" Sorry no detials found for KB No: " + stepContext.Context.Activity.Text.Trim()), cancellationToken);


                        //await stepContext.EndDialogAsync(null, cancellationToken);

                        // return await stepContext.NextAsync(null, cancellationToken);
                    }

                    //  return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(concatkb) }, cancellationToken);

                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Text(concatkb), cancellationToken);

                    //  var msg = $"Are you satisfied with the information? ";

                    //return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text(msg) }, cancellationToken);

                    //await stepContext.NextAsync(stepContext, cancellationToken);

                    var msg = $"Are you satisfied with the information? \n Select \"No\" to create Incident ";

                    return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text(msg) }, cancellationToken));
                }
                else

                if (bookingDetails.Incident_status.Equals("true"))
                {
                    bookingDetails.Incident_status = "false";

                    //  SNOWLogger nOWLoggerforinc = new SNOWLogger(Configuration);



                    // string concat = "";
                    if (bookingDetails != null)
                    {
                        return(await stepContext.BeginDialogAsync(nameof(IncDialog), bookingDetails, cancellationToken));
                    }



                    return(await stepContext.NextAsync(stepContext, cancellationToken));

                    // return await stepContext.BeginDialogAsync(nameof(BookingDialog), bookingDetails, cancellationToken);
                }
            }
            else
            {
                return(await stepContext.NextAsync(stepContext, cancellationToken));
            }



            return(await stepContext.NextAsync(stepContext, cancellationToken));
        }
Example #4
0
        private async Task <DialogTurnResult> OriginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var incidentDetails = (IncidentDetails)stepContext.Options;

            if (((IncidentDetails)stepContext.Options).Incident_No == null)
            {
                incidentDetails.Incident_No = (string)stepContext.Result.ToString().ToUpper();
            }


            string concat = "";


            SNOWLogger nOWLoggerforinc = new SNOWLogger(Configuration);


            if ((incidentDetails.Incident_No != null))
            {
                if (!(incidentDetails.Incident_No.Equals("")))


                {
                    incident_Api_Result = nOWLoggerforinc.GetIncident(incidentDetails.Incident_No.ToUpper());

                    apiresult = nOWLoggerforinc.GetIncidentDetails(incidentDetails.Incident_No.ToUpper());



                    if (incident_Api_Result != null && apiresult != null)
                    {
                        if (incident_Api_Result.Result.Count != 0 && apiresult.result.Count != 0)
                        {
                            for (int i = 0; i < incident_Api_Result.Result.Count; i++)
                            {
                                concat += " \n " + apiresult.result[i].number + ":" + apiresult.result[i].short_description + " \n Status: " + incident_Api_Result.Result[i].value + " \n Active:" + apiresult.result[i].active;
                            }


                            // Cards are sent as Attachments in the Bot Framework.
                            // So we need to create a list of attachments for the reply activity.
                            var attachments = new List <Attachment>();

                            // Reply to the activity we received with an activity.
                            var reply = MessageFactory.Attachment(attachments);

                            reply.Attachments.Add(Cards.GetHeroCardforStatus(apiresult.result[0].number, apiresult.result[0].short_description, incident_Api_Result.Result[0].value).ToAttachment());

                            await stepContext.Context.SendActivityAsync(reply, cancellationToken);



                            return(await stepContext.PromptAsync(nameof(ChoicePrompt),
                                                                 new PromptOptions
                            {
                                Prompt = MessageFactory.Text("Are you satisfied ? if not please select."),
                                Choices = ChoiceFactory.ToChoices(new List <string> {
                                    "comment", "Escalate", "Satisfied"
                                }),
                            }, cancellationToken));

                            //await stepContext.Context.SendActivityAsync(MessageFactory.Text(concat), cancellationToken);
                            //  return await stepContext.EndDialogAsync(null, cancellationToken);
                            //  return await stepContext.NextAsync(stepContext, cancellationToken);
                        }
                        else
                        {
                            if (incident_Api_Result.Result.Count == 0)
                            {
                                await stepContext.Context.SendActivityAsync(
                                    MessageFactory.Text(" Incident is not yet updated by team"), cancellationToken);

                                //  return await stepContext.EndDialogAsync(null, cancellationToken);
                                //return await stepContext.NextAsync(stepContext, cancellationToken);

                                return(await stepContext.PromptAsync(nameof(ChoicePrompt),
                                                                     new PromptOptions
                                {
                                    Prompt = MessageFactory.Text("Are you satisfied ? if Not please select."),
                                    Choices = ChoiceFactory.ToChoices(new List <string> {
                                        "Comment", "Escalate", "Satisfied"
                                    }),
                                    // Choices = ChoiceFactory.ToChoices(new List<string> { "Add my comment for SNOW team", "Escalate this issue", "I am Satisfied" }),
                                }, cancellationToken));
                            }
                            else if (apiresult.result.Count == 0)
                            {
                                await stepContext.Context.SendActivityAsync(
                                    MessageFactory.Text("No Incident update Found:"), cancellationToken);

                                //   return await stepContext.EndDialogAsync(null, cancellationToken);
                                //  return await stepContext.NextAsync(stepContext, cancellationToken);
                            }
                        }
                    }
                    else
                    {
                        await stepContext.Context.SendActivityAsync(
                            MessageFactory.Text(" Sorry no incident update found"), cancellationToken);

                        //  return await stepContext.EndDialogAsync(null, cancellationToken);
                        return(await stepContext.NextAsync(stepContext, cancellationToken));
                    }


                    //        {

                    //            //                        return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(" Sorry no details found for " + stepContext.Context.Activity.Text) }, cancellationToken);
                    //            if (incident_Api_Result == null)
                    //            {
                    //                await stepContext.Context.SendActivityAsync(
                    //          MessageFactory.Text(" Sorry no incident update found"), cancellationToken);

                    //                return await stepContext.EndDialogAsync(null, cancellationToken);
                    //            }
                    //            else

                    //            if (incident_Api_Result != null)
                    //            {

                    //                if (incident_Api_Result.Result.Count != 0)
                    //                {
                    //                    await stepContext.Context.SendActivityAsync(
                    //                    MessageFactory.Text(" Sorry no update found for: " + incident_Api_Result.Result[0].number.ToString()), cancellationToken);

                    //                    return await stepContext.EndDialogAsync(null, cancellationToken);
                    //                }
                    //                else
                    //                {
                    //                    await stepContext.Context.SendActivityAsync(
                    //                MessageFactory.Text(" Sorry no incident update found"), cancellationToken);

                    //                    return await stepContext.EndDialogAsync(null, cancellationToken);
                    //                }

                    //            }
                    //        }
                    //        return await stepContext.EndDialogAsync(null, cancellationToken);
                    //    }
                    //}
                    //else
                    //{

                    //    await stepContext.Context.SendActivityAsync(
                    //           MessageFactory.Text(" Sorry no incident update found"), cancellationToken);

                    //    return await stepContext.EndDialogAsync(null, cancellationToken);

                    //}



                    //return await stepContext.EndDialogAsync(null, cancellationToken);

                    //  return await stepContext.ContinueDialogAsync(cancellationToken);

                    // return await stepContext.ReplaceDialogAsync("MainDialog",incidentDetails,cancellationToken);
                }
            }


            //return await stepContext.EndDialogAsync(null, cancellationToken);
            return(await stepContext.NextAsync(stepContext, cancellationToken));
        }