question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When bot is in group chat, the callback for `.message` is not being called

See original GitHub issue

Description

I’m registering a callback with the following code:

app.message(/ping/, (e) => { console.log(e) })

It is not printing anything if I’m on group chat. I see the message on the debug console, but it fails with error: Conversation not found.

[DEBUG]  bolt-app {"token":"k7PRs87qbRwzm4A4LAtOCSGb","team_id":"T0JV0MYCE","api_app_id":"A01Q2UP4HQQ","event":{"client_msg_id":"0b3149e4-1243-4a27-be4c-2aecb715cab9","type":"app_mention","text":"<@U01PDC4EB8B> ping","user":"UR62DEJCX","ts":"1614363797.012900","team":"T0JV0MYCE","blocks":[{"type":"rich_text","block_id":"fxp","elements":[{"type":"rich_text_section","elements":[{"type":"user","user_id":"U01PDC4EB8B"},{"type":"text","text":" ping"}]}]}],"channel":"G01PJFVB4GK","event_ts":"1614363797.012900"},"type":"event_callback","event_id":"Ev01PQKP3RNY","event_time":1614363797,"authorizations":[{"enterprise_id":null,"team_id":"T0JV0MYCE","user_id":"U01PDC4EB8B","is_bot":true,"is_enterprise_install":false}],"is_ext_shared_channel":false,"event_context":"1-app_mention-T0JV0MYCE-G01PJFVB4GK"}
[DEBUG]  socket-mode:SocketModeClient:0 calling ack events_api
[DEBUG]  socket-mode:SocketModeClient:0 send() in state: connected,ready
[DEBUG]  socket-mode:SocketModeClient:0 sending message on websocket: {"envelope_id":"889495a0-c7ce-4ad4-a7cd-5329ba5c7295","payload":{}}
[DEBUG]  bolt-app Conversation context failed loading for ID: G01PJFVB4GK, error: Conversation not found

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

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code 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

Reproducible in:

package version: 3.2.0 node version: v12.13.0 OS version(s): Ubuntu 18.04

Steps to reproduce:

  1. Listen to anything using the .message call
  2. Add the bot in a group chat with at least two people
  3. Mention the bot with the message that it should listen

Expected result:

The callback to be called

Actual result:

The callback is not called, and the DEBUG info prints Conversation not found

What I also tried

Checked that the bot CAN post to the group conversation Checked with app.receiver.client.on('slack_event'...) that the message is visible

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
seratchcommented, Mar 1, 2021

@manucaicedo Is A01Q2UP4HQQ your app’s ID (I found this ID in your issue decscription)? If so, please visit https://api.slack.com/apps/A01Q2UP4HQQ/event-subscriptions and make sure if message.mpim is in the bot events.

1reaction
seratchcommented, Feb 27, 2021

Thanks for your prompt reply. Just in case, I’ve verified if there is no issue with Bolt’s handling with the following code.

const { App } = require('@slack/bolt');

const app = new App({
  socketMode: true,
  developerMode: true,
  token: process.env.SLACK_BOT_TOKEN,
  appToken: process.env.SLACK_APP_TOKEN,
});

app.message("ping", async ({ message }) => {
  console.log(message);
});

(async () => {
  await app.start();
})();

The result was that my app.message printed the message object for both public and private channels.

What I did are:

  • Create a new Slack app at https://api.slack.com/apps
  • Settings > Socket Mode - Turn Socket Mode on
  • Features > Event Subscriptions - Add the following bot events
    • message.channels
    • message.groups
  • Settings > Install App - Install the app to grab a bot token (xoxb- token)
  • (in your Bolt app project) Set SLACK_APP_TOKEN and SLACK_BOT_TOKEN in env variables
  • (in your Bolt app project) Run the app (say, npx node app.js)
  • (in the installed Slack workspace)
    • Create a private channel
    • Add the app to the channel
    • Say “ping” in the channel

The only difference in Bolt I can imagine here is that the framework intentionally ignores most events generated by the apps’ bot user itself. This is helpful to avoid unintentional infinite loop situation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Telegram bot callback with a custom message not ...
So I guess the problem is that your callback function hello expects three positional arguments but the telegram API under the hood calls...
Read more >
node-red-contrib-telegrambot
If the configuration node property ChatIds is not set, all chat messages are received. You can control if the bot receives every message...
Read more >
pyTelegramBotAPI 3.6.0 - PyPI
Python Telegram bot api. ... `How can I distinguish a User and a GroupChat in ... After that declaration, we need to register...
Read more >
ACTF2022 safer-tg-bot-{1,2} WP - JieJiSS' Blog
Data associated with the callback button. Be aware that the message originated the query can contain no callback buttons with this data.
Read more >
Telegram inline keyboard does not send callback for ...
is important part here. If i remember correctly you need to initialize connection to bot first to be able to receive messages.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found