hellomichibye
hellomichibye

Reputation: 4302

Bot User Events API for Direct Messages

I created a slack app with a Bot User that uses the Events API to listen to messages in channels the bot hangs out.

Oauth scope: bot,chat:write:bot

I subscribed to the following Bot Events:

When I invite my bot to join a channel, I receive a POST request as follows:

{
    [...]
    "event": {
        "user": "U24BYHV19",
        "inviter": "U03BN91GN",
        "text": "<@U24BYHV19|my_bot> has joined the channel",
        "type": "message",
        "subtype": "channel_join",
        "ts": "1472139425.000019",
        "channel": "C24UWQE85",
        "event_ts": "1472139425.000019"
    },
    "type": "event_callback",
    [...]
}

When I send a message in a channel where the bot hangs out, I receive a POST request as follows:

{
    [...]
    "event": {
        "type": "message",
        "user": "U03BN91GN",
        "text": "hello <@U24BYHV19>",
        "ts": "1472139444.000021",
        "channel": "C24UWQE85",
        "event_ts": "1472139444.000021"
    },
    "type": "event_callback",
    [...]
}

When I send a direct message to my bot, I receive a POST request as follows:

{
    [...]
    "event": {
        "type": "message",
        "user": "U03BN91GN",
        "text": "hello pager",
        "ts": "1472139450.000032",
        "channel": "D24DC8UTG",
        "event_ts": "1472139450.000032"
    },
    "type": "event_callback",
    [...]
}

The problem is, how can I determine that someone is talking to my bot via direct message? :) Because I want to respond if someone talks to my bot.

Upvotes: 1

Views: 934

Answers (1)

hellomichibye
hellomichibye

Reputation: 4302

Channels of Direct Messages start with an D instead of an C.

Upvotes: 3

Related Questions