botkit: Cannot read property 'user_id' when dealing with Slack Apps.
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:');
});
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (2 by maintainers)
Commits related to this issue
- Hotfix for issue #590 — committed to izotos/botkit by deleted user 6 years ago
- Merge pull request #1281 from izotos/issue-590-hotfix Hotfix for issue #590 — committed to jnv/botkit by jnv 6 years ago
- Fixed #590 — committed to jmeyers91/botkit by deleted user 6 years ago
- Work around botkit slash command bug https://github.com/howdyai/botkit/issues/590 https://github.com/1natsu172/Botkit-slack-slash-command-example/blob/master/index.js — committed to interstateone/slash-github-search by interstateone 5 years ago
- Hotfix for #590 — committed to CF-Carl/botkit by CF-Carl 5 years ago
i’ve the same issue with the latest version (0.6.7)
Also seeing this issue; verified #1281 is fixing this for me as well. Do we have an ETA on getting that PR reviewed/merged?
I’ve been having the same issue when trying to initiate a dialog, I issued a PR https://github.com/howdyai/botkit/pull/1281 with changes according to https://github.com/howdyai/botkit/issues/590#issuecomment-351545096
This is quite important for us, we could not find a npm version that implements dialogs on Slack that does not have this issue.
@justinemar that’s a very old botkit, you should upgrade to the latest version and tell us if you are still seeing the trouble
Is there any fixed for this? Currently encountering this on version
0.4.3currently using @mrbar42 quick fix.Work around - We are using another workaround from here https://github.com/howdyai/botkit/issues/108 which led me to do this (solves both problems):
This still hasn’t been merged? I can’t seem to get Slash commands working because of this.
Hey @peterswimm - over here we ran into the same issue. I think this may be due to some of the changes that Slack has made recently.
Since by default, if you enable slash command on your slack app (without a bot user) - you do not ask for the ‘bot’ permission. And now with the latest Slack change, you cannot add bot permission without a bot user.
It should still be possible to use slash commands without asking for the bot oauth permission (and subsequently adding a bot user) - as slash commands are independent from bot users.
The call to set the user_id of the bot object (which doesn’t exist, because we don’t have bot oauth permission, see line 5) is here : https://github.com/howdyai/botkit/blob/master/lib/SlackBot.js#L209 I’m also not sure it’s really necessary to spawn a bot for a slash command.
Just wanted you to be aware of this. We are looking at the feasibility of submitting a PR for you guys; I think it may be relatively easy to fix.
Had the same issue. After allowing a bot, I’m getting the error:
Using
botkit 0.4.10. Traced the code: my bot object is undefined.Should I be spawning a bot? If so, how would I get the bot token if it’s an app’s bot?
EDIT: Downgraded to 0.4.2, no longer getting the error.
It looks like it may be a configuration issue after all. I was able to get it to work once I also allowed “bot” during the oauth “Slack Button” creation, but I wasn’t using a bot for anything in my scripts, just slash commands.
I’m not sure if there is any advise on how to set it up if you don’t need a bot? Maybe I’m configuring the code improperly to handle a no bot situation.