soapergem
soapergem

Reputation: 9979

Is it possible to listen for message_deleted in a Slack Bolt app?

I've been writing a Slack application using Bolt for Python which can open modals and post messages in channels. What I would like is for a way to detect when the messages posted by my app get deleted (ideally with a simple Python decorator), though I am not sure this is possible. The Slack API does seem to have a message_deleted event, though I can't seem to get it to work. I've tried including this handler in my application:

@app.event("message_deleted")
async def message_deleted(ack, body, logger):
    logger.info(body)
    await ack()

However, nothing happens when I delete the message that was generated by my app. The event handler doesn't trigger, as if Slack doesn't actually send any event data to notify of the message being deleted in the first place.

I also went to my app's settings page and noticed there is a tab to enable Event Subscriptions. I turned that on and pointed it at my handler endpoint. But I still don't appear to receive any of the message_deleted events. And that doesn't seem to be an option available under either Bot Events or Workspace Events.

Upvotes: 1

Views: 334

Answers (1)

Kazuhiro Sera
Kazuhiro Sera

Reputation: 1877

The message_deleted is one of the subtypes for message events. Your app can subscribe message (channels/groups/mpim/im) events plus its listener function can check if there is the "message_deleted" subtype in a payload.

Upvotes: 3

Related Questions