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

Catching Direct Messages #199

Closed
cgamio opened this issue Jan 11, 2021 · 3 comments
Closed

Catching Direct Messages #199

cgamio opened this issue Jan 11, 2021 · 3 comments
Labels
enhancement New feature or request question Further information is requested
Milestone

Comments

@cgamio
Copy link

cgamio commented Jan 11, 2021

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

@misscoded misscoded added the question Further information is requested label Jan 11, 2021
@seratch
Copy link
Member

seratch commented Jan 11, 2021

@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.*".

@seratch seratch added the enhancement New feature or request label Jan 11, 2021
@seratch seratch added this to the 1.2.0 milestone Jan 11, 2021
@cgamio
Copy link
Author

cgamio commented Jan 11, 2021

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

@seratch
Copy link
Member

seratch commented Jan 11, 2021

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

@seratch seratch closed this as completed Jan 11, 2021
@seratch seratch modified the milestones: 1.2.0, 1.2.1 Jan 12, 2021
seratch added a commit to seratch/bolt-python that referenced this issue Jan 15, 2021
nickovs pushed a commit to nickovs/bolt-python that referenced this issue Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants