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.message not firing for public channel #2437

Open
jclark-dot-org opened this issue Mar 3, 2025 · 2 comments
Open

app.message not firing for public channel #2437

jclark-dot-org opened this issue Mar 3, 2025 · 2 comments
Labels
question M-T: User needs support to use the project

Comments

@jclark-dot-org
Copy link

My bot listens for and responds to certain keywords:

app.message(/^(next steps|status|summary)$/, approvals.summarizeChannel);

My first use case involved the bot creating a private channel, inviting users, posting messages in that channel, and then receiving those keywords. Everything works great.

My next use case involves the bot positing to an existing public channel, and listening for those same keywords on the thread. The bot can post to the public channel, but does not receive the message notifications on the thread, or for any message in the public channel. I have confirmed that my bot is a "member" of the channel; it is listed in the integrations tab of the channel info popup, and has posted to the channel.

As an additional debugging step, I added a handler to log all messages:

app.event('message', (event) => {
    console.log("event: ", event);
})

This fires every time a user posts to a private channel created by my bot, or replies in a thread to a post in that channel, but it never fires when a user posts to the public channel where the bot is a member, or to the thread which the bot posted.

I've checked my subscribed event types; here's the relevant part of my manifest:

"bot_events": [
    "app_home_opened",
    "message.channels",
    "message.groups",
    "message.im",
    "message.mpim"
]

And my scopes, also from the manifest:

"scopes": {
    "bot": [
        "channels:history",
        "channels:join",
        "channels:read",
        "channels:write.invites",
        "channels:manage",
        "chat:write",
        "commands",
        "groups:history",
        "groups:read",
        "groups:write",
        "im:history",
        "mpim:history",
        "users.profile:read",
        "users:read",
        "users:read.email"
    ]
}

I believe I should need the message.channels event and the channels.history scope to get messages from a public group where my bot is a member, and I have both. I'm not sure what else to check.

@slack/bolt version

4.2.0

Your App and Receiver Configuration

const expressReceiver = new ExpressReceiver({
    endpoints: '/slack/events',
    signingSecret: process.env.SLACK_SIGNING_SECRET,
    logLevel: LogLevel.DEBUG,
});

const app = new App({
    authorize: oauth.authorizeHandler,
    receiver: expressReceiver,
    logLevel: LogLevel.DEBUG,
});

Node.js runtime version

v20.17.0

Steps to reproduce:

I cannot publish all of my code due to corporate IP, but as my description above outlines, the basic issue is:

  1. Have bot create a private channel and post there.
  2. Have bot join a public channel and post there.
  3. Listen via app.message().
  4. Have a user post to both channels

Expected result:

Bot should see both user messages

Actual result:

Bot only sees message in private channel

@mwbrooks mwbrooks added question M-T: User needs support to use the project and removed untriaged labels Mar 3, 2025
@mwbrooks
Copy link
Member

mwbrooks commented Mar 3, 2025

Hi @jclark-dot-org 👋🏻 Thanks for the detailed issue report! 🙇🏻

I agree with you, the message.channels event and the channels.history scope should allow your bot to receive events in public channels that it's joined. Since you've confirmed that the bot is part of the public channel, I think a clue to the problem is that you're not receiving events for activity in the public channel.

Please excuse the obvious question, but it's good to confirm before we try to dig deeper. Have you re-installed your bot to the Slack Workspace after adding the latest scopes and events? Often, you need to re-install the bot for those changes to take effect and since you're not receiving log data, it makes me think that a re-install may help.

@jclark-dot-org
Copy link
Author

@mwbrooks Thank you for the quick reply!

Obvious questions are good! I did indeed reinstall my app, but your question made me go try again. I'm installing from an "Add to Slack" button on my own site via https://slack.com/oauth/v2/authorize, which means I'm specifying all requested scopes in that URL. I double checked, and sure enough, channels:history was missing from my scopes param. I added it, reinstalled the app, and voila, I'm receiving the missing messages. Thanks for the help 🙏 !

If I can just append a related question... is there any way for my https://slack.com/oauth/v2/authorize/... install URL to specify that scopes should just be taken from my app manifest/config, instead of needing to duplicate the list of scopes in both places (install URL and manifest)? I reviewed the OAuth docs and didn't see such an option

Thanks,
JC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

2 participants