Search code examples
node.jsbotframeworkazure-blob-storage

Can't access blob storage locally in chatbot emulator


I used to be able to access blob storage during local testing, but I've started getting a [onTurnError]: StorageError: Forbidden message when teseting locally via emulator. I do have issues connecting to some resources from my local (notably CosmosDB), but I do believe this was working before. I have HTTPS_PROXY value set in my local .env which works for everything except Cosmos (LUIS, QnA Maker, Azure Table Storage, etc are working). So I have two questions:

  1. Has something changed and/or is it possible at all to hit Blob storage via local emulator testing through a proxy.
  2. If not, is it possible to code the bot so that it will use memory storage from my local and blob storage from Azure?

For what it's worth, here is the code I use to set up the state storage but I think the issue is accessing the services through the proxy, not defining these storage objects.

// Memory storage - for development only
const memoryStorage = new MemoryStorage();
const conversationState = new ConversationState(memoryStorage);
const userState = new UserState(memoryStorage);

// Blob storage - for production
/*const blobStorage = new BlobStorage({
    containerName: 'bot-storage',
    storageAccountOrConnectionString: process.env.blobStorageServiceName,
    storageAccessKey: process.env.blobStorageAccessKey
});
const conversationState = new ConversationState(blobStorage);
const userState = new UserState(blobStorage);*/

Solution

  • I came up with a workaround to this, but I feel like it's not a great approach. Would like to see other solutions to the issue.

    My workaround was to look at my BOTNAME environmental variable, and if it matches what I have set in my local .env file, use MemoryStorage. Otherwise use BlobStorage. It is functioning, but I hate to have extra code only for the sake of local testing.

    Here is the code in my index.js file:

    if (process.env.BOTNAME == 'OEM_CSC_Support_Bot_Local') {
        // Memory storage - for development only
        console.log(`Using MemoryStorage for state storage`);
        const memoryStorage = new MemoryStorage();
        var conversationState = new ConversationState(memoryStorage);
        var userState = new UserState(memoryStorage);
    } else {
        // Blob storage - for production
        console.log(`Using BlobStorage for state storage`);
        const blobStorage = new BlobStorage({
            containerName: 'bot-storage',
            storageAccountOrConnectionString: process.env.blobStorageServiceName,
            storageAccessKey: process.env.blobStorageAccessKey
        });
        var conversationState = new ConversationState(blobStorage);
        var userState = new UserState(blobStorage);
    }