public OnboardingDialog( IServiceProvider serviceProvider) : base(nameof(OnboardingDialog)) { _templateManager = serviceProvider.GetService <LocaleTemplateManager>(); var userState = serviceProvider.GetService <UserState>(); _accessor = userState.CreateProperty <UserProfileState>(nameof(UserProfileState)); _services = serviceProvider.GetService <BotServices>(); var onboarding = new WaterfallStep[] { AskForNameAsync, FinishOnboardingDialogAsync, }; AddDialog(new WaterfallDialog(nameof(onboarding), onboarding)); AddDialog(new TextPrompt(DialogIds.NamePrompt)); }
public static Activity GenerateActivity(this LocaleTemplateManager manager, string templateId, IEnumerable <Card> cards, object tokens = null, string attachmentLayout = "carousel") { var input = new { Data = tokens, Cards = cards.Select((card) => { return(Convert(card)); }).ToArray(), Layout = attachmentLayout, }; try { return(manager.GenerateActivityForLocale(templateId, input)); } catch (Exception ex) { var result = Activity.CreateMessageActivity(); result.Text = ex.Message; return((Activity)result); } }
private async Task <DialogTurnResult> GetAndSendMusicResultAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var state = await StateAccessor.GetAsync(stepContext.Context, cancellationToken : cancellationToken); var status = false; // Get music api client IMusicService musicService = ServiceManager.InitMusicService(); // Extract query entity to search against Spotify for var searchQuery = state.Query; var genres = state.Genres; string searchItems = null; // Search music if given music info like artist/track/album/playlist or genres. Without info, we just get a recommendation album. if (!string.IsNullOrEmpty(searchQuery) || genres?.Count != 0) { searchItems = await musicService.SearchMusicAsync(searchQuery, genres); } else { searchItems = await musicService.GetNewAlbumReleasesAsync(); } if (!string.IsNullOrEmpty(searchItems)) { status = true; await SendOpenDefaultAppEventActivityAsync(stepContext, searchItems, cancellationToken); } else { await stepContext.Context.SendActivityAsync(LocaleTemplateManager.GenerateActivityForLocale(MainResponses.NoResultstMessage), cancellationToken); } // End dialog return(await stepContext.EndDialogAsync(new Models.ActionInfos.ActionResult() { ActionSuccess = status }, cancellationToken)); }
public static Activity ShowTrendingCards(ITurnContext context, LocaleTemplateManager localeTemplateEngineManager, dynamic data) { var response = context.Activity.CreateReply(); var articles = data as List <NewsTopic>; if (articles.Any()) { var trendingResponse = localeTemplateEngineManager.GenerateActivityForLocale(FavoriteTopicsResponses.ShowFavoriteTopics, new { Count = articles.Count, Article = articles[0] }); response.Text = trendingResponse.Text; response.Speak = trendingResponse.Speak; response.Attachments = new List <Attachment>(); response.AttachmentLayout = AttachmentLayoutTypes.Carousel; foreach (var item in articles) { var card = new HeroCard() { Title = item.Name, Images = item?.Image?.Url != null ? new List <CardImage>() { new CardImage(item.Image.Url), } : null, Buttons = new List <CardAction>() { new CardAction(ActionTypes.OpenUrl, title: localeTemplateEngineManager.GenerateActivityForLocale(MainStrings.ReadMore).Text, value: item.WebSearchUrl) }, }.ToAttachment(); response.Attachments.Add(card); } } else { response = localeTemplateEngineManager.GenerateActivityForLocale(TrendingArticlesResponses.NoTrending); } return(response); }
public static Activity GetCardResponse(this LocaleTemplateManager manager, string templateId, Card card, IDictionary <string, object> tokens = null, string containerName = null, IEnumerable <Card> containerItems = null) { throw new Exception("1. create *Containee.new.json which only keeps containee's body;2. in the container, write @{if(Cards==null,'',join(foreach(Cards,Card,CreateStringNoContainer(Card.Name,Card.Data)),','))}"); /* * var input = new * { * Data = tokens, * Cards = new CardExt[] { Convert(card, containerItems: containerItems) }, * }; * try * { * return manager.GenerateActivityForLocale(templateId, input); * } * catch (Exception ex) * { * var result = Activity.CreateMessageActivity(); * result.Text = ex.Message; * return (Activity)result; * } */ }
public DefaultAdapter( BotSettings settings, ICredentialProvider credentialProvider, IChannelProvider channelProvider, AuthenticationConfiguration authConfig, LocaleTemplateManager templateEngine, ConversationState conversationState, TelemetryInitializerMiddleware telemetryMiddleware, IBotTelemetryClient telemetryClient, ILogger <BotFrameworkHttpAdapter> logger, LoggingMiddleware loggingMiddleware, HandoffMiddleware handoffMiddleware, SkillsConfiguration skillsConfig = null, SkillHttpClient skillClient = null) : base(credentialProvider, authConfig, channelProvider, logger: logger) { _conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _templateEngine = templateEngine ?? throw new ArgumentNullException(nameof(templateEngine)); _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); _skillClient = skillClient; _skillsConfig = skillsConfig; _settings = settings; OnTurnError = HandleTurnErrorAsync; Use(telemetryMiddleware); Use(loggingMiddleware); Use(handoffMiddleware); // Uncomment the following line for local development without Azure Storage // Use(new TranscriptLoggerMiddleware(new MemoryTranscriptStore())); Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container))); Use(new ShowTypingMiddleware()); Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us")); Use(new EventDebuggerMiddleware()); Use(new SetSpeakMiddleware()); }
public MainDialog( IServiceProvider serviceProvider) : base(nameof(MainDialog)) { _settings = serviceProvider.GetService <BotSettings>(); _services = serviceProvider.GetService <BotServices>(); _templateManager = serviceProvider.GetService <LocaleTemplateManager>(); // Create conversation state properties var conversationState = serviceProvider.GetService <ConversationState>(); _stateAccessor = conversationState.CreateProperty <EmailSkillState>(nameof(EmailSkillState)); var steps = new WaterfallStep[] { IntroStepAsync, RouteStepAsync, FinalStepAsync, }; AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(nameof(TextPrompt))); InitialDialogId = nameof(MainDialog); // Register dialogs _forwardEmailDialog = serviceProvider.GetService <ForwardEmailDialog>() ?? throw new ArgumentNullException(nameof(_forwardEmailDialog)); _sendEmailDialog = serviceProvider.GetService <SendEmailDialog>() ?? throw new ArgumentNullException(nameof(_sendEmailDialog)); _showEmailDialog = serviceProvider.GetService <ShowEmailDialog>() ?? throw new ArgumentNullException(nameof(_showEmailDialog)); _replyEmailDialog = serviceProvider.GetService <ReplyEmailDialog>() ?? throw new ArgumentNullException(nameof(_replyEmailDialog)); _deleteEmailDialog = serviceProvider.GetService <DeleteEmailDialog>() ?? throw new ArgumentNullException(nameof(_deleteEmailDialog)); AddDialog(_forwardEmailDialog); AddDialog(_sendEmailDialog); AddDialog(_showEmailDialog); AddDialog(_replyEmailDialog); AddDialog(_deleteEmailDialog); GetReadingDisplayConfig(); }
public MainDialog( IServiceProvider serviceProvider) : base(nameof(MainDialog)) { _services = serviceProvider.GetService <BotServices>(); _templateManager = serviceProvider.GetService <LocaleTemplateManager>(); _serviceManager = serviceProvider.GetService <IServiceManager>(); _settings = serviceProvider.GetService <BotSettings>(); // Initialize state accessor var conversationState = serviceProvider.GetService <ConversationState>(); _stateAccessor = conversationState.CreateProperty <PointOfInterestSkillState>(nameof(PointOfInterestSkillState)); var steps = new WaterfallStep[] { IntroStepAsync, RouteStepAsync, FinalStepAsync, }; AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(nameof(TextPrompt))); InitialDialogId = nameof(MainDialog); // Register dialogs _routeDialog = serviceProvider.GetService <RouteDialog>() ?? throw new ArgumentNullException(nameof(RouteDialog)); _cancelRouteDialog = serviceProvider.GetService <CancelRouteDialog>() ?? throw new ArgumentNullException(nameof(CancelRouteDialog)); _findPointOfInterestDialog = serviceProvider.GetService <FindPointOfInterestDialog>() ?? throw new ArgumentNullException(nameof(FindPointOfInterestDialog)); _findParkingDialog = serviceProvider.GetService <FindParkingDialog>() ?? throw new ArgumentNullException(nameof(FindParkingDialog)); _getDirectionsDialog = serviceProvider.GetService <GetDirectionsDialog>() ?? throw new ArgumentNullException(nameof(GetDirectionsDialog)); AddDialog(_routeDialog); AddDialog(_cancelRouteDialog); AddDialog(_findPointOfInterestDialog); AddDialog(_findParkingDialog); AddDialog(_getDirectionsDialog); }
public MainDialog( IServiceProvider serviceProvider) : base(nameof(MainDialog)) { _services = serviceProvider.GetService <BotServices>(); _hotelService = serviceProvider.GetService <IHotelService>(); _templateManager = serviceProvider.GetService <LocaleTemplateManager>(); // Create conversation state properties var conversationState = serviceProvider.GetService <ConversationState>(); _stateAccessor = conversationState.CreateProperty <HospitalitySkillState>(nameof(HospitalitySkillState)); var userState = serviceProvider.GetService <UserState>(); _userStateAccessor = userState.CreateProperty <HospitalityUserSkillState>(nameof(HospitalityUserSkillState)); var steps = new WaterfallStep[] { IntroStepAsync, RouteStepAsync, FinalStepAsync, }; AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(nameof(TextPrompt))); InitialDialogId = nameof(MainDialog); // Register dialogs AddDialog(serviceProvider.GetService <CheckOutDialog>()); AddDialog(serviceProvider.GetService <LateCheckOutDialog>()); AddDialog(serviceProvider.GetService <ExtendStayDialog>()); AddDialog(serviceProvider.GetService <GetReservationDialog>()); AddDialog(serviceProvider.GetService <RequestItemDialog>()); AddDialog(serviceProvider.GetService <RoomServiceDialog>()); }
public MainDialog( IServiceProvider serviceProvider, ResourceExplorer resourceExplorer) : base(nameof(MainDialog)) { _services = serviceProvider.GetService <BotServices>(); _templateEngine = serviceProvider.GetService <LocaleTemplateManager>(); var steps = new WaterfallStep[] { IntroStepAsync }; AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(nameof(TextPrompt))); InitialDialogId = nameof(MainDialog); //from instructions: https://microsoft.github.io/botframework-solutions/skills/handbook/experimental-add-composer/ var dialogResource = resourceExplorer.GetResource("Composer-With-Skill.dialog"); var composerDialog = resourceExplorer.LoadType <AdaptiveDialog>(dialogResource); // Add the dialog AddDialog(composerDialog); }
public static Activity GenerateActivity(this LocaleTemplateManager manager, string templateId, Card card, IDictionary <string, object> tokens = null, string containerName = null, IEnumerable <Card> containerItems = null) { if (string.IsNullOrEmpty(templateId)) { templateId = CardsOnly; } var input = new { Data = tokens, Cards = new CardExt[] { Convert(card, containerItems: containerItems) }, }; try { return(manager.GenerateActivityForLocale(templateId, input)); } catch (Exception ex) { var result = Activity.CreateMessageActivity(); result.Text = ex.Message; return((Activity)result); } }
public MainDialog( IServiceProvider serviceProvider) : base(nameof(MainDialog)) { _services = serviceProvider.GetService <BotServices>(); _templateEngine = serviceProvider.GetService <LocaleTemplateManager>(); var steps = new WaterfallStep[] { IntroStepAsync, RouteStepAsync, FinalStepAsync, }; AddDialog(new WaterfallDialog(nameof(MainDialog), steps)); AddDialog(new TextPrompt(nameof(TextPrompt))); InitialDialogId = nameof(MainDialog); // Register dialogs _sampleDialog = serviceProvider.GetService <SampleDialog>(); _sampleAction = serviceProvider.GetService <SampleAction>(); AddDialog(_sampleDialog); AddDialog(_sampleAction); }
public static string GetString(this LocaleTemplateManager manager, string templateId) { // Not use .Text in case text and speak are different return(manager.GenerateActivityForLocale(templateId).Text); }
public static Activity GenerateActivity(this LocaleTemplateManager manager, string templateId, IDictionary <string, object> tokens = null) { return(manager.GenerateActivity(templateId, Array.Empty <Card>(), tokens)); }
public static Activity GenerateActivity(this LocaleTemplateManager manager, string templateId, Card card, IDictionary <string, object> tokens = null) { return(manager.GenerateActivity(templateId, new Card[] { card }, tokens)); }
public static Activity GenerateActivity(this LocaleTemplateManager manager, IEnumerable <Card> cards, string attachmentLayout = "carousel") { return(manager.GenerateActivity(CardsOnly, cards, null, attachmentLayout)); }
public static Activity GenerateActivity(this LocaleTemplateManager manager, Card card) { return(manager.GenerateActivity(new Card[] { card })); }
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 virtual void Initialize() { Services = new ServiceCollection().AddLogging(config => config.AddConsole()); Services.AddSingleton(new BotSettings()); Services.AddSingleton(new BotServices() { // Non US languages are empty as Dispatch/LUIS not required for localization tests. CognitiveModelSets = new Dictionary <string, CognitiveModelSet> { { "en-us", new CognitiveModelSet { DispatchService = DispatchTestUtil.CreateRecognizer(), LuisServices = new Dictionary <string, LuisRecognizer> { { "General", GeneralTestUtil.CreateRecognizer() } }, QnAConfiguration = new Dictionary <string, Microsoft.Bot.Builder.AI.QnA.QnAMakerEndpoint> { { "Chitchat", new QnAMakerEndpoint { KnowledgeBaseId = _knowledgeBaseId, EndpointKey = _endpointKey, Host = _hostname } } } } }, { "zh-cn", new CognitiveModelSet { } }, { "fr-fr", new CognitiveModelSet { } }, { "es-es", new CognitiveModelSet { } }, { "de-de", new CognitiveModelSet { } }, { "it-it", new CognitiveModelSet { } } } }); Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>(); Services.AddSingleton(new MicrosoftAppCredentials("appId", "password")); Services.AddSingleton(new UserState(new MemoryStorage())); Services.AddSingleton(new ConversationState(new MemoryStorage())); // For localization testing CultureInfo.CurrentUICulture = new CultureInfo("en-us"); var localizedTemplates = new Dictionary <string, string>(); var templateFile = "AllResponses"; var supportedLocales = new List <string>() { "en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn" }; foreach (var locale in supportedLocales) { // LG template for en-us does not include locale in file extension. var localeTemplateFile = locale.Equals("en-us") ? Path.Combine(".", "Responses", $"{templateFile}.lg") : Path.Combine(".", "Responses", $"{templateFile}.{locale}.lg"); localizedTemplates.Add(locale, localeTemplateFile); } TestLocaleTemplateManager = new LocaleTemplateManager(localizedTemplates, "en-us"); Services.AddSingleton(TestLocaleTemplateManager); Services.AddTransient <MockMainDialog>(); Services.AddTransient <OnboardingDialog>(); Services.AddTransient <SwitchSkillDialog>(); Services.AddTransient <List <SkillDialog> >(); Services.AddSingleton <TestAdapter, DefaultTestAdapter>(); Services.AddTransient <IBot, DefaultActivityHandler <MockMainDialog> >(); // Add MicrosoftAPPId to configuration var configuration = new Mock <IConfiguration>(); var configurationSection = new Mock <IConfigurationSection>(); configurationSection.Setup(a => a.Value).Returns("testvalue"); configuration.Setup(a => a.GetSection("MicrosoftAppId")).Returns(configurationSection.Object); // Register configuration Services.AddSingleton(configuration.Object); TestUserProfileState = new UserProfileState(); TestUserProfileState.Name = "Bot"; }
public static string GetString(this LocaleTemplateManager manager, string templateId) { return(manager.GenerateActivityForLocale(templateId + ".Text").Text); }