Exemple #1
0
        private async Task <DialogTurnResult> SummaryStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if ((bool)stepContext.Result)
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Here are the details you provided."), cancellationToken);

                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Python programming questions - "), cancellationToken);

                for (int i = 0; i < QnAData.QuestionPhrase.Count; i++)
                {
                    await stepContext.Context.SendActivityAsync(MessageFactory.Text(QnAData.QuestionPhrase[i]), cancellationToken);
                }

                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Your programming Answer - "), cancellationToken);

                await stepContext.Context.SendActivityAsync(MessageFactory.Text((string)stepContext.Values["Answer"]), cancellationToken);

                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Please wait while I update my Knowledge Base."), cancellationToken);

                await stepContext.Context.SendActivitiesAsync(
                    new Activity[] {
                    new Activity {
                        Type = ActivityTypes.Typing
                    },
                    new Activity {
                        Type = "delay", Value = 5000
                    },
                },
                    cancellationToken);

                var authoringURL = $"https://{Configuration["ResourceName"]}.cognitiveservices.azure.com";

                // <AuthorizationAuthor>
                var client = new QnAMakerClient(new ApiKeyServiceClientCredentials(Configuration["Key"]))
                {
                    Endpoint = authoringURL
                };
                // </AuthorizationAuthor>

                QnAClient.UpdateKB(client, Configuration["KnowledgeBaseId"], (string)stepContext.Values["Answer"]).Wait();
                QnAClient.PublishKb(client, Configuration["KnowledgeBaseId"]).Wait();

                await stepContext.Context.SendActivityAsync(MessageFactory.Text("I have update my Knowledge Base. Thank you for your contribution 😇"));

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
            else
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Request Not Confirmed."));

                return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
            }
        }