How to use the botbuilder-azure.CosmosDbStorage function in botbuilder-azure

To help you get started, we’ve selected a few botbuilder-azure examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / botframework-solutions / templates / Enterprise-Template / src / typescript / src / index.ts View on Github external
await turnContext.sendActivity("Sorry, it looks like something went wrong.");
};

// CAUTION: The Memory Storage used here is for local bot debugging only. When the bot
// is restarted, anything stored in memory will be gone.
// const storage = new MemoryStorage();

// For production bots use the Azure CosmosDB storage, Azure Blob, or Azure Table storage provides.
const CosmosDbStorage = require("botbuilder-azure").CosmosDbStorage;
const STORAGE_CONFIGURATION = process.env.STORAGE_NAME || ""; // this is the name of the cosmos DB configuration in your .bot file
const cosmosConfig: ICosmosDBService = botConfig.findServiceByNameOrId(STORAGE_CONFIGURATION) as ICosmosDBService;
if (!cosmosConfig) {
    console.log("Please configure your CosmosDB connection in your .bot file.");
    process.exit(BOT_CONFIGURATION_ERROR);
}
const storage = new CosmosDbStorage({
    authKey: cosmosConfig.key,
    collectionId: cosmosConfig.collection,
    databaseId: cosmosConfig.database,
    serviceEndpoint: cosmosConfig.endpoint,
});

// create conversation and user state with in-memory storage provider.
const conversationState = new ConversationState(storage);
const userState = new UserState(storage);

// Use the AutoSaveStateMiddleware middleware to automatically read and write conversation and user state.
// CONSIDER:  if only using userState, then switch to adapter.use(userState);
adapter.use(new AutoSaveStateMiddleware(conversationState, userState));

// Transcript Middleware (saves conversation history in a standard format)
const AzureBlobTranscriptStore = require("botbuilder-azure").AzureBlobTranscriptStore;
github microsoft / botframework-solutions / templates / Virtual-Assistant-Template / typescript / generator-botbuilder-assistant / generators / app / templates / sample-assistant / src / index.ts View on Github external
appId: botSettings.microsoftAppId,
    appPassword: botSettings.microsoftAppPassword
};

if (botSettings.cosmosDb === undefined) {
    throw new Error();
}

const cosmosDbStorageSettings: CosmosDbStorageSettings = {
    authKey: botSettings.cosmosDb.authKey,
    collectionId: botSettings.cosmosDb.collectionId,
    databaseId: botSettings.cosmosDb.databaseId,
    serviceEndpoint: botSettings.cosmosDb.cosmosDBEndpoint
};

const storage: CosmosDbStorage = new CosmosDbStorage(cosmosDbStorageSettings);
const userState: UserState = new UserState(storage);
const conversationState: ConversationState = new ConversationState(storage);

const appCredentials: MicrosoftAppCredentials = new MicrosoftAppCredentials(
    botSettings.microsoftAppId || '',
    botSettings.microsoftAppPassword || ''
);
const adapter: DefaultAdapter = new DefaultAdapter(
    botSettings,
    adapterSettings,
    telemetryClient,
    userState,
    conversationState
);
// const webSocketEnabledHttpAdapter: webSocketEnabledHttpAdapter = (botsettings, adapter))
github microsoft / botframework-solutions / templates / Virtual-Assistant-Template / typescript / samples / sample-assistant / src / adapters / defaultAdapter.ts View on Github external
adapterSettings: Partial
    ) {
        super(adapterSettings);

        if (settings.cosmosDb === undefined) {
            throw new Error('There is no cosmosDb value in appsettings file');
        }

        this.cosmosDbStorageSettings = {
            authKey: settings.cosmosDb.authkey,
            collectionId: settings.cosmosDb.collectionId,
            databaseId: settings.cosmosDb.databaseId,
            serviceEndpoint: settings.cosmosDb.cosmosDBEndpoint
        };

        const storage: CosmosDbStorage = new CosmosDbStorage(this.cosmosDbStorageSettings);

        // create conversation and user state
        this.conversationState = new ConversationState(storage);
        this.userState = new UserState(storage);
        this.proactiveState = new ProactiveState(storage);

        if (settings.blobStorage === undefined) {
            throw new Error('There is no blobStorage value in appsettings file');
        }

        this.transcriptStore = new AzureBlobTranscriptStore({
            containerName: settings.blobStorage.container,
            storageAccountOrConnectionString: settings.blobStorage.connectionString
        });

        if (settings.appInsights === undefined) {
github microsoft / botframework-solutions / templates / Virtual-Assistant-Template / typescript / samples / sample-skill / src / index.ts View on Github external
}

const telemetryClient: BotTelemetryClient = getTelemetryClient(botSettings);

if (botSettings.cosmosDb === undefined) {
    throw new Error();
}

const cosmosDbStorageSettings: CosmosDbStorageSettings = {
    authKey: botSettings.cosmosDb.authKey,
    collectionId: botSettings.cosmosDb.collectionId,
    databaseId: botSettings.cosmosDb.databaseId,
    serviceEndpoint: botSettings.cosmosDb.cosmosDBEndpoint
};

const storage: CosmosDbStorage = new CosmosDbStorage(cosmosDbStorageSettings);
const userState: UserState = new UserState(storage);
const conversationState: ConversationState = new ConversationState(storage);
const stateAccessor: StatePropertyAccessor = userState.createProperty(SkillState.name);
const dialogStateAccessor: StatePropertyAccessor = userState.createProperty('DialogState');
const skillContextAccessor: StatePropertyAccessor = userState.createProperty(SkillContext.name);

const adapterSettings: Partial = {
    appId: botSettings.microsoftAppId,
    appPassword: botSettings.microsoftAppPassword
};

const botAdapter: DefaultAdapter = new DefaultAdapter(
    botSettings,
    adapterSettings,
    userState,
    conversationState,
github microsoft / botframework-solutions / templates / Virtual-Assistant-Template / typescript / generator-botbuilder-assistant / generators / skill / templates / sample-skill / src / index.ts View on Github external
}

const telemetryClient: BotTelemetryClient = getTelemetryClient(botSettings);

if (botSettings.cosmosDb === undefined) {
    throw new Error();
}

const cosmosDbStorageSettings: CosmosDbStorageSettings = {
    authKey: botSettings.cosmosDb.authKey,
    collectionId: botSettings.cosmosDb.collectionId,
    databaseId: botSettings.cosmosDb.databaseId,
    serviceEndpoint: botSettings.cosmosDb.cosmosDBEndpoint
};

const storage: CosmosDbStorage = new CosmosDbStorage(cosmosDbStorageSettings);
const userState: UserState = new UserState(storage);
const conversationState: ConversationState = new ConversationState(storage);
const stateAccessor: StatePropertyAccessor = userState.createProperty(SkillState.name);
const dialogStateAccessor: StatePropertyAccessor = userState.createProperty('DialogState');
const skillContextAccessor: StatePropertyAccessor = userState.createProperty(SkillContext.name);

const adapterSettings: Partial = {
    appId: botSettings.microsoftAppId,
    appPassword: botSettings.microsoftAppPassword
};

const botAdapter: DefaultAdapter = new DefaultAdapter(
    botSettings,
    adapterSettings,
    userState,
    conversationState,