How to use botframework-connector - 10 common examples

To help you get started, we’ve selected a few botframework-connector 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-js / samples / redux-bot-es6 / app.js View on Github external
// Create store
const store = redux.createStore(conversation.store, 
    redux.applyMiddleware(
        // our custom Redux middleware
        lowerCase,
        // and a popular piece of Redux middleware from npm
        createLogger()
));

// Create the authenticator (for inbound activities) and the credentials (for outbound activities)
const botCredentials = {
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
};
const authenticator = new SimpleCredentialProvider(botCredentials.appId, botCredentials.appPassword);
const credentials = new MicrosoftAppCredentials(botCredentials.appId, botCredentials.appPassword);;

// Redux provides a simple pub-sub model that we can use to help organize our application logic in a decoupled way

server.post('/api/messages', (req, res) => {

    console.log('processReq:', req.body);

    let activity = req.body;

    // authenticate request
    JwtTokenValidation.assertValidActivity(activity, req.headers.authorization, authenticator).then(() => {

        // dispatch the inbound activity to redux
        store.dispatch({ type: activity.type, activity: activity });

        res.send(202);
github microsoft / botbuilder-js / samples / redux-bot-es6 / app.js View on Github external
store.subscribe(() => {
    const state = store.getState();
    if (state) {
        const last = state[state.length - 1];
        if (last && last.bot) {
            const activity = last.bot;

            const client = new ConnectorClient(credentials, activity.serviceUrl);

            if (last.replyToId) {
                // in this case we know this was a reply to an inbound activity
                client.conversations.replyToActivity(activity.conversation.id, last.replyToId, activity)
                .then(() => {
                    console.log('reply send with id: ' + last.replyToId);
                });
            }
            else {
                // otherwise just send the activity to teh conversation
                client.conversations.sendToConversation(activity.conversation.id, activity)
                    .then(() => {
                        console.log('sent activity to conversation');
                    });
            }
        }
github microsoft / botbuilder-js / samples / echobot-connector-es6 / app.js View on Github external
JwtTokenValidation.assertValidActivity(activity, req.headers.authorization, authenticator).then(() => {

        // On message activity, reply with the same text
        if (activity.type ===  ActivityTypes.Message) {
            var reply = createReply(activity, `You said: ${activity.text}`);
            const client = new ConnectorClient(credentials, activity.serviceUrl);
            client.conversations.replyToActivity(activity.conversation.id, activity.id, reply)
                .then((reply) => {
                    console.log('reply send with id: ' + reply.id);
                });
        }

        res.send(202);
    }).catch(err => {
        console.log('Could not authenticate request:', err);
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 80.skills-simple-bot-to-bot / simple-root-bot / index.js View on Github external
// A bot requires a state store to persist the dialog and user state between messages.

// For local development, in-memory storage is used.
// 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 memoryStorage = new MemoryStorage();
const conversationState = new ConversationState(memoryStorage);

// Create the conversationIdFactory
const conversationIdFactory = new SkillConversationIdFactory();

// Load skills configuration
const skillsConfig = new SkillsConfiguration();

// Create the credential provider;
const credentialProvider = new SimpleCredentialProvider(process.env.MicrosoftAppId, process.env.MicrosoftAppPassword);

// Create the skill client
const skillClient = new SkillHttpClient(credentialProvider, conversationIdFactory);

// Create the main dialog.
const bot = new RootBot(conversationState, skillsConfig, skillClient);

// Create HTTP server.
// maxParamLength defaults to 100, which is too short for the conversationId created in skillConversationIdFactory.
// See: https://github.com/microsoft/BotBuilder-Samples/issues/2194.
const server = restify.createServer({ maxParamLength: 1000 });
server.listen(process.env.port || process.env.PORT || 3978, function() {
    console.log(`\n${ server.name } listening to ${ server.url }`);
    console.log('\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator');
    console.log('\nTo talk to your bot, open the emulator select "Open Bot"');
});
github microsoft / botbuilder-js / samples / echobot-connector-es6 / app.js View on Github external
const { ConnectorClient, MicrosoftAppCredentials,  SimpleCredentialProvider, JwtTokenValidation } = require('botframework-connector');
const { Activity, ActivityTypes } = require('botframework-schema');
const restify = require('restify');

// Create server
let server = restify.createServer();
server.use(restify.plugins.bodyParser());
server.listen(process.env.port || process.env.PORT || 3978, function () {
    console.log(`${server.name} listening to ${server.url}`);
});

const botCredentials = {
    appId: '',
    appPassword: ''
};
const authenticator = new SimpleCredentialProvider(botCredentials.appId, botCredentials.appPassword);
const credentials = new MicrosoftAppCredentials(botCredentials.appId, botCredentials.appPassword);;

server.post('/api/messages', (req, res, next) => {
    console.log('processReq:', req.body);

    let activity = req.body;

    // authenticate request
    JwtTokenValidation.assertValidActivity(activity, req.headers.authorization, authenticator).then(() => {

        // On message activity, reply with the same text
        if (activity.type ===  ActivityTypes.Message) {
            var reply = createReply(activity, `You said: ${activity.text}`);
            const client = new ConnectorClient(credentials, activity.serviceUrl);
            client.conversations.replyToActivity(activity.conversation.id, activity.id, reply)
                .then((reply) => {
github microsoft / botbuilder-js / samples / redux-bot-es6 / app.js View on Github external
// Create store
const store = redux.createStore(conversation.store, 
    redux.applyMiddleware(
        // our custom Redux middleware
        lowerCase,
        // and a popular piece of Redux middleware from npm
        createLogger()
));

// Create the authenticator (for inbound activities) and the credentials (for outbound activities)
const botCredentials = {
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
};
const authenticator = new SimpleCredentialProvider(botCredentials.appId, botCredentials.appPassword);
const credentials = new MicrosoftAppCredentials(botCredentials.appId, botCredentials.appPassword);;

// Redux provides a simple pub-sub model that we can use to help organize our application logic in a decoupled way

server.post('/api/messages', (req, res) => {

    console.log('processReq:', req.body);

    let activity = req.body;

    // authenticate request
    JwtTokenValidation.assertValidActivity(activity, req.headers.authorization, authenticator).then(() => {

        // dispatch the inbound activity to redux
        store.dispatch({ type: activity.type, activity: activity });
github compulim / BotFramework-MockBot / src / index.ts View on Github external
const LOG_LENGTH = 20;

// Create server
const server = restify.createServer();

server.listen(process.env.PORT, () => {
  console.log(`${ server.name } listening to ${ server.url }`);
});

server.use(restify.plugins.queryParser());

MicrosoftAppCredentials.trustServiceUrl('https://api.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.scratch.botframework.com');

MicrosoftAppCredentials.trustServiceUrl('https://api.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.ppe.botframework.com');

// Create adapter
const adapter = new BotFrameworkAdapter({
  appId: process.env.MICROSOFT_APP_ID,
  appPassword: process.env.MICROSOFT_APP_PASSWORD,
  oAuthEndpoint: process.env.OAUTH_ENDPOINT,
  openIdMetadata: process.env.OPENID_METADATA
});

// const storage = new MemoryStorage();
// const convoState = new ConversationState(storage);
// const userState = new UserState(storage);

// adapter.use(new BotStateSet(convoState, userState));
github compulim / BotFramework-MockBot / src / index.ts View on Github external
// Create server
const server = restify.createServer();

server.listen(process.env.PORT, () => {
  console.log(`${ server.name } listening to ${ server.url }`);
});

server.use(restify.plugins.queryParser());

MicrosoftAppCredentials.trustServiceUrl('https://api.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.scratch.botframework.com');

MicrosoftAppCredentials.trustServiceUrl('https://api.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.ppe.botframework.com');

// Create adapter
const adapter = new BotFrameworkAdapter({
  appId: process.env.MICROSOFT_APP_ID,
  appPassword: process.env.MICROSOFT_APP_PASSWORD,
  oAuthEndpoint: process.env.OAUTH_ENDPOINT,
  openIdMetadata: process.env.OPENID_METADATA
});

// const storage = new MemoryStorage();
// const convoState = new ConversationState(storage);
// const userState = new UserState(storage);

// adapter.use(new BotStateSet(convoState, userState));

let numActivities = 0;
github compulim / BotFramework-MockBot / src / index.ts View on Github external
import generateDirectLineToken from './generateDirectLineToken';
import renewDirectLineToken from './renewDirectLineToken';

const LOG_LENGTH = 20;

// Create server
const server = restify.createServer();

server.listen(process.env.PORT, () => {
  console.log(`${ server.name } listening to ${ server.url }`);
});

server.use(restify.plugins.queryParser());

MicrosoftAppCredentials.trustServiceUrl('https://api.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.scratch.botframework.com');

MicrosoftAppCredentials.trustServiceUrl('https://api.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.ppe.botframework.com');

// Create adapter
const adapter = new BotFrameworkAdapter({
  appId: process.env.MICROSOFT_APP_ID,
  appPassword: process.env.MICROSOFT_APP_PASSWORD,
  oAuthEndpoint: process.env.OAUTH_ENDPOINT,
  openIdMetadata: process.env.OPENID_METADATA
});

// const storage = new MemoryStorage();
github compulim / BotFramework-MockBot / src / index.ts View on Github external
import generateDirectLineToken from './generateDirectLineToken';
import renewDirectLineToken from './renewDirectLineToken';

const LOG_LENGTH = 20;

// Create server
const server = restify.createServer();

server.listen(process.env.PORT, () => {
  console.log(`${ server.name } listening to ${ server.url }`);
});

server.use(restify.plugins.queryParser());

MicrosoftAppCredentials.trustServiceUrl('https://api.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.scratch.botframework.com');

MicrosoftAppCredentials.trustServiceUrl('https://api.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.ppe.botframework.com');

// Create adapter
const adapter = new BotFrameworkAdapter({
  appId: process.env.MICROSOFT_APP_ID,
  appPassword: process.env.MICROSOFT_APP_PASSWORD,
  oAuthEndpoint: process.env.OAUTH_ENDPOINT,
  openIdMetadata: process.env.OPENID_METADATA
});

// const storage = new MemoryStorage();
// const convoState = new ConversationState(storage);