node.jsgoogle-app-engineslack-apibotkit

Botkit Slackbot responds with 401 error every time


I'm trying to create a very simple Slack bot using botkit and Google App Engine, but for some reason I keep getting 401 errors any time I message the bot. The weird thing is that the Slack Event Subscription URL (the one ending in /api/messages) validates correctly, and I get a 200 response in GAE logs and validation within Slack.

But whenever I actually message the bot it always gets a 401 error with no message explaining the error at all. I've tried various combinations of the code below, and have now stripped it down to the bare minimum as found here. Aside from dependencies and a code to decrypt credentials (which I've verified is working as expected), this is my full code at the moment:

botInit();

async function botInit () {

    const credentialsRaw = await getCredentials();
    const credentials = JSON.parse(credentialsRaw);
    const adapter = new SlackAdapter(credentials);
    
    const controller = new Botkit({
        adapter: adapter
    });
    
    controller.on('message', async(bot, message) => {
        await bot.reply(message, 'I heard a message!');
    });
}

I have also tried this for the messaging function:

controller.ready(() => {
    controller.hears(['hello', 'hi'], ['message', 'direct_message'],
    async (bot, message) => {
        await bot.reply(message, 'Meow. :smile_cat:')
    })
})

and this for setting up the controller:

const controller = new Botkit({
        webhook_uri: '/api/messages',
        adapter: adapter
    });

And everything gives back the same exact 401 error, despite all of them working with the Event Subscription URL verification on Slack.


Solution

  • I had same issue but figured out the problem.

    I had been using Client Secret as clientSigningSecret

    But I should use Signing Secret !

    enter image description here