File size: 5,143 Bytes
b9d9271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
from typing import Optional

from pydantic import BaseModel


class SlackAuthProfile(BaseModel):
    r"""Represents the authorization profile within a Slack event.

    Events will contain a single, compact authorizations field that shows one
    installation of your app that the event is visible to.
    In other words, lists of authorizations will be truncated to one element.

    If there's more than one installing party that your app is keeping track
    of, it's best not to rely on the single party listed in authorizations to
    be any particular one.

    To get a full list of who can see events, call the apps.event.
    authorizations.list method after obtaining an app-level token. Read more on
    the changes here; they have taken effect for existing apps as of
    February 24, 2021.

    References:

    - https://api.slack.com/apis/events-api#authorizations
    - https://api.slack.com/changelog/2020-09-15-events-api-truncate-authed-users#no_context
    """

    enterprise_id: Optional[str] = None
    """The ID of the enterprise associated with the authorization."""

    team_id: str
    """The ID of the team associated with the authorization."""

    user_id: str
    """The ID of the user associated with the authorization."""

    is_bot: bool
    """Whether the authorized user is a bot."""

    is_enterprise_install: bool
    """Whether the authorization is for an enterprise installation."""


class SlackEventProfile(BaseModel):
    r"""Represents the detailed profile of a Slack event, including user,
    message, and context data.
    """

    user: str
    """The ID of the user associated with the event."""

    type: str
    """The type of the event (e.g., 'message')."""

    ts: str
    """A timestamp representing when the event was triggered."""

    thread_ts: Optional[str] = None
    """The timestamp of the parent message in a thread."""

    client_msg_id: str
    """A unique ID generated by the client for the message (if available)."""

    text: str
    """The message content text."""

    team: str
    """The ID of the team that the event is associated with."""

    blocks: list
    """The list of message blocks, providing structured information."""

    channel: str
    """The ID of the Slack channel where the event happened."""

    event_ts: str
    """The event-specific timestamp when it occurred."""

    channel_type: Optional[str]
    """The type of Slack channel (e.g., 'channel', 'im')."""


class SlackEventBody(BaseModel):
    r"""Represents the entire body of a Slack event, including the event
    profile, authorization, and context.
    """

    token: str
    """The token to verify the source of the event."""

    team_id: str
    """The ID of the team where the event is happening."""

    context_team_id: Optional[str]
    """The team ID for the shared channel context, if applicable."""

    context_enterprise_id: Optional[str] = None
    """The enterprise ID for the shared channel context, if applicable."""

    api_app_id: str
    """The unique identifier for the Slack app that received the event."""

    event: SlackEventProfile
    """A detailed profile of the event"""

    type: str
    """The overall type of event received (e.g., 'event_callback')."""

    event_id: str
    """A unique identifier assigned to this event by Slack."""

    event_time: int
    """The timestamp (in seconds) representing when the event was triggered."""

    authorizations: Optional[list[SlackAuthProfile]] = None
    """An optional list of authorizations that describe which installation can 
    see the event."""

    is_ext_shared_channel: bool
    """Indicates if the event is part of a shared channel between different 
    organizations."""

    event_context: str
    """A unique string representing the context of the event."""


class SlackAppMentionEventProfile(SlackEventProfile):
    r"""Represents the detailed profile of a Slack event where the app was
    mentioned in a message.
    """

    channel_type: Optional[str] = None
    """The type of Slack channel. it's None for app mentions."""


class SlackAppMentionEventBody(SlackEventBody):
    r"""Represents the entire body of a Slack event where the app was mentioned
    in a message.
    """

    context_team_id: Optional[str] = None
    """A detailed profile of the event. it's None for app mentions."""

    event: SlackAppMentionEventProfile
    """A detailed profile of the event"""