Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controller.spawn() throws UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'context' of undefined #1945

Closed
NxP4Code opened this issue Mar 23, 2020 · 1 comment

Comments

@NxP4Code
Copy link
Contributor

NxP4Code commented Mar 23, 2020

Steps to reproduce
Run the following sample code (https://hazel-jazzy-peach.glitch.me/):


//  __   __  ___        ___
// |__) /  \  |  |__/ |  |  
// |__) \__/  |  |  \ |  |  

// This is the main file for the starter-webex bot.

// Import Botkit's core features
const { Botkit } = require('botkit');
const { BotkitCMSHelper } = require('botkit-plugin-cms');

// Import a platform-specific adapter for webex.

const { WebexAdapter } = require('botbuilder-adapter-webex');

const { MongoDbStorage } = require('botbuilder-storage-mongodb');
const common = require('./common');


// Load process.env values from .env file
require('dotenv').config();

let storage = null;
if (process.env.MONGO_URI) {
    storage = new MongoDbStorage({
        url : process.env.MONGO_URI,
    });
}


const adapter = new WebexAdapter({
    // REMOVE THIS OPTION AFTER YOU HAVE CONFIGURED YOUR APP!
    enable_incomplete: true,
  
    access_token: process.env.access_token,
    public_address: process.env.public_address,
    secret: process.env.secret
})    


const controller = new Botkit({
    webhook_uri: '/api/messages',

    adapter: adapter,

    storage
});

controller.spawn().then(bot => {
    common.bot = bot;
     bot.api.messages.create({
       text: "beep, boop!",
       toPersonEmail: 'ABC.DEF@here.com'

     });
  });

if (process.env.cms_uri) {
    controller.usePlugin(new BotkitCMSHelper({
        cms_uri: process.env.cms_uri,
        token: process.env.cms_token,
    }));
}

controller.usePlugin({
  name: 'webserver logger',
  init: function(botkit) {
    console.log('binding new express middleware');
    botkit.webserver.use(function(req, res, next) {
      console.log('FIRE MIDDLEWARE');
      console.log('> ', req.url, JSON.stringify(req.body, null, 2));
      next();
    });
  }
});

// Once the bot has booted up its internal services, you can use them to do stuff.
controller.ready(() => {

    // load traditional developer-created local custom feature modules
    controller.loadModules(__dirname + '/features');

    /* catch-all that uses the CMS to trigger dialogs */
    if (controller.plugins.cms) {
        controller.on('message,direct_message', async (bot, message) => {
            let results = false;
            results = await controller.plugins.cms.testTrigger(bot, message);

            if (results !== false) {
                // do not continue middleware!
                return false;
            }
        });
    }

});

controller.webserver.get('/', (req, res) => {
    res.send(`This app is running Botkit ${ controller.version }.`);
});

Expected behavior:
No error generated, and an instance of the bot can be used to call bot.api.messages.create function.

Even with this error bot responds to added features.

Describe your issue here, include as much detail as necessary to reproduce the issue or implement a missing functionality.

@benbrown
Copy link
Contributor

Fixed in 4.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants