botkit: Can not use botkit with Slack

var PORT = 8765;
var Botkit = require('botkit');
var controller = Botkit.slackbot({});

var bot = controller.spawn({
    token: '...........'
});

bot.startRTM(function(err,bot,payload) {
});

controller.setupWebserver(PORT,function(err,webserver) {
    controller.createWebhookEndpoints(controller.webserver);
});

controller.on('slash_command',function(bot,message) {
    bot.replyPublic(message, '.......');
});

But when I send the command from slack:

Initializing Botkit v0.5.5
info: ** No persistent storage method specified! Data may be lost when process shuts down.
info: ** Setting up custom handlers for processing Slack messages
info: ** API CALL: https://slack.com/api/rtm.connect
info: ** Starting webserver on port 8765
info: ** Serving webhook endpoints for Slash commands and outgoing webhooks at: http://0.0.0.0:8765/slack/receive
error: Could not load team while processing webhook:  Error: could not find team .......
    at /Users/svmelyukov/github/slack-bot-map/node_modules/botkit/lib/SlackBot.js:172:24
    at Object.get (/Users/svmelyukov/github/slack-bot-map/node_modules/botkit/lib/CoreBot.js:890:17)
    at Object.Slackbot.slack_botkit.findTeamById (/Users/svmelyukov/github/slack-bot-map/node_modules/botkit/lib/SlackBot.js:351:36)
    at Object.Slackbot.slack_botkit.findAppropriateTeam (/Users/svmelyukov/github/slack-bot-map/node_modules/botkit/lib/SlackBot.js:150:22)
    at Object.Slackbot.slack_botkit.handleWebhookPayload (/Users/svmelyukov/github/slack-bot-map/node_modules/botkit/lib/SlackBot.js:192:22)
    at /Users/svmelyukov/github/slack-bot-map/node_modules/botkit/lib/SlackBot.js:138:26
    at Layer.handle [as handle_request] (/Users/svmelyukov/github/slack-bot-map/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/svmelyukov/github/slack-bot-map/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/svmelyukov/github/slack-bot-map/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/svmelyukov/github/slack-bot-map/node_modules/express/lib/router/layer.js:95:5)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

I struggled with this for a while. The key for me was to go to http://localhost:3000/login – until you have done that the team id is not saved to the local database and you will get this error message.

@smelukov @peterswimm

The same issue was for me!!, after debugging … I figured out the issue … 😌

1- make sure you add the storage configuration, for example:

var controller = Botkit.slackbot({
   json_file_store: './db_slackbutton_bot/'
});

2- try to save the team manually after hearing the message, sth like this >>

controller.hears('hear_message', 'direct_message,direct_mention,mention', function(bot, message) {
    controller.storage.teams.save({id: message.team, foo:'bar'}, function(err) { console.log(err) });
.......

3- after saving message.team … it should work … and this error error: Could not load team while processing webhook: Error: could not find team ... will be solved

First things first, let’s get you working from an up to date example, check out the Botkit Slack stater kit.

There’s a few things going wrong here for you, I’ll address the second error first. You’re getting an error from the slack web api when calling startRTM indicating you are missing permissions for that API call.

From the Slack Docs you need the permission client to use that API call. Make sure the token you generated has client scope.

You’re getting the first error because you’re mixing two types of slack integrations in this file. You’re mixing the single legacy token based integration with the new Events API based Slack App setup.

Creating a server and webhoook endpoints using those functions will consume events being sent to your server via the handleWebhookPayload function which is meant for Slack Apps. You’ll need to add your clientId and clientSecret, as well as some form or storage. The starter kit has a json filestore setup, take a look at the config options in the controller there.

That error means Botkit does not have a team record saved for the team you’ve just received a message from. The team record is setup during the oauth slack login flow that is only available to Slack Apps. Follow the setup instructions in the starter kit above and you should be good to go 👍

@yamanaltereh thank you for sharing your fix!