private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { if ((bool)stepContext.Result) { var incidentDetails = (IncidentDetails)stepContext.Options; SNOWLogger nOWLogger1 = new SNOWLogger(Configuration); string incident1 = nOWLogger1.CreateIncidentServiceNow(incidentDetails.Short_desc, incidentDetails.Descrip, incidentDetails.GetPrioritycode(incidentDetails.Priority)); if (incident1 != null) { string[] strList = incident1.Split(","); // 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.GetHeroCard(strList[0], strList[1], incidentDetails.Short_desc, incidentDetails.Descrip, incidentDetails.Priority).ToAttachment()); await stepContext.Context.SendActivityAsync(reply, cancellationToken); // await stepContext.Context.SendActivityAsync( //MessageFactory.Text("Incident No: "+ incident1+" Created for: "+incidentDetails.Short_desc+ "\n is there anything I can help you with ?", null,null)); stepContext.Context.TurnState.Add("incID", incidentDetails); return(await stepContext.EndDialogAsync(incidentDetails, cancellationToken)); } // stepContext = null; return(await stepContext.CancelAllDialogsAsync()); // return await stepContext.EndDialogAsync(null, cancellationToken); } else { await stepContext.Context.SendActivityAsync( MessageFactory.Text("Incident creation aborted ! \n is there anything I can help you with ? ", null, null)); // stepContext = null; return(await stepContext.EndDialogAsync(null, cancellationToken)); } }
static void Main(string[] args) { int x = 1, y = 0, z; string incNo = string.Empty; try { z = x / y; } catch (Exception ex) { incNo = SNOWLogger.CreateIncidentServiceNow(ex.Message, "My App's exception : " + ex.StackTrace); Console.WriteLine("SNOW Incident Number : " + incNo); } }
private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.) var bookingDetails = stepContext.Result != null; string incidentno = null; if (stepContext.Result != null) { string shortds = stepContext.Result.ToString(); SNOWLogger nOWLogger = new SNOWLogger(Configuration); incidentno = nOWLogger.CreateIncidentServiceNow(shortds, "long des"); return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("Incident: " + incidentno + " created Successfully for : " + shortds) }, cancellationToken)); } else { await stepContext.Context.SendActivityAsync(MessageFactory.Text("Thank you."), cancellationToken); } return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken)); await stepContext.EndDialogAsync(cancellationToken : cancellationToken); // ? // await LuisHelper.ExecuteLuisQuery(Configuration, Logger, stepContext.Context, cancellationToken) // : // new BookingDetails(); // In this sample we only have a single Intent we are concerned with. However, typically a scenario // will have multiple different Intents each corresponding to starting a different child Dialog. // Run the BookingDialog giving it whatever details we have from the LUIS call, it will fill out the remainder. // return await stepContext.BeginDialogAsync(nameof(BookingDialog), bookingDetails, cancellationToken); // return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text(incidentno) }, cancellationToken); }
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)); } } }
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)); }
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)); }
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)); }