コード例 #1
0
        private async Task <DialogTurnResult> ResponsePhraseDialog(WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken))
        {
            var phrase = (string)step.Result;
            var code   = await TranslatorHelper.GetDesiredLanguageAsync(phrase);

            step.ActiveDialog.State["language"] = code;

            var response = "Remember, you can use the command {{00}} in case you want to start again the bot";
            var message  = await TranslatorHelper.TranslateSentenceAsync(response, "en", step.ActiveDialog.State["language"].ToString());

            message = message.Replace("{{00}}", "/start");
            await step.Context.SendActivityAsync($"{message}");

            return(await step.NextAsync());
        }
コード例 #2
0
        private async Task <DialogTurnResult> EndMainDialog(WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken))
        {
            string userLanguage = await accessors.LanguagePreference.GetAsync(step.Context, () => { return(string.Empty); });

            if (string.IsNullOrEmpty(userLanguage))
            {
                throw new System.Exception("there was an issue reading the language preference");
            }

            var response = $"Hey, thanks for using this bot, now you will be redirect to use LUIS to perform intelligent interactions";
            var message  = await TranslatorHelper.TranslateSentenceAsync(response, "en", userLanguage);

            await step.Context.SendActivityAsync($"{message}");

            //ending dialog
            await step.EndDialogAsync(step.ActiveDialog.State);

            return(Dialog.EndOfTurn);
        }
コード例 #3
0
        public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (turnContext == null)
            {
                throw new ArgumentNullException(nameof(turnContext));
            }

            var dialogContext = await dialogs.CreateContextAsync(turnContext, cancellationToken);

            switch (turnContext.Activity.Type)
            {
            case ActivityTypes.ConversationUpdate:
                if (turnContext.Activity.MembersAdded.FirstOrDefault()?.Id == turnContext.Activity.Recipient.Id)
                {
                    await dialogContext.BeginDialogAsync("MainDialog", null, cancellationToken);
                }
                break;

            case ActivityTypes.Message:
                var results = await dialogContext.ContinueDialogAsync(cancellationToken);

                var text = turnContext.Activity.Text;
                if (text == "/start")
                {
                    await accessors.IsReadyForLUISPreference.DeleteAsync(turnContext);

                    await accessors.LanguagePreference.DeleteAsync(turnContext);

                    await dialogContext.EndDialogAsync();

                    await dialogContext.BeginDialogAsync("MainDialog", null, cancellationToken);
                }
                else
                {
                    if (!dialogContext.Context.Responded)
                    {
                        bool isReady = await accessors.IsReadyForLUISPreference.GetAsync(turnContext, () => { return(false); });

                        if (!isReady)
                        {
                            await dialogContext.BeginDialogAsync("MainDialog", null, cancellationToken);
                        }
                        else
                        {
                            string userLanguage = await accessors.LanguagePreference.GetAsync(turnContext, () => { return(string.Empty); });

                            turnContext.Activity.Text = await TranslatorHelper.TranslateSentenceAsync(turnContext.Activity.Text, userLanguage, "en");

                            await turnContext.SendActivityAsync($"Sending to LUIS -> {turnContext.Activity.Text}");

                            // LUIS
                            var recognizerResult = await accessors.LuisServices[Settings.LuisName01].RecognizeAsync(turnContext, cancellationToken);
                            var topIntent        = recognizerResult?.GetTopScoringIntent();
                            if (topIntent != null && topIntent.HasValue && topIntent.Value.intent != "None")
                            {
                                await ProcessIntentAsync(turnContext, topIntent.Value.intent, topIntent.Value.score, cancellationToken);
                            }
                            else
                            {
                                var response = @"No LUIS intents were found.";
                                var message  = await TranslatorHelper.TranslateSentenceAsync(response, "en", userLanguage);

                                await turnContext.SendActivityAsync(message);
                            }
                        }
                    }
                }

                break;
            }
        }