|
6 | 6 |
|
7 | 7 | from integration_tests.env_variable_names import SLACK_SDK_TEST_BOT_TOKEN |
8 | 8 | from slack_sdk.models.metadata import ( |
9 | | - Metadata, EventAndEntityMetadata, EntityMetadata, ExternalRef, |
10 | | - EntityPayload, EntityAttributes, EntityTitle, TaskEntityFields, EntityStringField, |
11 | | - EntityTitle, EntityAttributes, EntityFullSizePreview, |
12 | | - TaskEntityFields, EntityTypedField, EntityStringField, EntityTimestampField, |
13 | | - EntityEditSupport, EntityEditTextConfig, EntityCustomField, EntityUserIDField, |
14 | | - EntityIconField, ExternalRef as CustomExternalRef, EntityArrayItemField |
| 9 | + Metadata, |
| 10 | + EventAndEntityMetadata, |
| 11 | + EntityMetadata, |
| 12 | + ExternalRef, |
| 13 | + EntityPayload, |
| 14 | + EntityAttributes, |
| 15 | + EntityTitle, |
| 16 | + TaskEntityFields, |
| 17 | + EntityStringField, |
| 18 | + EntityTitle, |
| 19 | + EntityAttributes, |
| 20 | + EntityFullSizePreview, |
| 21 | + TaskEntityFields, |
| 22 | + EntityTypedField, |
| 23 | + EntityStringField, |
| 24 | + EntityTimestampField, |
| 25 | + EntityEditSupport, |
| 26 | + EntityEditTextConfig, |
| 27 | + EntityCustomField, |
| 28 | + EntityUserIDField, |
| 29 | + ExternalRef, |
15 | 30 | ) |
16 | 31 | from slack_sdk.web import WebClient |
17 | 32 |
|
@@ -139,118 +154,92 @@ def test_publishing_entity_metadata(self): |
139 | 154 | new_message = client.chat_postMessage( |
140 | 155 | channel="C014KLZN9M0", |
141 | 156 | text="Message with entity metadata", |
142 | | - metadata={"entities": [{ |
143 | | - "entity_type": "slack#/entities/task", |
144 | | - "url": "https://abc.com/123", |
145 | | - "external_ref": {"id": "123"}, |
146 | | - "entity_payload": { |
147 | | - "attributes": { |
148 | | - "title": {"text": "My task"}, |
149 | | - "product_name": "We reference only" |
150 | | - }, |
151 | | - "fields": { |
152 | | - "due_date": { |
153 | | - "value": "2026-06-06", |
154 | | - "type": "slack#/types/date", |
155 | | - "edit": {"enabled": True} |
156 | | - }, |
157 | | - "created_by": { |
158 | | - "type": "slack#/types/user", |
159 | | - "user": {"user_id": "U014KLZE350"} |
| 157 | + metadata={ |
| 158 | + "entities": [ |
| 159 | + { |
| 160 | + "entity_type": "slack#/entities/task", |
| 161 | + "url": "https://abc.com/123", |
| 162 | + "external_ref": {"id": "123"}, |
| 163 | + "entity_payload": { |
| 164 | + "attributes": {"title": {"text": "My task"}, "product_name": "We reference only"}, |
| 165 | + "fields": { |
| 166 | + "due_date": {"value": "2026-06-06", "type": "slack#/types/date", "edit": {"enabled": True}}, |
| 167 | + "created_by": {"type": "slack#/types/user", "user": {"user_id": "U014KLZE350"}}, |
| 168 | + "date_created": {"value": 1760629278}, |
| 169 | + }, |
| 170 | + "custom_fields": [ |
| 171 | + { |
| 172 | + "label": "img", |
| 173 | + "key": "img", |
| 174 | + "type": "slack#/types/image", |
| 175 | + "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg", |
| 176 | + } |
| 177 | + ], |
160 | 178 | }, |
161 | | - "date_created": {"value": 1760629278} |
162 | | - }, |
163 | | - "custom_fields": [ |
164 | | - { |
165 | | - "label": "img", |
166 | | - "key": "img", |
167 | | - "type": "slack#/types/image", |
168 | | - "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg" |
169 | | - } |
170 | | - ] |
171 | | - } |
172 | | - }]} |
| 179 | + } |
| 180 | + ] |
| 181 | + }, |
173 | 182 | ) |
174 | | - |
| 183 | + |
175 | 184 | self.assertIsNone(new_message.get("error")) |
176 | 185 | self.assertIsNone(new_message.get("warning")) |
177 | 186 |
|
178 | 187 | def test_publishing_entity_metadata_using_models(self): |
179 | | - |
| 188 | + |
180 | 189 | # Build the metadata |
181 | | - |
| 190 | + |
182 | 191 | title = EntityTitle(text="My title") |
183 | 192 | full_size_preview = EntityFullSizePreview( |
184 | 193 | is_supported=True, |
185 | 194 | preview_url="https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg", |
186 | | - mime_type="image/jpeg" |
187 | | - ) |
188 | | - attributes = EntityAttributes( |
189 | | - title=title, |
190 | | - product_name="My Product", |
191 | | - full_size_preview=full_size_preview |
| 195 | + mime_type="image/jpeg", |
192 | 196 | ) |
| 197 | + attributes = EntityAttributes(title=title, product_name="My Product", full_size_preview=full_size_preview) |
193 | 198 | description = EntityStringField( |
194 | 199 | value="Description of the task.", |
195 | 200 | long=True, |
196 | | - edit=EntityEditSupport( |
197 | | - enabled=True, |
198 | | - text=EntityEditTextConfig( |
199 | | - min_length=5, |
200 | | - max_length=100 |
201 | | - ) |
202 | | - ) |
203 | | - ) |
204 | | - due_date = EntityTypedField( |
205 | | - value="2026-06-06", |
206 | | - type="slack#/types/date", |
207 | | - edit=EntityEditSupport(enabled=True) |
| 201 | + edit=EntityEditSupport(enabled=True, text=EntityEditTextConfig(min_length=5, max_length=100)), |
208 | 202 | ) |
| 203 | + due_date = EntityTypedField(value="2026-06-06", type="slack#/types/date", edit=EntityEditSupport(enabled=True)) |
209 | 204 | created_by = EntityTypedField( |
210 | 205 | type="slack#/types/user", |
211 | 206 | user=EntityUserIDField(user_id="USLACKBOT"), |
212 | 207 | ) |
213 | | - date_created = EntityTimestampField( |
214 | | - value=1762450663, |
215 | | - type="slack#/types/timestamp" |
216 | | - ) |
217 | | - date_updated = EntityTimestampField( |
218 | | - value=1762450663, |
219 | | - type="slack#/types/timestamp" |
220 | | - ) |
| 208 | + date_created = EntityTimestampField(value=1762450663, type="slack#/types/timestamp") |
| 209 | + date_updated = EntityTimestampField(value=1762450663, type="slack#/types/timestamp") |
221 | 210 | fields = TaskEntityFields( |
222 | 211 | description=description, |
223 | 212 | due_date=due_date, |
224 | 213 | created_by=created_by, |
225 | 214 | date_created=date_created, |
226 | | - date_updated=date_updated |
| 215 | + date_updated=date_updated, |
227 | 216 | ) |
228 | 217 | custom_fields = [] |
229 | | - custom_fields.append(EntityCustomField( |
230 | | - label="My Image", |
231 | | - key="my-image", |
232 | | - type="slack#/types/image", |
233 | | - image_url="https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg" |
234 | | - )) |
235 | | - entity = EntityPayload( |
236 | | - attributes=attributes, |
237 | | - fields=fields, |
238 | | - custom_fields=custom_fields |
| 218 | + custom_fields.append( |
| 219 | + EntityCustomField( |
| 220 | + label="My Image", |
| 221 | + key="my-image", |
| 222 | + type="slack#/types/image", |
| 223 | + image_url="https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg", |
| 224 | + ) |
239 | 225 | ) |
| 226 | + entity = EntityPayload(attributes=attributes, fields=fields, custom_fields=custom_fields) |
240 | 227 |
|
241 | 228 | client: WebClient = WebClient(token=self.bot_token) |
242 | 229 | new_message = client.chat_postMessage( |
243 | | - channel="C014KLZN9M0", |
| 230 | + channel="#random", |
244 | 231 | text="Message with entity metadata", |
245 | 232 | metadata=EventAndEntityMetadata( |
246 | 233 | entities=[ |
247 | 234 | EntityMetadata( |
248 | | - entity_type="slack#/entities/task", |
249 | | - external_ref=ExternalRef(id="abc123"), |
250 | | - url="https://myappdomain.com", |
251 | | - entity_payload=entity, |
252 | | - )]), |
| 235 | + entity_type="slack#/entities/task", |
| 236 | + external_ref=ExternalRef(id="abc123"), |
| 237 | + url="https://myappdomain.com", |
| 238 | + entity_payload=entity, |
| 239 | + ) |
| 240 | + ] |
| 241 | + ), |
253 | 242 | ) |
254 | | - |
| 243 | + |
255 | 244 | self.assertIsNone(new_message.get("error")) |
256 | 245 | self.assertIsNone(new_message.get("warning")) |
0 commit comments