Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
const BLOB_CONFIGURATION = process.env.BLOB_NAME || ""; // this is the name of the BlobStorage configuration in your .bot file
const blobStorageConfig: IBlobStorageService = botConfig.findServiceByNameOrId(BLOB_CONFIGURATION) as IBlobStorageService;
if (!blobStorageConfig) {
console.log("Please configure your Blob storage connection in your .bot file.");
process.exit(BOT_CONFIGURATION_ERROR);
}
const blobStorage = new BlobStorageService(blobStorageConfig);
const transcriptStore = new AzureBlobTranscriptStore({
containerName: blobStorage.container,
storageAccountOrConnectionString: blobStorage.connectionString,
});
adapter.use(new TranscriptLoggerMiddleware(transcriptStore));
// Typing Middleware (automatically shows typing when the bot is responding/working) (not implemented https://github.com/Microsoft/botbuilder-js/issues/470)
// adapter.use(new ShowTypingMiddleware());
// Content Moderation Middleware (analyzes incoming messages for inappropriate content including PII, profanity, etc.)
import { ContentModeratorMiddleware } from "./middleware/contentModeratorMiddleware";
const CM_CONFIGURATION = process.env.CONTENT_MODERATOR_NAME || ""; // this is the name of the Content Moderator configuration in your .bot file
const cmConfig: IGenericService = botConfig.findServiceByNameOrId(CM_CONFIGURATION) as IGenericService;
if (cmConfig && cmConfig.configuration.key && cmConfig.configuration.region) {
const contentModerator = new ContentModeratorMiddleware(cmConfig.configuration.key, cmConfig.configuration.region);
adapter.use(contentModerator);
} else {
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) {
throw new Error('There is no appInsights value in appsettings file');
}
this.telemetryClient = new TelemetryClient(settings.appInsights.instrumentationKey);
// Use the AutoSaveStateMiddleware middleware to automatically read and write conversation and user state.
this.use(new AutoSaveStateMiddleware(this.conversationState, this.userState));
// Currently not working https://github.com/Microsoft/botbuilder-js/issues/853#issuecomment-481416004
// this.use(new TranscriptLoggerMiddleware(this.transcriptStore));
// Typing Middleware (automatically shows typing when the bot is responding/working)
this.use(new ShowTypingMiddleware());
if (settings.cosmosDb === undefined) {
throw new Error('There is no cosmosDb value in appsettings file');
}
if (settings.blobStorage === undefined) {
throw new Error('There is no blobStorage value in appsettings file');
}
if (settings.appInsights === undefined) {
throw new Error('There is no appInsights value in appsettings file');
}
if (settings.blobStorage === undefined) {
throw new Error('There is no blobStorage value in appsettings file');
}
const transcriptStore: TranscriptStore = new AzureBlobTranscriptStore({
containerName: settings.blobStorage.container,
storageAccountOrConnectionString: settings.blobStorage.connectionString
});
this.use(new TranscriptLoggerMiddleware(transcriptStore));
this.use(new TelemetryLoggerMiddleware(telemetryClient, true));
this.use(new ShowTypingMiddleware());
this.use(new SetLocaleMiddleware(settings.defaultLocale || 'en-us'));
this.use(new EventDebuggerMiddleware());
// Use the AutoSaveStateMiddleware middleware to automatically read and write conversation and user state.
this.use(new AutoSaveStateMiddleware(conversationState, userState));
}
}
public constructor(
settings: Partial,
adapterSettings: Partial,
userState: UserState,
conversationState: ConversationState,
telemetryClient: BotTelemetryClient
) {
super(adapterSettings);
if (settings.blobStorage === undefined) {
throw new Error('There is no blobStorage value in appsettings file');
}
const transcriptStore: TranscriptStore = new AzureBlobTranscriptStore({
containerName: settings.blobStorage.container,
storageAccountOrConnectionString: settings.blobStorage.connectionString
});
this.use(new TelemetryLoggerMiddleware(telemetryClient, true));
this.use(new TranscriptLoggerMiddleware(transcriptStore));
this.use(new ShowTypingMiddleware());
this.use(new SetLocaleMiddleware(settings.defaultLocale || 'en-us'));
this.use(new EventDebuggerMiddleware());
this.use(new AutoSaveStateMiddleware(conversationState, userState));
}
}
public constructor(
settings: Partial,
userState: UserState,
conversationState: ConversationState,
telemetryClient: BotTelemetryClient,
skillContextAccessor: StatePropertyAccessor,
dialogStateAccessor: StatePropertyAccessor
) {
super(telemetryClient);
if (settings.blobStorage === undefined) {
throw new Error('There is no blobStorage value in appsettings file');
}
const transcriptStore: TranscriptStore = new AzureBlobTranscriptStore({
containerName: settings.blobStorage.container,
storageAccountOrConnectionString: settings.blobStorage.connectionString
});
this.use(new TelemetryLoggerMiddleware(telemetryClient, true));
this.use(new TranscriptLoggerMiddleware(transcriptStore));
this.use(new ShowTypingMiddleware());
this.use(new SetLocaleMiddleware(settings.defaultLocale || 'en-us'));
this.use(new EventDebuggerMiddleware());
this.use(new AutoSaveStateMiddleware(conversationState, userState));
this.use(new SkillMiddleware(conversationState, dialogStateAccessor));
}
}