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

Missing fields in AppMentionEvent #961

Open
phoebelilius opened this issue Aug 7, 2021 · 4 comments
Open

Missing fields in AppMentionEvent #961

phoebelilius opened this issue Aug 7, 2021 · 4 comments

Comments

@phoebelilius
Copy link

AppMentionEvent may have attachments, if referenced by another bot.
Example payload:

{
    "api_app_id": "xxxx",
    "authorizations": [
        {
            "enterprise_id": "xxx",
            "is_bot": true,
            "is_enterprise_install": false,
            "team_id": "xxx",
            "user_id": "xxx"
        }
    ],
    "enterprise_id": "xxx",
    "event": {
        "attachments": [
            {
                "blocks": [
                    {
                        "block_id": "HNku",
                        "text": {
                            "text": "My test event CC <@MYBOTID>",
                            "type": "mrkdwn",
                            "verbatim": false
                        },
                        "type": "section"
                    }
                ],
                "color": "#29AF7B",
                "fallback": "[no preview available]",
                "id": 1
            }
        ],
        "bot_id": "xxx",
        "bot_profile": {
            "app_id": "xxx",
            "deleted": false,
            "icons": {
                "image_36": "https://slack-files2.s3-us-west-2.amazonaws.com/avatars/xxx"
            },
            "id": "xxx",
            "name": "xxx",
            "team_id": "xxx",
            "updated": 1562687282
        },
        "channel": "xxx",
        "edited": {
            "ts": "1628260114.000000",
            "user": "xxx"
        },
        "event_ts": "1628259917.003000",
        "team": "xxx",
        "text": "",
        "ts": "1628259917.003000",
        "type": "app_mention",
        "user": "xxx"
    },
    "event_context": "xxx",
    "event_id": "xxx",
    "event_time": 1628259917,
    "is_ext_shared_channel": false,
    "team_id": "xxx",
    "token": "xxx",
    "type": "event_callback"
}

type AppMentionEvent struct {
Type string `json:"type"`
User string `json:"user"`
Text string `json:"text"`
TimeStamp string `json:"ts"`
ThreadTimeStamp string `json:"thread_ts"`
Channel string `json:"channel"`
EventTimeStamp json.Number `json:"event_ts"`
// When Message comes from a channel that is shared between workspaces
UserTeam string `json:"user_team,omitempty"`
SourceTeam string `json:"source_team,omitempty"`
// BotID is filled out when a bot triggers the app_mention event
BotID string `json:"bot_id,omitempty"`
}

Currently using ParseEvent can only parse inner events (AppMentionEvent) in the format:

{
    "api_app_id": "xxx",
    "authorizations": [
        {
            "enterprise_id": "xxx",
            "is_bot": true,
            "is_enterprise_install": false,
            "team_id": "xxx",
            "user_id": "xxx"
        }
    ],
    "enterprise_id": "xxx",
    "event": {
        "bot_id": "xxx",
        "channel": "xxx",
        "event_ts": "1628260061.003900",
        "subtype": "bot_message",
        "text": "CC <@BOTID> test",
        "ts": "1628260061.003900",
        "type": "app_mention",
        "username": "xxx"
    },
    "event_context": "xxx",
    "event_id": "xxx",
    "event_time": 1628260061,
    "is_ext_shared_channel": false,
    "team_id": "xxx",
    "token": "xxx",
    "type": "event_callback"
}
@phoebelilius
Copy link
Author

I guess it would be a matter of adding Attachments []slack.Attachment `json:"attachments,omitempty".

@phoebelilius
Copy link
Author

Actually I guess an app_mention event can have all the fields as in MessageEvent.

type MessageEvent struct {
// Basic Message Event - https://api.slack.com/events/message
ClientMsgID string `json:"client_msg_id"`
Type string `json:"type"`
User string `json:"user"`
Text string `json:"text"`
ThreadTimeStamp string `json:"thread_ts"`
TimeStamp string `json:"ts"`
Channel string `json:"channel"`
ChannelType string `json:"channel_type"`
EventTimeStamp json.Number `json:"event_ts"`
// When Message comes from a channel that is shared between workspaces
UserTeam string `json:"user_team,omitempty"`
SourceTeam string `json:"source_team,omitempty"`
// Edited Message
Message *MessageEvent `json:"message,omitempty"`
PreviousMessage *MessageEvent `json:"previous_message,omitempty"`
Edited *Edited `json:"edited,omitempty"`
// Message Subtypes
SubType string `json:"subtype,omitempty"`
// bot_message (https://api.slack.com/events/message/bot_message)
BotID string `json:"bot_id,omitempty"`
Username string `json:"username,omitempty"`
Icons *Icon `json:"icons,omitempty"`
Upload bool `json:"upload"`
Files []File `json:"files"`
Attachments []slack.Attachment `json:"attachments,omitempty"`
// Root is the message that was broadcast to the channel when the SubType is
// thread_broadcast. If this is not a thread_broadcast message event, this
// value is nil.
Root *MessageEvent `json:"root"`
}

@phoebelilius phoebelilius changed the title AppMentionEvent may have attachments Missing fields in AppMentionEvent Aug 7, 2021
@chrisgoffinet
Copy link

Would it just make sense to make AppMentionEvent be this for consistency? It looks like the slack docs at https://api.slack.com/events/app_mention suggest:

The app_mention event is not a message like the message.* event types. However, your app can treat its contents similarly.

type AppMentionEvent struct {
  MessageEvent
}

I ran into this bug myself where I didn't reference another bot but blocks were missing that comes along in the payload by default.

@phoebelilius
Copy link
Author

@chrisgoffinet I agree with you on that. The only issue would be that that would be a breaking change in the code unfortunately if the following would be implemented:

type AppMentionEvent struct {
  MessageEvent
}

I hope the maintainers of this repo would look into this!

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

No branches or pull requests

3 participants