Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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))
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) {
}
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,
}
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,