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)
Another example:
var CLIENT_ID = '....';
var CLIENT_SECRET = '....';
var PORT = 8765;
var Botkit = require('botkit');
var controller = Botkit.slackbot({
clientId: CLIENT_ID,
clientSecret: CLIENT_SECRET,
redirectUri: '....',
scopes: ['commands']
});
var bot = controller.spawn({
token: '....'
});
bot.startRTM(function(err, bot, payload) {
if (err) {
console.error('Error:', err);
}
});
controller.setupWebserver(PORT,function(err,webserver) {
controller.createWebhookEndpoints(controller.webserver);
});
controller.on('slash_command',function(bot,message) {
bot.replyPublic(message, 'Everyone can see the results of this slash command');
});
After start:
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: missing_scope
And there is no react to commands from slack.
Whats wrong?
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 👍
Can you confirm you pulled the changes from the master branch?
Did you also go through the login flow, to create a new team in the
database?
On Wed, Jul 26, 2017 at 1:22 PM Steven Wade notifications@github.com
wrote:
I am getting the same error in regards to not being able to find team.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/howdyai/botkit/issues/938#issuecomment-318123305, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AMUR2xeVvkxRMgsAp_JIaSFyO2WZeEkRks5sR3XHgaJpZM4OiUAd
.
@smelukov I was having this same problem, and looking through the starter kit @jonchurch provided helped immensely. My final config looks like:
var slackController = botkit.slackbot({
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
scopes: ['bot'],
redirectUri: 'http://localhost:3000/oauth',
json_file_store: __dirname + '/.data/db/'
});
slackController.startTicking();
slackController.createOauthEndpoints(app);
slackController.createWebhookEndpoints(app);
Important parameters to note are the json_file_store and redirectUri. To start using your app, you need to navigate to http://localhost:3000/login and authorize the app to work with your slack group. Hope I could help.
@seaside98 You are passing app into those functions but you don't show it's definition.
@stevenmwade Ah yes, my bad. app is an express web server. If you use botkit's builtin web server, it would look something like:
```javascript
slackController.setupWebserver(3000, function(err, express) {
slackController.createOauthEndpoints(express);
slackController.createWebhookEndpoints(express);
});
This happens to me when I use localtunnel, but not when I use glitch.
@stevenmwade the glitch project is setup to use a json file store, which is also ignored by the .gitignore there. So any cloning your project locally wont have your db included. Thats a potential gotcha there.
Can you confirm what storage youre passing into your controller? Its likely whatever storage system youre giving botkit to save team data is not persisting it, either because of local permissions or possibly a bad path to the json file system.
@jonchurch I gave it just the JSON file store since the postgres one doesn't seem to work any longer. It doesn't seem to be using the JSON file store. I'm not sure if Docker makes this no longer possible?
Actually got the postgres store to work, but nothing is getting persisted in either type.
@stevenmwade did you ever figure out your issue?
@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
@yamanaltereh thank you for sharing your fix!
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.
solution from @dselman works, with some extras steps, like setting the public url in "bot.js", i.e
" redirectUri: 'https://xyz.glitch.me/oauth',
Most helpful comment
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.