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

How to distinguish DMs from messages to rooms? #45

Open
llimllib opened this issue Jun 3, 2015 · 5 comments
Open

How to distinguish DMs from messages to rooms? #45

llimllib opened this issue Jun 3, 2015 · 5 comments
Labels

Comments

@llimllib
Copy link
Owner

llimllib commented Jun 3, 2015

Sparked by: this commit

@StewPoll
Copy link
Contributor

The first part of the channel ID will start with "D"

{'ts': '1454135373.000338', 'text': 'This is a channel', 'user': 'U02GSB32U', 'channel': 'C02HDGZT9', 'team': '<REDACTED>', 'type': 'message'}
{'ts': '1454135387.000045', 'text': 'This is a group', 'user': 'U02GSB32U', 'channel': 'G04UL2QM5', 'team': '<REDACTED>', 'type': 'message'}
{'ts': '1454135392.000010', 'text': 'This is a DM', 'user': 'U02GSB32U', 'channel': 'D04UGH7SL', 'team': '<REDACTED>', 'type': 'message'}

@llimllib
Copy link
Owner Author

llimllib commented Feb 5, 2016

neat! next up is that this should be wired into slackrtm, probably the message should come with an is_direct_message field or something?

@StewPoll
Copy link
Contributor

StewPoll commented Feb 6, 2016

Having a second look at the code in the commit that you've linked, they're not looking for DMs, they're looking for mentions of the bot within regular channel/group messages.

init_msg == '<@xxxxxxx>:'

You can get this ID using the auth.test call from slack.

Maybe have a .self_id attribute to server?

That way we can have the following functions as part of the server object, that people can check with within plugins:

def is_direct(server, msg):
    if msg['channel'][0] == "D":
        return True

def is_mention(server, msg):
    if msg["text"].split(" ")[0] = "<{0}>:".format(server.self_id):
        return True

@llimllib
Copy link
Owner Author

llimllib commented Feb 8, 2016

The bot's ID is actually available, via the opaque server.slack.server.login_data["self"]["name"]; limbo used to make sure it wasn't responding to itself but I seem to have cut that out when I added the bot_message handler.

@llimllib
Copy link
Owner Author

llimllib commented Feb 8, 2016

the slackrtm library should probably gain two issues:

  • create a self_id attribute
  • add a direct message flag

will do when I have time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants