|
1 | | -from typing import Dict, Any |
| 1 | +from typing import Dict, Any, Union |
| 2 | +from enum import StrEnum |
2 | 3 | from slack_sdk.models.basic_objects import JsonObject |
3 | 4 |
|
4 | 5 |
|
@@ -28,3 +29,180 @@ def __str__(self): |
28 | 29 |
|
29 | 30 | def __repr__(self): |
30 | 31 | return self.__str__() |
| 32 | + |
| 33 | + |
| 34 | +## Work object entity metadata |
| 35 | + |
| 36 | +class EntityType(StrEnum): |
| 37 | + FILE = "slack#/entities/file" |
| 38 | + TASK = "slack#/entities/task" |
| 39 | + ITEM = "slack#/entities/item" |
| 40 | + INCIDENT = "slack#/entities/incident" |
| 41 | + CONTENT_ITEM = "slack#/entities/content_item" |
| 42 | + |
| 43 | + |
| 44 | +class ExternalRef(JsonObject): |
| 45 | + attributes = { |
| 46 | + "id", |
| 47 | + "type", |
| 48 | + } |
| 49 | + def __init__( |
| 50 | + self, |
| 51 | + id: str, |
| 52 | + type: str = None, |
| 53 | + **kwargs, |
| 54 | + ): |
| 55 | + self.id = id |
| 56 | + self.type = type |
| 57 | + self.additional_attributes = kwargs |
| 58 | + |
| 59 | + def __str__(self): |
| 60 | + return str(self.get_non_null_attributes()) |
| 61 | + |
| 62 | + def __repr__(self): |
| 63 | + return self.__str__() |
| 64 | + |
| 65 | +class Title(JsonObject): |
| 66 | + attributes = { |
| 67 | + "text", |
| 68 | + "edit", |
| 69 | + } |
| 70 | + def __init__( |
| 71 | + self, |
| 72 | + text: str, |
| 73 | + edit: Dict[str, Any] = None, # TODO EntityEditSupport |
| 74 | + **kwargs, |
| 75 | + ): |
| 76 | + self.text = text |
| 77 | + self.edit = edit |
| 78 | + self.additional_attributes = kwargs |
| 79 | + |
| 80 | + def __str__(self): |
| 81 | + return str(self.get_non_null_attributes()) |
| 82 | + |
| 83 | + def __repr__(self): |
| 84 | + return self.__str__() |
| 85 | + |
| 86 | + |
| 87 | +class Attributes(JsonObject): |
| 88 | + attributes = { |
| 89 | + "title", |
| 90 | + "display_type", |
| 91 | + "display_id", |
| 92 | + "product_icon" |
| 93 | + "product_name" |
| 94 | + "locale" |
| 95 | + "full_size_preview" |
| 96 | + "metadata_last_modified" |
| 97 | + } |
| 98 | + def __init__( |
| 99 | + self, |
| 100 | + title: Title, |
| 101 | + display_type: str = None, |
| 102 | + display_id: str = None, |
| 103 | + product_icon: Dict[str, Any] = None, |
| 104 | + product_name: str = None, |
| 105 | + locale: str = None, |
| 106 | + full_size_preview: str = None, |
| 107 | + metadata_last_modified: int = None, |
| 108 | + **kwargs, |
| 109 | + ): |
| 110 | + self.title = title |
| 111 | + self.display_type = display_type |
| 112 | + self.display_id = display_id |
| 113 | + self.product_icon = product_icon |
| 114 | + self.product_name = product_name |
| 115 | + self.locale = locale |
| 116 | + self.full_size_preview = full_size_preview |
| 117 | + self.metadata_last_modified = metadata_last_modified |
| 118 | + self.additional_attributes = kwargs |
| 119 | + |
| 120 | + def __str__(self): |
| 121 | + return str(self.get_non_null_attributes()) |
| 122 | + |
| 123 | + def __repr__(self): |
| 124 | + return self.__str__() |
| 125 | + |
| 126 | + |
| 127 | +class EntityPayload(JsonObject): |
| 128 | + attributes = { |
| 129 | + "attributes" |
| 130 | + } |
| 131 | + def __init__( |
| 132 | + self, |
| 133 | + attributes: Attributes, |
| 134 | + **kwargs, |
| 135 | + ): |
| 136 | + self.attributes = attributes |
| 137 | + # TODO |
| 138 | + self.additional_attributes = kwargs |
| 139 | + |
| 140 | + def __str__(self): |
| 141 | + return str(self.get_non_null_attributes()) |
| 142 | + |
| 143 | + def __repr__(self): |
| 144 | + return self.__str__() |
| 145 | + |
| 146 | + |
| 147 | +class EntityMetadata(JsonObject): |
| 148 | + """Work object entity metadata |
| 149 | +
|
| 150 | + https://docs.slack.dev/messaging/work-objects/ |
| 151 | + """ |
| 152 | + |
| 153 | + attributes = { |
| 154 | + "entity_type", |
| 155 | + "external_ref", |
| 156 | + "url", |
| 157 | + "app_unfurl_url", |
| 158 | + "entity_payload", |
| 159 | + } |
| 160 | + |
| 161 | + def __init__( |
| 162 | + self, |
| 163 | + entity_type: Union[str, EntityType], |
| 164 | + external_ref: Union[Dict[str, Any], ExternalRef], |
| 165 | + url: str, |
| 166 | + entity_payload: Union[Dict[str, Any], EntityPayload], |
| 167 | + app_unfurl_url: str = None, |
| 168 | + **kwargs, |
| 169 | + ): |
| 170 | + self.entity_type = entity_type |
| 171 | + self.external_ref = external_ref |
| 172 | + self.url = url |
| 173 | + self.app_unfurl_url = app_unfurl_url |
| 174 | + self.entity_payload = entity_payload |
| 175 | + self.additional_attributes = kwargs |
| 176 | + |
| 177 | + def __str__(self): |
| 178 | + return str(self.get_non_null_attributes()) |
| 179 | + |
| 180 | + def __repr__(self): |
| 181 | + return self.__str__() |
| 182 | + |
| 183 | + |
| 184 | +class EventAndEntityMetadata(JsonObject): |
| 185 | + """Message metadata |
| 186 | +
|
| 187 | + https://docs.slack.dev/messaging/message-metadata/ |
| 188 | + """ |
| 189 | + |
| 190 | + attributes = {"event_type", "event_payload", "entities"} |
| 191 | + |
| 192 | + def __init__( |
| 193 | + self, |
| 194 | + event_type: str = None, |
| 195 | + event_payload: Dict[str, Any] = None, |
| 196 | + entities: list[EntityMetadata] = None, |
| 197 | + **kwargs, |
| 198 | + ): |
| 199 | + self.event_type = event_type |
| 200 | + self.event_payload = event_payload |
| 201 | + self.entities = entities |
| 202 | + self.additional_attributes = kwargs |
| 203 | + |
| 204 | + def __str__(self): |
| 205 | + return str(self.get_non_null_attributes()) |
| 206 | + |
| 207 | + def __repr__(self): |
| 208 | + return self.__str__() |
0 commit comments