Exemple #1
0
        private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // If the child dialog ("BookingDialog") was cancelled, the user failed to confirm or if the intent wasn't BookFlight
            // the Result here will be null.
            if (stepContext.Result is Incident result)
            {
                // Now we have all the booking details call the booking service.

                // If the call to the booking service was successful tell the user.

                //var timeProperty = new TimexProperty(result.IncidentDate);
                //var travelDateMsg = timeProperty.ToNaturalLanguage(DateTime.Now);
                APIRequest apicall = new APIRequest();

                string messageText = string.Empty;
                //string jsonss = _iconfiguration.GetValue<string>("IncidentCreateJson");
                //string url = _iconfiguration.GetValue<string>("IncidentCreateURL");
                //string url1 = _iconfiguration.GetValue<string>("IncidentStatusCheckByID");
                //string url2 = _iconfiguration.GetValue<string>("LastFiveIncidentNo");
                if (result.ChoiceID == "1")
                {
                    string json = _iconfiguration.GetValue <string>("IncidentCreateJson");
                    json = json.Replace("{shortdesc}", result.IncidentDesc).Replace("{desc}", result.IncidentDesc);
                    if (!string.IsNullOrEmpty(result.EmailID))
                    {
                        if (result.EmailID.ToLower() == "*****@*****.**")
                        {
                            json = json.Replace("{caller_id}", "Sivasubramanian");
                        }
                        else if (result.EmailID.ToLower() == "*****@*****.**")
                        {
                            json = json.Replace("{caller_id}", "veera");
                        }
                        else
                        {
                            json = json.Replace("{caller_id}", "int_user");
                        }
                    }
                    else
                    {
                        json = json.Replace("{caller_id}", "int_user");
                    }

                    string url             = _iconfiguration.GetValue <string>("IncidentCreateURL");
                    string incident_number = apicall.CreateIncident(result.IncidentDesc, result.EmailID, json, url);
                    // string incident_number = "INC123456789";

                    messageText = $"I have created a INC **#{incident_number}** with this details - Description : {result.IncidentDesc} from {result.EmailID} on {DateTime.Now.ToString()}";
                }
                else if (result.ChoiceID == "2")
                {
                    string url             = _iconfiguration.GetValue <string>("IncidentStatusCheckByID");
                    string incident_number = result.IncidentNo;
                    string status          = apicall.CheckIncidentStatusByID(result.EmailID, result.IncidentNo, url);// "CANCELLED";
                    if (string.IsNullOrWhiteSpace(status) || status == "Issue")
                    {
                        messageText = $"**Unable to find the status for Incident #{incident_number}.**";
                    }
                    else
                    {
                        messageText = $"Current status of this **#{incident_number} : {status}**";
                    }
                }
                else if (result.ChoiceID == "3")
                {
                    string url    = _iconfiguration.GetValue <string>("LastFiveIncidentNo");
                    string incLst = apicall.LastFiveIncidentLst(result.EmailID, url);
                    if (string.IsNullOrWhiteSpace(incLst))
                    {
                        messageText = "No INC list available for you.";
                    }
                    else
                    {
                        messageText = "Please find the list of last 5 incidents -" + incLst;
                    }
                    //messageText = "1) INC123456789 \n 2) INC123456789 \n 3) INC123456789 \n 4) INC123456789 \n 5) INC123456789";
                }

                await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = (Activity)MessageFactory.Attachment(Respository.GenerateAdaptiveCardTextBlock(messageText)) }, cancellationToken);

                //var message = MessageFactory.Text(messageText, messageText, InputHints.IgnoringInput);
                //await stepContext.Context.SendActivityAsync(message, cancellationToken);
            }

            // Restart the main dialog with a different message the second time around
            var promptMessage = "What else can I do for you?";

            //return await stepContext.ReplaceDialogAsync(InitialDialogId, promptMessage, cancellationToken);

            //var adaptiveCardJson = File.ReadAllText(Environment.CurrentDirectory + "\\Cards\\menuCard.json");
            //JObject json1 = JObject.Parse(adaptiveCardJson);
            //var adaptiveCardAttachment = new Attachment()
            //{
            //    ContentType = "application/vnd.microsoft.card.adaptive",
            //    Content = JsonConvert.DeserializeObject(json1.ToString()),
            //};
            //return await stepContext.ReplaceDialogAsync(InitialDialogId, null, cancellationToken);
            //return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = (Activity)MessageFactory.Attachment(adaptiveCardAttachment) }, cancellationToken);
            //var promptMessage = adaptiveCardAttachment;
            return(await stepContext.ReplaceDialogAsync(InitialDialogId, promptMessage, cancellationToken));
        }