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

Question: Is there a troubleshooting guide (for Slack)? #1835

Closed
ianfixes opened this issue Oct 23, 2019 · 8 comments
Closed

Question: Is there a troubleshooting guide (for Slack)? #1835

ianfixes opened this issue Oct 23, 2019 · 8 comments
Labels

Comments

@ianfixes
Copy link

ianfixes commented Oct 23, 2019

Are you sure this is an issue with the Botkit core module?

Yes, TL;DR I believe there is insufficient information on logging and troubleshooting.

please feel free to join the discussion slack : https://community.botkit.ai

I think there's more value in ending up with a google-able guide (vs a personal answer in Slack), so I'm writing this up as a GitHub issue.

What are you trying to achieve or the steps to reproduce?

I'm having trouble getting a new bot working (my first in this framework, although I've written 6 or 7 of them in various Slack frameworks since 2011). I'm trying to get the basic hear/respond behavior from the examples to function, but it isn't.

Here's how I set things up:

  1. Created a new app on Slack
  2. npm install -g yo generator-botkit - Botkit Docs
  3. yo botkit and fill in all the stuff from https://api.slack.com/apps/<MY APP ID>/general?
  4. Set up a public-facing web service
  5. Update bot.js with the appropriate scopes specified for the Slack app
  6. Deploy the bot to the webserver and confirm that it's running and listening
  7. Update https://api.slack.com/apps/<MY APP ID>/event-subscriptions? with server URL + webhook endpoint reported above
  8. Slack verifies the app (https://api.slack.com/events/url_verification).
  9. I verify the same positive response with a bot instance on my local machine with curl -X POST -H 'Content-type: application/json' --data '{"token":"foobar","challenge":"44","type":"url_verification"}' http://localhost:3000/api/messages shows a local response as well.

What was the result you received?

Despite responding to the url_verification message as indicated above, this code in features/sample_hears.js doesn't seem to fire when the bot is running and I type things into Slack:

    // listen for a message containing the word "hello", and send a reply
    controller.hears('hello','message',async(bot, message) => {
        // do something!
        await bot.reply(message, 'Hello human')
    });

I can't get a response from the bot, whether @-mentioning, DMing, or just talking to in a public channel.

What did you expect?

I expected the app to fail or succeed as a whole. Instead, the verification step initiated by Slack works just fine but nothing else seems to work. Slack reports the bot as offline, even though I can run the curl command above (that does the url_verification) and see it work.

What I'm looking for is a troubleshooting guide of some kind, possibly paired with a debug option.

// Trying to use this for logging but it doesn't seem to work
const { MiddlewareSet } = require('botbuilder');
class MyLogger extends MiddlewareSet {
  async onTurn(context, next) {
    console.log(`MyLogger.onTurn: ${JSON.stringify(context)}`);
    await next();
  }
}
adapter.use(new MyLogger());
// This doesn't log anything either
controller.middleware.receive.use(function(bot, message, next) {
  console.log(`Received message: ${JSON.stringify(message, null, 2)}`);
  next();
});

So, how do I verify that Slack is sending me messages in the first place? Is there a way I can log that? How can I send slack-style messages to myself with curl to verify that the app responds in an appropriate way?

And can we put these answers in a document somewhere?

Context:

  • Botkit version:
  • Messaging Platform: Slack
  • Node version: v13.0.0
  • Os: node:13.0-alpine image (previously node:alpine with node v10.12.0, which didn't work either)
  • Any other relevant information: I'm watching Botkit dialog test client #1815 to see if any relevant testing methods will emerge
@dlajarretie
Copy link

I am experiencing the exact same behaviour.

I tracked down the incoming HTTP POST requests by adding logs directly in node modules.
The requests are well received by the app server, however they just seem to be lost somewhere along the way without any error message. The handlers are not triggered and there is not even an HTTP response to these requests from slack.

@ianfixes
Copy link
Author

Which node modules did you edit to get logs of incoming HTTP POST? I'd like to try that

@dlajarretie
Copy link

I just added a console.log in node_modules/botkit/lib/core.js on line 167. Inside this function :

this.webserver.use((req, res, next) => {
          req.rawBody = '';
          req.on('data', function(chunk) {
            req.rawBody += chunk;
          });
          next();
        });

@dlajarretie
Copy link

Actually if you add your own middleware down the chain (after use(bodyParser.json()), you will see the slack message payload in the req body.

@ianfixes
Copy link
Author

if you add your own middleware down the chain

As noted above, I tried adapter.use and controller.middleware.receive.use as part of the bot.js that yeoman generated. What middleware insertion point are you referring to here?

@dlajarretie
Copy link

I was referring to the express middlewares in node_modules/botkit/lib/core.js. If you add something like

this.webserver.use((req, res, next) => {
          console.log(req.body);
          next();
        });

You should see the slack payload, which means the messages do reach this point. But after this, I don't know where they're lost...

@dlajarretie
Copy link

It's fixed for me.

The issue was an invalid clientSigningSecret in the env. This PR should prevent this from failing silently : https://github.com/howdyai/botkit/pull/1833/files

@stale
Copy link

stale bot commented Dec 23, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 23, 2019
@stale stale bot closed this as completed Dec 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants