rubin-squarebot 0.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,92 @@
1
+ Metadata-Version: 2.1
2
+ Name: rubin-squarebot
3
+ Version: 0.7.0
4
+ Summary: Client library for the Rubin Observatory Squarebot
5
+ License: The MIT License (MIT)
6
+
7
+ Copyright (c) 2018-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+
27
+ Project-URL: Homepage, https://github.com/lsst-sqre/squarebot
28
+ Project-URL: Source, https://github.com/lsst-sqre/squarebot
29
+ Keywords: rubin,lsst
30
+ Classifier: Development Status :: 4 - Beta
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.11
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Natural Language :: English
37
+ Classifier: Operating System :: POSIX
38
+ Classifier: Typing :: Typed
39
+ Requires-Python: >=3.11
40
+ Description-Content-Type: text/markdown
41
+ License-File: LICENSE
42
+ Requires-Dist: pydantic
43
+ Requires-Dist: safir
44
+ Provides-Extra: dev
45
+ Requires-Dist: mypy ; extra == 'dev'
46
+
47
+ # Squarebot
48
+
49
+ Squarebot is the nexus service for ChatOps and event-driven bots for Rubin Observatory.
50
+ As a Slack app, Squarebot receives events from Slack and publishes them into specific _Square Events_ Kafka topics in the [Roundtable Kubernetes cluster](https://phalanx.lsst.io/environments/roundtable-prod/index.html).
51
+ Other applications on Roundtable can consume these events and act on them, such as by posting messages back to Slack or by performing some other background automation.
52
+
53
+ ```mermaid
54
+ flowchart LR
55
+ subgraph Slack
56
+ message[Slack message]
57
+ interaction[Slack interaction]
58
+ end
59
+ subgraph sqrbot ["Squarebot"]
60
+ eventapi["/slack/event"]
61
+ interactionapi["/slack/interaction"]
62
+ message -->|HTTP POST| eventapi
63
+ interaction -->|HTTP POST| interactionapi
64
+ end
65
+ subgraph kafka ["Kafka Topics"]
66
+ topicmention["lsst.square-events.squarebot.slack.app.mention"]
67
+ topicchannel["lsst.square-events.squarebot.slack.message.channel"]
68
+ topicgroup["lsst.square-events.squarebot.slack.message.group"]
69
+ topicim["lsst.square-events.squarebot.slack.message.im"]
70
+ topicmpim["lsst.square-events.squarebot.slack.message.mpim"]
71
+ topicinteraction["lsst.square-events.squarebot.slack.interaction"]
72
+ end
73
+ eventapi --> topicmention
74
+ eventapi --> topicchannel
75
+ eventapi --> topicgroup
76
+ eventapi --> topicim
77
+ eventapi --> topicmpim
78
+ interactionapi --> topicinteraction
79
+ subgraph backends ["Backends"]
80
+ backend1["Backend 1"]
81
+ backend2["Backend 2"]
82
+ end
83
+ topicchannel --> backend1
84
+ topicgroup --> backend1
85
+ topicmention --> backend2
86
+ topicinteraction --> backend2
87
+ ```
88
+
89
+ Slack integration is implemented at the time.
90
+ We plan to add support for other event sources, such as GitHub, in the future.
91
+
92
+ Squarebot is built on top of [FastAPI](https://fastapi.tiangolo.com/), a modern Python web framework, with Rubin/SQuaRE libraries [Safir](https://safir.lsst.io) (FastAPI application libraries) and [Kafkit](https://kafkit.lsst.io) (Kafka integration).
@@ -0,0 +1,10 @@
1
+ rubinobs/square/squarebot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ rubinobs/square/squarebot/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ rubinobs/square/squarebot/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ rubinobs/square/squarebot/models/kafka.py,sha256=We-fEoXCZYX4tC_5XuHQmU08ZX2vS76fm9OkNbKze48,4865
5
+ rubinobs/square/squarebot/models/slack.py,sha256=2jrFebzxoNnd83aImXkAktxoUAuSMiCq66ASQ10RURk,5718
6
+ rubin_squarebot-0.7.0.dist-info/LICENSE,sha256=HRokC_gX5O7I06OH-XfnNZ1uKGqVwP2Y7joWPOW6rUg,1138
7
+ rubin_squarebot-0.7.0.dist-info/METADATA,sha256=wdr2x9ijzO1f0bm8ISFGV2JsmqLpSPpbvBSbIJ2TNYw,4175
8
+ rubin_squarebot-0.7.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
9
+ rubin_squarebot-0.7.0.dist-info/top_level.txt,sha256=SFhUfkkTjXmZSix1tAkI1VdwPzbT6YDJHsswa7lfgJU,9
10
+ rubin_squarebot-0.7.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.40.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ rubinobs
File without changes
File without changes
@@ -0,0 +1,179 @@
1
+ """Models for Kafka messages produced by Squarebot."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any, Self
7
+
8
+ from dataclasses_avroschema.avrodantic import AvroBaseModel
9
+ from pydantic import Field
10
+
11
+ from .slack import SlackChannelType, SlackMessageEvent, SlackMessageType
12
+
13
+ __all__ = [
14
+ "SquarebotSlackMessageKey",
15
+ "SquarebotSlackMessageValue",
16
+ "SquarebotSlackAppMentionValue",
17
+ ]
18
+
19
+
20
+ class SquarebotSlackMessageKey(AvroBaseModel):
21
+ """Kafka message key model for Slack messages sent by Squarebot."""
22
+
23
+ channel: str = Field(..., description="The Slack channel ID.")
24
+
25
+ class Meta:
26
+ """Metadata for the model."""
27
+
28
+ namespace = "lsst.square-events.squarebot.messages"
29
+ schema_name = "key"
30
+
31
+ @classmethod
32
+ def from_event(cls, event: SlackMessageEvent) -> Self:
33
+ """Create a Kafka key for a Slack message from a Slack event.
34
+
35
+ Parameters
36
+ ----------
37
+ event
38
+ The Slack event.
39
+
40
+ Returns
41
+ -------
42
+ key
43
+ The Squarebot message key.
44
+ """
45
+ return cls(channel=event.event.channel)
46
+
47
+
48
+ class SquarebotSlackMessageValue(AvroBaseModel):
49
+ """Kafka message value model for Slack messages sent by Squarebot.
50
+
51
+ This value schema should be paired with `SquarebotSlackMessageKey` for
52
+ the key schema.
53
+ """
54
+
55
+ type: SlackMessageType = Field(..., description="The Slack event type.")
56
+
57
+ channel: str = Field(..., description="The Slack channel ID.")
58
+
59
+ channel_type: SlackChannelType = Field(
60
+ ..., description="The Slack channel type."
61
+ )
62
+
63
+ user: str = Field(
64
+ ..., description="The ID of the user that sent the message."
65
+ )
66
+
67
+ ts: str = Field(
68
+ ...,
69
+ description=(
70
+ "The Slack message timestamp. This is string-formatted to allow "
71
+ "comparison with other Slack messges which use the ``ts`` to "
72
+ "identify and reference messages."
73
+ ),
74
+ )
75
+
76
+ text: str = Field(..., description="The Slack message text content.")
77
+
78
+ slack_event: str = Field(
79
+ ..., description="The original Slack event JSON string."
80
+ )
81
+
82
+ class Meta:
83
+ """Metadata for the model."""
84
+
85
+ namespace = "lsst.square-events.squarebot.messages"
86
+ schema_name = "value"
87
+
88
+ @classmethod
89
+ def from_event(cls, event: SlackMessageEvent, raw: dict[str, Any]) -> Self:
90
+ """Create a Kafka value for a Slack message from a Slack event.
91
+
92
+ Parameters
93
+ ----------
94
+ event
95
+ The Slack event.
96
+ raw
97
+ The raw Slack event JSON.
98
+
99
+ Returns
100
+ -------
101
+ value
102
+ The Squarebot message value.
103
+ """
104
+ return cls(
105
+ type=event.event.type,
106
+ channel=event.event.channel,
107
+ channel_type=event.event.channel_type,
108
+ user=event.event.user,
109
+ ts=event.event.ts,
110
+ text=event.event.text,
111
+ slack_event=json.dumps(raw),
112
+ )
113
+
114
+
115
+ class SquarebotSlackAppMentionValue(AvroBaseModel):
116
+ """Kafka message value model for Slack app_mention message sent by
117
+ Squarebot.
118
+
119
+ These are like `SquarebotSlackMessageValue` but lack a `channel_type`
120
+ field.
121
+
122
+ This value schema should be paired with `SquarebotSlackMessageKey` for
123
+ the key schema.
124
+ """
125
+
126
+ type: SlackMessageType = Field(..., description="The Slack event type.")
127
+
128
+ channel: str = Field(..., description="The Slack channel ID.")
129
+
130
+ user: str = Field(
131
+ ..., description="The ID of the user that sent the message."
132
+ )
133
+
134
+ ts: str = Field(
135
+ ...,
136
+ description=(
137
+ "The Slack message timestamp. This is string-formatted to allow "
138
+ "comparison with other Slack messges which use the ``ts`` to "
139
+ "identify and reference messages."
140
+ ),
141
+ )
142
+
143
+ text: str = Field(..., description="The Slack message text content.")
144
+
145
+ slack_event: str = Field(
146
+ ..., description="The original Slack event JSON string."
147
+ )
148
+
149
+ class Meta:
150
+ """Metadata for the model."""
151
+
152
+ namespace = "lsst.square-events.squarebot.appmention"
153
+ schema_name = "value"
154
+
155
+ @classmethod
156
+ def from_event(cls, event: SlackMessageEvent, raw: dict[str, Any]) -> Self:
157
+ """Create a Kafka value for a Slack message from a Slack event.
158
+
159
+ Parameters
160
+ ----------
161
+ event
162
+ The Slack event.
163
+ raw
164
+ The raw Slack event JSON.
165
+
166
+ Returns
167
+ -------
168
+ value
169
+ The Squarebot message value.
170
+ """
171
+ return cls(
172
+ type=event.event.type,
173
+ channel=event.event.channel,
174
+ channel_type=event.event.channel_type,
175
+ user=event.event.user,
176
+ ts=event.event.ts,
177
+ text=event.event.text,
178
+ slack_event=json.dumps(raw),
179
+ )
@@ -0,0 +1,207 @@
1
+ """Slack API models."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from enum import Enum
6
+ from typing import Optional
7
+
8
+ from pydantic import BaseModel, Field
9
+
10
+ __all__ = [
11
+ "BaseSlackEvent",
12
+ "SlackUrlVerificationEvent",
13
+ "SlackMessageEvent",
14
+ "SlackMessageType",
15
+ "SlackChannelType",
16
+ "SlackMessageEventContent",
17
+ "SlackBlockAction",
18
+ "SlackUser",
19
+ "SlackTeam",
20
+ "SlackChannel",
21
+ ]
22
+
23
+
24
+ class BaseSlackEvent(BaseModel):
25
+ """A model for the minimal request payload from Slack for an event.
26
+
27
+ Any event message is gauranteed to have these fields. For specific types of
28
+ events, re-parse the request body with a specific model such as
29
+ `SlackMessageEvent`. For information about all the Slack event types, see
30
+ https://api.slack.com/events.
31
+ """
32
+
33
+ type: str = Field(
34
+ ...,
35
+ description=(
36
+ "The Slack event type in the message's outer scope; typically "
37
+ "this is ``url_verification`` or ``event_callback``."
38
+ ),
39
+ )
40
+
41
+
42
+ class SlackUrlVerificationEvent(BaseSlackEvent):
43
+ """A Slack ``url_verification`` event."""
44
+
45
+ challenge: str = Field(..., description="URL challenge content.")
46
+
47
+
48
+ class SlackMessageType(str, Enum):
49
+ app_mention = "app_mention"
50
+ message = "message"
51
+
52
+
53
+ class SlackChannelType(str, Enum):
54
+ channel = "channel" # public channel
55
+ group = "group" # private channel
56
+ im = "im" # direct message
57
+ mpim = "mpim" # multi-persion direct message
58
+
59
+
60
+ class SlackMessageEventContent(BaseModel):
61
+ """A model for the ``event`` field inside a message event.
62
+
63
+ See https://api.slack.com/events/app_mention and
64
+ https://api.slack.com/events/message.
65
+ """
66
+
67
+ type: SlackMessageType = Field(description="The Slack message type.")
68
+
69
+ channel: str = Field(
70
+ description=(
71
+ "ID of the channel where the message was sent "
72
+ "(e.g., C0LAN2Q65)."
73
+ )
74
+ )
75
+
76
+ channel_type: Optional[SlackChannelType] = Field(
77
+ description=(
78
+ "The type of channel (public, direct im, etc..). This is null for "
79
+ "``app_mention`` events."
80
+ )
81
+ )
82
+
83
+ user: str = Field(
84
+ description="The ID of the user that sent the message (eg U061F7AUR)."
85
+ )
86
+
87
+ text: str = Field(description="Content of the message.")
88
+
89
+ ts: str = Field(description="Timestamp of the message.")
90
+
91
+ event_ts: str = Field(description="When the event was dispatched.")
92
+
93
+
94
+ class SlackMessageEvent(BaseSlackEvent):
95
+ """A Slack event for message events in general.
96
+
97
+ See https://api.slack.com/events/app_mention and
98
+ https://api.slack.com/events/message.
99
+ """
100
+
101
+ team_id: str = Field(
102
+ description=(
103
+ "The unique identifier of the workspace where the event occurred."
104
+ )
105
+ )
106
+
107
+ api_app_id: str = Field(
108
+ description=(
109
+ "The unique identifier of your installed Slack application. Use "
110
+ "this to distinguish which app the event belongs to if you use "
111
+ "multiple apps with the same Request URL."
112
+ )
113
+ )
114
+
115
+ event_id: str = Field(
116
+ description=(
117
+ "A unique identifier for this specific event, globally unique "
118
+ "across all workspaces."
119
+ )
120
+ )
121
+
122
+ event_time: int = Field(
123
+ description=(
124
+ "The epoch timestamp in seconds indicating when this event was "
125
+ "dispatched."
126
+ )
127
+ )
128
+
129
+ authed_users: Optional[list[str]] = Field(
130
+ None,
131
+ description=(
132
+ "An array of string-based User IDs. Each member of the collection "
133
+ "represents a user that has installed your application/bot and "
134
+ "indicates the described event would be visible to those users."
135
+ ),
136
+ )
137
+
138
+ event: SlackMessageEventContent
139
+
140
+
141
+ class SlackUser(BaseModel):
142
+ """A model for the user field in Slack interaction payloads."""
143
+
144
+ id: str = Field(description="ID of the user.")
145
+
146
+ username: str = Field(description="User name of the user.")
147
+
148
+ team_id: str = Field(description="The user's team.")
149
+
150
+
151
+ class SlackTeam(BaseModel):
152
+ """A model for the team field in Slack interaction payloads."""
153
+
154
+ id: str = Field(description="ID of the team.")
155
+
156
+ domain: str = Field(description="Domain name of the team.")
157
+
158
+
159
+ class SlackChannel(BaseModel):
160
+ """A model for the channel field in Slack interaction payloads."""
161
+
162
+ id: str = Field(description="ID of the channel.")
163
+
164
+ name: str = Field(description="Name of the channel.")
165
+
166
+
167
+ class SlackBlockAction(BaseModel):
168
+ """A model for a Slack Block kit interaction.
169
+
170
+ This isn't yet a full model for a block action payload; experience is
171
+ needed to fully understand what the payloads are for the types of
172
+ interactions we use.
173
+
174
+ See https://api.slack.com/reference/interaction-payloads/block-actions
175
+ """
176
+
177
+ type: str = Field(description="Should be `block_actions`.")
178
+
179
+ trigger_id: str = Field(
180
+ description="A short-lived ID used to launch modals."
181
+ )
182
+
183
+ api_app_id: str = Field(
184
+ description=(
185
+ "The unique identifier of your installed Slack application. Use "
186
+ "this to distinguish which app the event belongs to if you use "
187
+ "multiple apps with the same Request URL."
188
+ )
189
+ )
190
+
191
+ response_url: str = Field(
192
+ description=(
193
+ "A short-lived URL to send message in response to interactions."
194
+ )
195
+ )
196
+
197
+ user: SlackUser = Field(
198
+ description=(
199
+ "Information about the user that triggered the interaction."
200
+ )
201
+ )
202
+
203
+ team: SlackTeam = Field(description="Information about the Slack team.")
204
+
205
+ channel: SlackChannel = Field(
206
+ description="Information about the Slack channel."
207
+ )
File without changes