Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app_home_opened event never fires handler #308

Closed
4 of 9 tasks
kroltan opened this issue Nov 5, 2019 · 15 comments
Closed
4 of 9 tasks

app_home_opened event never fires handler #308

kroltan opened this issue Nov 5, 2019 · 15 comments
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project

Comments

@kroltan
Copy link

kroltan commented Nov 5, 2019

Description

Even after following the proper instructions to enabling App Home, it is impossible to listen to the app_home_opened, and thus not possible to use App Home with Bolt.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

key value
package version 1.4.1
node version 10.13.x
OS version(s) ??? containerized Linux

Steps to reproduce:

  1. Create a empty Bolt app;
  2. Set up App Home;
  3. Add a handler to app_home_opened with a simple console.log("Hi");
  4. Access your bot's home tab.

Optionally, forward your bot through a logger/webhook inspector to see the transactions.

Expected result:

Handler to be fired.

Actual result:

Handler is not fired, despite webhook being called.

Attachments:

I've contacted Slack support and they helped debug this issue, See attached text transcript for everything we tested: slack_support_logs.txt

@seratch
Copy link
Member

seratch commented Nov 5, 2019

I'm afraid you haven't enabled subscription of app_home_opened events yet.

Enabling App Home doesn't automatically add app_home_opened subscription at https://api.slack.com/apps/{app id}/event-subscriptions for you.

Screen Shot 2019-11-05 at 12 48 41

@kroltan
Copy link
Author

kroltan commented Nov 5, 2019

I have, actually. Tested by adding the subscription to the "bot events", "workspace events", and both at once. If I intercept the requests being made I see Slack posting the event to my address, but the bot doesn't receive it.

@jahosh
Copy link

jahosh commented Nov 7, 2019

@kroltan could you post a snippet of your handler logic?

@kroltan
Copy link
Author

kroltan commented Nov 8, 2019

Sure! It's copied straight from the doc example:

app.event("app_home_opened", async ({ context, event, say, ack }) => {
  ack();
  
  // check the message history if there was a prior interaction for this App DM
  const history = await app.client.im.history({
    token: context.botToken,
    channel: event.channel,
    count: 1 // we only need to check if >=1 messages exist
  });

  // if there was no prior interaction (= 0 messages),
  // it's save to send a welcome message
  if (!history.messages.length) {
    say("Hia");
  }
});

But even a simpler one like below is never invoked.

app.event("app_home_opened", async ({ ack }) => {
  ack();
  console.log("Blah");
});

@adamUpchurch
Copy link

Under the "Event Subscriptions" section, make sure your request url ends like such with '/slack/events'

This could be your solution.

image

@kroltan
Copy link
Author

kroltan commented Nov 22, 2019

The event URL is set up properly, as I stated earlier:

If I intercept the requests being made I see Slack posting the event to my address, but the bot doesn't receive it.

@TK95
Copy link
Contributor

TK95 commented Dec 8, 2019

I just tested this event. It fires as expected

  1. Looks like you run your app using Docker container. Just to eliminate any misconfiguration in containers, could you start your app without the container and verify the Slack hits your server? You can use ngrok for this.
  2. Do other events work on your environment?

I highly doubt that it matters, but I run bolt 1.4.0

@jamesfmac
Copy link

When testing locally I noticed that app_home_opened event doesn't receive and ack property?

@kroltan
Copy link
Author

kroltan commented Dec 10, 2019

Hi again! I'll try to test this further as @TK95 asked, but as many, my end of year schedule is pretty busy, might only have actual time to test this after the turn of the year. Sorry for the inconvenience.

When testing locally I noticed that app_home_opened event doesn't receive and ack property?

Nice catch, but if that was the issue wouldn't Bolt still log the event and at least throw the runtime error once the called ack is undefined?

@jamesfmac
Copy link

@kroltan Yep it looks like yours is failing before it gets a chance to respond.

@seratch
Copy link
Member

seratch commented Dec 25, 2019

@kroltan

as many, my end of year schedule is pretty busy

👋 I hope you're having a wonderful time.

I'd like to suggest two things for this question.

  1. Make sure if your endpoint receives requests from Slack

If you use ngrok, you can check the requests on its screen.

Having the following middleware in your Bolt app also may be helpful to check what requests came in.

app.use(args => {
  console.log(JSON.stringify(args.body, null, 2));
  args.next();
});
  1. Remove ack function call

This is already mentioned above but ack function is not available in Events API listeners. For Events API, Bolt automatically acknowledges requests for you.

@seratch seratch added needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project labels Dec 25, 2019
@seratch
Copy link
Member

seratch commented Apr 19, 2020

@kroltan Hello, are you still having this issue? Just doing the following should work for you.

  • In Event Subscription section of Slack app configuration page
    • Add app_home_opened event
    • Properly configure Request URL (I recommend using a new URL and verify if it works with challenge requests)
    • Click Save Changes button
  • In your application side & operations in Slack
    • Add app.event("app_home_opened", async ({ event, logger }) => { logger.info(event) }); in your Bolt app
    • Access Home/Messages tab of your app in Slack
    • Confirm if your Bolt app is receiving requests from Slack (as I mentioned in the previous comment)

Let me know when you have any updates on this. If you already addressed this or are no longer working on this, close this issue.

@kroltan
Copy link
Author

kroltan commented Apr 23, 2020

Hi! Sorry for the very long silence. Yes I am still seeing it.

This is probably an issue with my hosting then, because with both the logging snippets @seratch recommended, I don't see any request coming in from Slack when I open the app home (though I do when I use a slash command). I also tried the app_mention event and it didn't come through either.

With previous interception I could see Slack itself sending the requests, so it's clearly something between Slack and Bolt that is dropping it, not necessarily fault of either.

I'll close this for now and investigate with the hosting, if necessary I can reopen this later.

@kroltan kroltan closed this as completed Apr 23, 2020
@pkozuchowski
Copy link

pkozuchowski commented Jan 23, 2023

I have the same issue now. App home events worked yesterday in my app, but the event doesn't fire today.
I've tried both through Socket Mode and through Http (ngrok) and ngrok doesn't register any incoming traffic and the home page says " This is still a work in progress" - it probably times out after 3 seconds.

It looks like the event is not sent at all.
For sanity, I've also check if node express app receives something, but no. Any request would show up in ngrok in the first place.

If you need info for debugging, I was expecting "app_home_opened" event sent to "https://df1e-185-186-152-216.eu.ngrok.io/slack/events" endpoint at 2023-01-23 19:47 UTC time.

=====EDIT=======
Looks like the root cause was that I was missing "app_home_opened" scope in my Event Subscriptions -> Bot Events ^_^"
I'm leaving this comment here, since someone may fall for the same issue.

@max1ld
Copy link

max1ld commented May 15, 2023

In case it helps anyone else out: I had the same issue and it was driving me mad. I was receiving events as confirmed my ngrok, and bolt was seeing them because I hacked my node_modules to see what was going on. Turns out I accidentally stored the installation.user.id as the slack_bot_id in my database, instead of installation.bot.userId. This caused the ignoreSelf() middleware to silently skip over the event message because it thought it was originating from itself. I fixed it by storing the correct user id when the user installs the app and the installation handler is called in my oauth flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

8 participants