Skip to content

Catching Direct Messages #199

Description

@cgamio

I'm trying to catch DM's and treat them differently from other messages. I've tried leveraging the message.im event type as described here, but that doesn't seem to be caught by using the event listener decorator

Reproducible in:

Python 3.7.4
slack-bolt==1.1.5
slack-sdk==3.1.1
ProductName:	Mac OS X
ProductVersion:	10.14.5
BuildVersion:	18F2058
Darwin Kernel Version 18.6.0: Sun Apr 28 18:06:45 PDT 2019; root:xnu-4903.261.4~6/RELEASE_X86_64

Steps to reproduce:

  1. Setup a sample app with the appropriate event subscriptions and scopes
  2. Create a function that listens for the message.im type
@app.event("message.im")
def handle_mention(event, say):
   # Do something
  1. DM the bot

Expected result:

The function should execute

Actual result:

The function is passed over, presumably because the event type doesn't fit.

[2021-01-11 14:19:18,882] DEBUG    app             l:351  msg: Checking listener: handle_dm ...

and then nothing happens

Activity

  1. seratch commented on Jan 11, 2021

    @seratch
    Contributor

    @cgamio Hello, thanks for asking the question. I do understand this is a bit confusing but the event type to catch this pattern is not message.im but message (message.im is {event.type}.{event.channel_type}).

    https://api.slack.com/events/message.im

    {
        "token": "one-long-verification-token",
        "team_id": "T061EG9R6",
        "api_app_id": "A0PNCHHK2",
        "event": {
            "type": "message",
            "channel": "D024BE91L",
            "user": "U2147483697",
            "text": "Hello hello can you hear me?",
            "ts": "1355517523.000005",
            "event_ts": "1355517523.000005",
            "channel_type": "im"
        },
        "type": "event_callback",
        "authed_teams": [
            "T061EG9R6"
        ],
        "event_id": "Ev0PV52K21",
        "event_time": 1355517523
    }

    Thus, updating your code as below should help.

    @app.event("message")

    I will improve this framework to raise an exception that tells what's wrong with the "message.*".

  2. added this to the 1.2.0 milestone on Jan 11, 2021
  3. cgamio commented on Jan 11, 2021

    @cgamio
    Author

    Thanks for the heads up! So I'll expand that listener to include all of message and then create a middleware or otherwise filter by messages that have the channel_type set to im

  4. seratch commented on Jan 11, 2021

    @seratch
    Contributor

    @cgamio Yes, you're on the right track 👍 Let me close this issue now.

  5. modified the milestones: 1.2.0, 1.2.1 on Jan 12, 2021
  6. added a commit that references this issue on Jan 19, 2021
  7. added a commit that references this issue on Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions