public IWantANewWatchDialog(IStatePropertyAccessor <UserData> botStateAccessor, IConfiguration configuration, BotConfigOptions botConfigOptions)
            : base(nameof(IWantANewWatchDialog))
        {
            BotStateAccessor  = botStateAccessor ?? throw new ArgumentNullException(nameof(botStateAccessor));
            _botConfigOptions = botConfigOptions;

            SiteImagesPath       = configuration["imageHostUrl"];
            TextAnalyticsService = new TextAnalyticsService(configuration["textAnalyticsKey"], configuration["region"]);
            CustomVisionService  = new CustomVisionService(configuration["customVisionKey"], configuration["customVisionProjectId"]);
            ProductService       = new ProductService(configuration);

            // This array defines how the Waterfall will execute.
            var waterfallSteps = new WaterfallStep[]
            {
                CheckWatchesStepAsync,
                AskforPhotoStepAsync,
                SearchWatchesStepAsync,
            };

            // Add named dialogs to the DialogSet. These names are saved in the dialog state.
            AddDialog(new WaterfallDialog(SearchWatches, waterfallSteps));
            AddDialog(new TextPrompt(ConfirmWatchFound));
            AddDialog(new AttachmentPrompt(AskForImage, ImageValidatorAsync));
            AddDialog(new TextPrompt(SearchSimilarWatches));
        }
Exemple #2
0
        public static ConnectorClient GetConnectorClient(string serviceUrl, BotConfigOptions botConfigOptions)
        {
            if (botConfigOptions != null && string.IsNullOrEmpty(botConfigOptions.MicrosoftAppId))
            {
                var appId       = botConfigOptions.MicrosoftAppId;
                var appPassword = botConfigOptions.MicrosoftAppPassword;
                return(new ConnectorClient(new Uri(serviceUrl), appId, appPassword));
            }

            return(new ConnectorClient(new Uri(serviceUrl)));
        }
Exemple #3
0
        public TellMeWhatToWearDialog(IStatePropertyAccessor <Models.UserData> userDataStateAccessor, IConfiguration configuration, BotConfigOptions botConfigOptions)
            : base(nameof(TellMeWhatToWearDialog))
        {
            UserStateAccessor = userDataStateAccessor ?? throw new ArgumentNullException(nameof(userDataStateAccessor));
            ProductService    = new ProductService(configuration);
            SpeechService     = new SpeechService(configuration);
            _botConfigOptions = botConfigOptions;

            // Add control flow dialogs
            var waterfallSteps = new WaterfallStep[]
            {
                UploadPictureStepAsync,
                FindSimilarProductsStepAsync,
            };

            AddDialog(new WaterfallDialog(FindSimilarProductsDialog, waterfallSteps));
            AddDialog(new AttachmentPrompt(UploadPicturePrompt));
            AddDialog(new TextPrompt(FindSimilarProductsPrompt));
        }
Exemple #4
0
        public SmartRetailBot(BotAccessors accessors, BotConfigOptions botConfigOptions, ILoggerFactory loggerFactory, IConfiguration configuration, LuisRecognizer luisRecognizer)
        {
            SiteImagesPath = configuration["imageHostUrl"];
            ProductService = new ProductService(configuration);
            SpeechService  = new SpeechService(configuration);

            _botConfigOptions = botConfigOptions;
            _accessors        = accessors ?? throw new System.ArgumentNullException(nameof(accessors));

            // Initialize the LUIS recognizer
            _luis = luisRecognizer;

            // The DialogSet needs a DialogState accessor, it will call it when it has a turn context.
            _dialogs = new DialogSet(accessors.ConversationDialogState);

            // Dialog for the IWantAWatch Intent
            _dialogs.Add(new IWantANewWatchDialog(_accessors.UserData, configuration, _botConfigOptions));

            // Dialog for the TryWatch Intent
            _dialogs.Add(new TryWatchDialog(_accessors.UserData, configuration));

            // Dialog for the TellMeWhatToWear Intent
            _dialogs.Add(new TellMeWhatToWearDialog(_accessors.UserData, configuration, _botConfigOptions));
        }
Exemple #5
0
        /// <summary>
        /// Uploads a file and creates an <see cref="Attachment"/> with the uploaded file url.
        /// </summary>
        /// <returns>An attachment.</returns>
        public static async Task <Attachment> CreateAndUploadAttachmentAsync(string serviceUrl, string type, string conversationId, byte[] file, string attName, BotConfigOptions _botConfigOptions)
        {
            // Create a connector client to use to upload the image.
            using (var connector = BotUtils.GetConnectorClient(serviceUrl, _botConfigOptions))
            {
                var attachments = new Attachments(connector);
                var response    = await attachments.Client.Conversations.UploadAttachmentAsync(
                    conversationId,
                    new AttachmentData
                {
                    Name           = attName,
                    OriginalBase64 = file,
                    Type           = type,
                });

                var attachmentUri = attachments.GetAttachmentUri(response.Id);

                return(new Attachment
                {
                    Name = attName,
                    ContentType = type,
                    ContentUrl = attachmentUri,
                });
            }
        }