public MainDialog( IServiceProvider serviceProvider, IBotTelemetryClient telemetryClient, MicrosoftAppCredentials appCredentials, ProactiveState proactiveState) : base(nameof(MainDialog), telemetryClient) { _services = serviceProvider.GetService <BotServices>(); _settings = serviceProvider.GetService <BotSettings>(); _templateEngine = serviceProvider.GetService <LocaleTemplateEngineManager>(); TelemetryClient = telemetryClient; // Create user state properties var userState = serviceProvider.GetService <UserState>(); _userProfileState = userState.CreateProperty <UserProfileState>(nameof(UserProfileState)); _skillContext = userState.CreateProperty <SkillContext>(nameof(SkillContext)); // Create conversation state properties var conversationState = serviceProvider.GetService <ConversationState>(); _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse); // SAMPLE: Create proactive state properties _appCredentials = appCredentials; _proactiveStateAccessor = proactiveState.CreateProperty <ProactiveModel>(nameof(ProactiveModel)); // Register dialogs _onboardingDialog = serviceProvider.GetService <OnboardingDialog>(); _switchSkillDialog = serviceProvider.GetService <SwitchSkillDialog>(); AddDialog(_onboardingDialog); AddDialog(_switchSkillDialog); // Register a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided. var localizedServices = _services.GetCognitiveModels(); foreach (var knowledgebase in localizedServices.QnAConfiguration) { var qnaDialog = new QnAMakerDialog( knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId, endpointKey: knowledgebase.Value.EndpointKey, hostName: knowledgebase.Value.Host, noAnswer: _templateEngine.GenerateActivityForLocale("UnsupportedMessage"), activeLearningCardTitle: _templateEngine.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text, cardNoMatchText: _templateEngine.GenerateActivityForLocale("QnaMakerNoMatchText").Text) { Id = knowledgebase.Key }; AddDialog(qnaDialog); } // Register skill dialogs var skillDialogs = serviceProvider.GetServices <SkillDialog>(); foreach (var dialog in skillDialogs) { AddDialog(dialog); } }
public async Task Cumprimento(IDialogContext context, LuisResult result) { ConversationStarter.TextReference = string.Empty; await context.PostAsync($"Texto enviado: {result.Query}"); var qnaService = new QnAMakerService(new QnAMakerAttribute(qnaSubscriptionKey, qnaKnowledgebaseId, "Buguei aqui, pera! ¯\(º_o)/¯")); var qnaMaker = new QnAMakerDialog(qnaService); await qnaMaker.MessageReceivedAsync(context, Awaitable.FromItem(activity)); }
public MainDialog( IServiceProvider serviceProvider, IBotTelemetryClient telemetryClient) : base(nameof(MainDialog)) { _services = serviceProvider.GetService <BotServices>(); _settings = serviceProvider.GetService <BotSettings>(); _templateEngine = serviceProvider.GetService <LocaleTemplateEngineManager>(); _skillsConfig = serviceProvider.GetService <SkillsConfiguration>(); TelemetryClient = telemetryClient; var conversationState = serviceProvider.GetService <ConversationState>(); _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse); var steps = new WaterfallStep[] { RouteStepAsync, }; AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(nameof(TextPrompt))); InitialDialogId = nameof(MainDialog); // Register dialogs _switchSkillDialog = serviceProvider.GetService <TeamsSwitchSkillDialog>(); AddDialog(_switchSkillDialog); // Register a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided. var localizedServices = _services.GetCognitiveModels(); foreach (var knowledgebase in localizedServices.QnAConfiguration) { var qnaDialog = new QnAMakerDialog( knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId, endpointKey: knowledgebase.Value.EndpointKey, hostName: knowledgebase.Value.Host, noAnswer: _templateEngine.GenerateActivityForLocale("UnsupportedMessage"), activeLearningCardTitle: _templateEngine.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text, cardNoMatchText: _templateEngine.GenerateActivityForLocale("QnaMakerNoMatchText").Text) { Id = knowledgebase.Key }; AddDialog(qnaDialog); } // Register skill dialogs var skillDialogs = serviceProvider.GetServices <TeamsSkillDialog>(); foreach (var dialog in skillDialogs) { AddDialog(dialog); } }
public override async Task <object> FulfillAsync(IDialogContext context = null, string messageText = "") { var qnaModels = new QnAMakerAttribute(subscriptionKey: ConfigurationManager.AppSettings["SubscriptionKey"], knowledgebaseId: ConfigurationManager.AppSettings["KnowledgeBaseId"], defaultMessage: Resources.ChatBot.NoMatchMessage, scoreThreshold: 0.2, top: 4); var qnaMakerDialog = new QnAMakerDialog(new List <IQnAService> { new QnAMakerService(qnaModels) }.ToArray()); await context.Forward(qnaMakerDialog, ResumeAfterQnAMakerDialog, context.Activity.AsMessageActivity(), CancellationToken.None); return(Task.FromResult((object)"")); }
private void LoadDialogs() { System.Diagnostics.Trace.TraceInformation("Loading resources..."); // Create a non-used dialog just to make sure the target assembly is referred so that // the target assembly's component registration can be used to deserialize declarative components var qnaDialog = new QnAMakerDialog(); System.Diagnostics.Trace.TraceInformation($"Touch ${qnaDialog.GetType().ToString()} to make sure assembly is referred."); var rootDialog = new AdaptiveDialog() { AutoEndDialog = false, }; var choiceInput = new ChoiceInput() { Prompt = new ActivityTemplate("What declarative sample do you want to run?"), Property = "conversation.dialogChoice", AlwaysPrompt = true, Choices = new ChoiceSet(new List <Choice>()) }; var handleChoice = new SwitchCondition() { Condition = "conversation.dialogChoice", Cases = new List <Case>() }; Dialog lastDialog = null; var choices = new ChoiceSet(); foreach (var resource in this.resourceExplorer.GetResources(".dialog").Where(r => r.Id.EndsWith(".main.dialog"))) { try { var name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(resource.Id)); choices.Add(new Choice(name)); var dialog = resourceExplorer.LoadType <Dialog>(resource); lastDialog = dialog; handleChoice.Cases.Add(new Case($"{name}", new List <Dialog>() { dialog })); } catch (SyntaxErrorException err) { Trace.TraceError($"{err.Source}: Error: {err.Message}"); } catch (Exception err) { Trace.TraceError(err.Message); } } if (handleChoice.Cases.Count() == 1) { rootDialog.Triggers.Add(new OnBeginDialog { Actions = new List <Dialog> { lastDialog, new RepeatDialog() } }); } else { choiceInput.Choices = choices; choiceInput.Style = ListStyle.Auto; rootDialog.Triggers.Add(new OnBeginDialog() { Actions = new List <Dialog>() { choiceInput, new SendActivity("# Running ${conversation.dialogChoice}.main.dialog"), handleChoice, new RepeatDialog() } }); } this.dialogManager = new DialogManager(rootDialog) .UseResourceExplorer(this.resourceExplorer) .UseLanguageGeneration(); Trace.TraceInformation("Done loading resources."); }
public async Task Apresentacao(IDialogContext context, LuisResult result) { var qnaService = new QnAMakerService(new QnAMakerAttribute(qnaSubscriptionKey, qnaKnowledgebaseId, "Buguei aqui, pera! ¯\(º_o)/¯")); var qnaMaker = new QnAMakerDialog(qnaService); await qnaMaker.MessageReceivedAsync(context, Awaitable.FromItem(ArgumentoStatic.Argument)); }
public MainDialog( IServiceProvider serviceProvider, IBotTelemetryClient telemetryClient ) : base(nameof(MainDialog)) { _services = serviceProvider.GetService <BotServices>(); _settings = serviceProvider.GetService <BotSettings>(); _templateManager = serviceProvider.GetService <LocaleTemplateManager>(); _skillsConfig = serviceProvider.GetService <SkillsConfiguration>(); _feedbackOptions = serviceProvider.GetService <FeedbackOptions>(); TelemetryClient = telemetryClient; var userState = serviceProvider.GetService <UserState>(); _userProfileState = userState.CreateProperty <UserProfileState>(nameof(UserProfileState)); var conversationState = serviceProvider.GetService <ConversationState>(); _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse); _feedbackAccessor = conversationState.CreateProperty <FeedbackRecord>(nameof(FeedbackRecord)); var steps = new List <WaterfallStep>() { OnboardingStepAsync, IntroStepAsync, RouteStepAsync, }; if (_feedbackOptions.FeedbackEnabled) { steps.Add(RequestFeedback); steps.Add(RequestFeedbackComment); steps.Add(ProcessFeedback); AddDialog(new TextPrompt(DialogIds.FeedbackPrompt)); AddDialog(new TextPrompt(DialogIds.FeedbackCommentPrompt)); } steps.Add(FinalStepAsync); AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(DialogIds.NextActionPrompt)); InitialDialogId = nameof(MainDialog); // Register dialogs _onboardingDialog = serviceProvider.GetService <OnboardingDialog>(); _switchSkillDialog = serviceProvider.GetService <SwitchSkillDialog>(); AddDialog(_onboardingDialog); AddDialog(_switchSkillDialog); // Register a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided. var localizedServices = _services.GetCognitiveModels(); foreach (var knowledgebase in localizedServices.QnAConfiguration) { var qnaDialog = new QnAMakerDialog( knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId, endpointKey: knowledgebase.Value.EndpointKey, hostName: knowledgebase.Value.Host, noAnswer: _templateManager.GenerateActivityForLocale("UnsupportedMessage"), activeLearningCardTitle: _templateManager.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text, cardNoMatchText: _templateManager.GenerateActivityForLocale("QnaMakerNoMatchText").Text) { Id = knowledgebase.Key }; AddDialog(qnaDialog); } // Register skill dialogs var skillDialogs = serviceProvider.GetServices <SkillDialog>(); foreach (var dialog in skillDialogs) { AddDialog(dialog); } }
public MainDialog( IServiceProvider serviceProvider, IBotTelemetryClient telemetryClient) : base(nameof(MainDialog), serviceProvider, telemetryClient) { _services = serviceProvider.GetService <BotServices>(); _settings = serviceProvider.GetService <BotSettings>(); _templateEngine = serviceProvider.GetService <LocaleTemplateEngineManager>(); _skillsConfig = serviceProvider.GetService <SkillsConfiguration>(); var userState = serviceProvider.GetService <UserState>(); _userProfileState = userState.CreateProperty <UserProfileState>(nameof(UserProfileState)); var conversationState = serviceProvider.GetService <ConversationState>(); _previousResponseAccessor = conversationState.CreateProperty <List <Activity> >(StateProperties.PreviousBotResponse); WaterfallStep[] steps = SetupWaterfallSteps(); AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(nameof(TextPrompt))); AddDialog(new ChoicePrompt(nameof(ChoicePrompt)) { Style = ListStyle.HeroCard }); InitialDialogId = nameof(MainDialog); // Register dialogs _oauthPrompt = serviceProvider.GetService <OAuthPrompt>(); _loginDialog = serviceProvider.GetService <LoginDialog>(); _onboardingDialog = serviceProvider.GetService <OnboardingDialog>(); _switchSkillDialog = serviceProvider.GetService <SwitchSkillDialog>(); _escalateDialog = serviceProvider.GetService <EscalateDialog>(); _cancelDialog = serviceProvider.GetService <CancelDialog>(); _entertainDialog = serviceProvider.GetService <EntertainDialog>(); _chitchatdialog = serviceProvider.GetService <ChitchatDialog>(); _stressDialog = serviceProvider.GetService <StressDialog>(); _highstresshandlingDialog = serviceProvider.GetService <HighStressHandlingDialog>(); _stresshandlingDialog = serviceProvider.GetService <StressHandlingDialog>(); _journalingDialog = serviceProvider.GetService <JournalingDialog>(); AddDialog(_oauthPrompt); AddDialog(_loginDialog); AddDialog(_onboardingDialog); AddDialog(_switchSkillDialog); AddDialog(_escalateDialog); AddDialog(_cancelDialog); AddDialog(_entertainDialog); AddDialog(_chitchatdialog); AddDialog(_stressDialog); AddDialog(_highstresshandlingDialog); AddDialog(_stresshandlingDialog); AddDialog(_journalingDialog); // Register a QnAMakerDialog for each registered knowledgebase and ensure localised responses are provided. var localizedServices = _services.GetCognitiveModels(); foreach (var knowledgebase in localizedServices.QnAConfiguration) { var qnaDialog = new QnAMakerDialog( knowledgeBaseId: knowledgebase.Value.KnowledgeBaseId, endpointKey: knowledgebase.Value.EndpointKey, hostName: knowledgebase.Value.Host, noAnswer: _templateEngine.GenerateActivityForLocale("UnsupportedMessage"), activeLearningCardTitle: _templateEngine.GenerateActivityForLocale("QnaMakerAdaptiveLearningCardTitle").Text, cardNoMatchText: _templateEngine.GenerateActivityForLocale("QnaMakerNoMatchText").Text) { Id = knowledgebase.Key }; AddDialog(qnaDialog); } // Register skill dialogs var skillDialogs = serviceProvider.GetServices <SkillDialog>(); foreach (var dialog in skillDialogs) { AddDialog(dialog); } }
public async Task Cumprimento(IDialogContext context, LuisResult result) { var qnaService = new QnAMakerService(new QnAMakerAttribute(qnaSubscriptionKey, qnaKnowledgebaseId, "eh o que maluco ? ¯\(º_o)/¯")); var qnaMaker = new QnAMakerDialog(qnaService); await qnaMaker.MessageReceivedAsync(context, Awaitable.FromItem(messageActivity)); }