How to use the botbuilder-core.ConversationState function in botbuilder-core

To help you get started, we’ve selected a few botbuilder-core 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 / BotBuilder-Samples / samples / javascript_es6 / 01.browser-echo / src / app.ts View on Github external
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);
github microsoft / botbuilder-js / samples / 10. sidecarDebugging / src / index.ts View on Github external
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)}`);
});
github microsoft / botbuilder-js / samples / 10. sidecarDebugging / lib / index.js View on Github external
"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();
github microsoft / botbuilder-js / libraries / botbuilder-testing / src / dialogTestClient.ts View on Github external
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);

    }