Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Cannot read property 'user_id' when dealing with Slack Apps. #590

@kevinwritescode

Description

@kevinwritescode

When attempting to configure a private Slack App, I'm running into issues with team.bot.user_id being undefined? Is this a configuration issue with Slack Apps? The team object I get back in that area of code looks like this:

{
  "id": "UNIQID1",
  "createdBy": "UNIQID2",
  "url": "https://COMPANY.slack.com/",
  "name": "COMPANY"
}

I've pasted the error logs below.

TypeError: Cannot read property 'user_id' of undefined
    at /Users/knuut/slack-bot/node_modules/botkit/lib/SlackBot.js:177:33
    at Object.get (/Users/knuut/slack-bot/node_modules/botkit/lib/CoreBot.js:822:17)
    at Object.Slackbot.slack_botkit.findTeamById (/Users/knuut/slack-bot/node_modules/botkit/lib/SlackBot.js:300:36)
    at Object.Slackbot.slack_botkit.handleWebhookPayload (/Users/knuut/slack-bot/node_modules/botkit/lib/SlackBot.js:158:22)
    at /Users/knuut/slack-bot/node_modules/botkit/lib/SlackBot.js:137:26
    at Layer.handle [as handle_request] (/Users/knuut/slack-bot/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/knuut/slack-bot/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Users/knuut/slack-bot/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/knuut/slack-bot/node_modules/express/lib/router/layer.js:95:5)
    at /Users/knuut/slack-bot/node_modules/express/lib/router/index.js:277:22

I've also added the basic code used for testing.

const Botkit = require('botkit');

const controller = Botkit.slackbot({
  debug: true,
});

controller.configureSlackApp({
  clientId: process.env.CLIENT_ID,
  clientSecret: process.env.CLIENT_SECRET,
  scopes: ['incoming-webhook','team:read','users:read','channels:read','im:read','im:write','groups:read','emoji:read','chat:write:bot'],
});

controller.setupWebserver(process.env.PORT, (err, webserver) => {
  controller.createWebhookEndpoints(webserver);
  controller.createOauthEndpoints(webserver, (err2, req, res) => {
    if (err2) {
      res.status(500).send(`ERROR: ${err2}`);
    } else {
      res.send('Success!');
    }
  });
});

controller.on('slash_command', (bot, message) => {
  // check message.command
  // and maybe message.text...
  // use EITHER replyPrivate or replyPublic...
  bot.replyPrivate(message, `This is a private reply to the ${message.command} slash command!`);

  // and then continue to use replyPublicDelayed or replyPrivateDelayed
  bot.replyPublicDelayed(message, `This is a public reply to the ${message.command} slash command!`);

  bot.replyPrivateDelayed(message, ':dash:');
});

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions