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

Cannot read property 'id' of undefined #118

Open
geraldoramos opened this issue Jan 18, 2019 · 0 comments
Open

Cannot read property 'id' of undefined #118

geraldoramos opened this issue Jan 18, 2019 · 0 comments

Comments

@geraldoramos
Copy link

geraldoramos commented Jan 18, 2019

I'm getting these errors when trying to use postMessageToUser. Some users works fine, some crashes with this error.

error: {
message: Cannot read property 'id' of undefined, 
name: TypeError, 
stack: 
TypeError: Cannot read property 'id' of undefined
    at Bot.<anonymous> (/opt/slack-integration-api-internal/node_modules/slackbots/index.js:246:56)
    at Array.<anonymous> (/opt/slack-integration-api-internal/node_modules/vow/lib/vow.js:773:56)
    at Immediate.callFns (/opt/slack-integration-api-internal/node_modules/vow/lib/vow.js:24:35)
    at processImmediate (timers.js:632:19)
    at process.topLevelDomainCallback (domain.js:120:23)
}

This is where the error is happening: (slackbots index.js):

getChatId(name) {
        return this.getUser(name).then(function(data) {

            var chatId = _.find(this.ims, { user: data.id }); // here is the problem

            return (chatId && chatId.id) || this.openIm(data.id);
        }.bind(this)).then(function(data) {
            return typeof data === 'string' ? data : data.channel.id;
        });
    }

This is my postMessageToUser wrapper:

const SlackBot = require('slackbots')

module.exports = {
  postMessageToUser: async(name, info, message, token) => {
    return new Promise((resolve) => {
      const bot = new SlackBot({
        token,
        disconnect: true,
      })
      bot.postMessageToUser(name, info, message, data => {
        resolve(data)
      })
    });
  },

}

Any thoughts? I'm sure the user being received by the postMessageToUser function is a valid user in the given workspace.

Thanks in advance,

Geraldo

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

No branches or pull requests

1 participant