Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { renderWebChat } from 'botframework-webchat';
// Create the custom WebChatAdapter.
const webChatAdapter = new WebChatAdapter();
// Connect our BotFramework-WebChat instance with the DOM.
renderWebChat({
directLine: webChatAdapter.botConnection
}, document.getElementById('webchat')
);
// Instantiate MemoryStorage for use with the ConversationState class.
const memory = new MemoryStorage();
// Add the instantiated storage into ConversationState.
const conversationState = new ConversationState(memory);
// Create a property to keep track of how many messages are received from the user.
const countProperty = conversationState.createProperty('turnCounter');
// Register the business logic of the bot through the WebChatAdapter's processActivity implementation.
webChatAdapter.processActivity(async turnContext => {
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
if (turnContext.activity.type === ActivityTypes.Message) {
// Read from state.
let count = await countProperty.get(turnContext);
count = count === undefined ? 1 : count;
await turnContext.sendActivity(
`${ count }: You said "${ turnContext.activity.text }"`
);
// Increment and set turn counter.
await countProperty.set(turnContext, ++count);
import {ConversationState} from "botbuilder-core";
import {BotDebugger} from "botbuilder-dialogs";
const {MemoryStorage} = require('botbuilder-core');
const restify = require('restify');
const {default: chalk} = require('chalk');
const {BotFrameworkAdapter} = require('botbuilder');
const {EmulatorAwareBot} = require('./bot');
const memoryStorage = new MemoryStorage();
// Create conversation state with in-memory storage provider.
const conversationState = new ConversationState(memoryStorage);
const bot = new EmulatorAwareBot(conversationState);
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD,
});
if (process.env.NODE_ENV === 'development') {
new BotDebugger(memoryStorage, adapter);
}
const server = restify.createServer();
server.listen(process.env.PORT, () => {
process.stdout.write(`Bot is listening on port: ${chalk.blue(server.address().port)}`);
});
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const botbuilder_core_1 = require("botbuilder-core");
const botbuilder_dialogs_1 = require("botbuilder-dialogs");
const { MemoryStorage } = require('botbuilder-core');
const restify = require('restify');
const { default: chalk } = require('chalk');
const { BotFrameworkAdapter } = require('botbuilder');
const { EmulatorAwareBot } = require('./bot');
const memoryStorage = new MemoryStorage();
// Create conversation state with in-memory storage provider.
const conversationState = new botbuilder_core_1.ConversationState(memoryStorage);
const bot = new EmulatorAwareBot(conversationState);
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD,
});
if (process.env.NODE_ENV === 'development') {
new botbuilder_dialogs_1.BotDebugger(memoryStorage, adapter);
}
const server = restify.createServer();
server.listen(process.env.PORT, () => {
process.stdout.write(`Bot is listening on port: ${chalk.blue(server.address().port)}`);
});
server.opts('/api/messages', (req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
public constructor(targetDialog: Dialog, initialDialogOptions?: any, middlewares?: Middleware[], testAdapter?: TestAdapter, callback?: (turnContext: TurnContext) => Promise, adapterOptions?: Partial) {
let convoState = new ConversationState(new MemoryStorage());
let dialogState = convoState.createProperty('DialogState');
this._callback = callback || this.getDefaultCallback(targetDialog, initialDialogOptions || null, dialogState);
this._testAdapter = testAdapter || new TestAdapter(this._callback,adapterOptions).use(new AutoSaveStateMiddleware(convoState));
this.addUserMiddlewares(middlewares);
}