Skip to content

Commit 0aab530

Browse files
committed
update
1 parent 12c78c2 commit 0aab530

File tree

5 files changed

+1138
-42
lines changed

5 files changed

+1138
-42
lines changed

integration_tests/web/test_message_metadata.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
import os
33
import time
44
import unittest
5+
import json
56

67
from integration_tests.env_variable_names import SLACK_SDK_TEST_BOT_TOKEN
7-
from slack_sdk.models.metadata import Metadata, EventAndEntityMetadata, EntityMetadata, EntityType, ExternalRef
8+
from slack_sdk.models.metadata import (
9+
Metadata, EventAndEntityMetadata, EntityMetadata, EntityType, 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
15+
)
816
from slack_sdk.web import WebClient
917

1018

@@ -128,9 +136,68 @@ def test_publishing_message_metadata_using_models(self):
128136

129137
def test_publishing_message_entity_metadata_using_models(self):
130138

131-
payload = { "attributes": { "title": { "text": "Work References" }, "product_name": "We reference only", "metadata_last_modified": 1760999279, "full_size_preview": { "is_supported": True } }, "fields": { "due_date": { "value": "2026-06-06", "type": "slack#/types/date", "edit": { "enabled": True } }, "created_by": { "type": "slack#/types/user", "user": { "user_id": "U014KLZE350" }, "edit": { "enabled": True } }, "description": { "value": "Initial task work object for test test test", "format": "markdown", "long": True, "edit": { "enabled": True, "text": { "min_length": 1, "max_length": 100 } } }, "date_created": { "value": 1760629278 }, "date_updated": { "value": 1760999279 } }, "custom_fields": [ { "label": "img", "key": "img", "type": "slack#/types/image", "image_url": "https://cdn.shopify.com/s/files/1/0156/3796/files/shutterstock_54266797_large.jpg?v=1549042211" }, { "label": "Reference tasks", "key": "ref-tasks", "type": "slack#/types/entity_ref", "entity_ref": { "entity_url": "https://app-one-app-two-auth-dev.tinyspeck.com/admin/slack/workobject/129/change/", "external_ref": { "id": "129" }, "title": "Radiant task", "display_type": "tasks", "icon": { "alt_text": "img", "url": "https://avatars.slack-edge.com/2024-09-05/7707480927360_791cc0c5cdf5b6720b21_512.png" } } }, { "label": "All related references", "key": "related-refs", "type": "array", "item_type": "slack#/types/entity_ref", "value": [ { "entity_ref": { "entity_url": "https://app-one-app-two-auth-dev.tinyspeck.com/admin/slack/workobject/131/change/", "external_ref": { "id": "131" }, "title": "Work object planner", "icon": { "alt_text": "img", "url": "https://avatars.slack-edge.com/2024-09-05/7707480927360_791cc0c5cdf5b6720b21_512.png" } } }, { "entity_ref": { "entity_url": "https://app-one-app-two-auth-dev.tinyspeck.com/admin/slack/workobject/133/change/", "external_ref": { "id": "133" }, "title": "Test" } }, { "entity_ref": { "entity_url": "https://app-one-app-two-auth-dev.tinyspeck.com/admin/slack/workobject/142/change/", "external_ref": { "id": "142" }, "title": "Test" } } ] } ] }
139+
# Build the metadata
132140

133-
client: WebClient = WebClient(token=self.bot_token,base_url='https://dev2378.slack.com/api/')
141+
title = EntityTitle(text="My title")
142+
full_size_preview = EntityFullSizePreview(
143+
is_supported=True,
144+
preview_url="https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
145+
mime_type="image/jpeg"
146+
)
147+
attributes = EntityAttributes(
148+
title=title,
149+
product_name="My Product",
150+
full_size_preview=full_size_preview
151+
)
152+
description = EntityStringField(
153+
value="Description of the task.",
154+
long=True,
155+
edit=EntityEditSupport(
156+
enabled=True,
157+
text=EntityEditTextConfig(
158+
min_length=5,
159+
max_length=100
160+
)
161+
)
162+
)
163+
due_date = EntityTypedField(
164+
value="2026-06-06",
165+
type="slack#/types/date",
166+
edit=EntityEditSupport(enabled=True)
167+
)
168+
created_by = EntityTypedField(
169+
type="slack#/types/user",
170+
user=EntityUserIDField(user_id="USLACKBOT"),
171+
)
172+
date_created = EntityTimestampField(
173+
value=1762450663,
174+
type="slack#/types/timestamp"
175+
)
176+
date_updated = EntityTimestampField(
177+
value=1762450663,
178+
type="slack#/types/timestamp"
179+
)
180+
fields = TaskEntityFields(
181+
description=description,
182+
due_date=due_date,
183+
created_by=created_by,
184+
date_created=date_created,
185+
date_updated=date_updated
186+
)
187+
custom_fields = []
188+
custom_fields.append(EntityCustomField(
189+
label="My Image",
190+
key="my-image",
191+
type="slack#/types/image",
192+
image_url="https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg"
193+
))
194+
entity = EntityPayload(
195+
attributes=attributes,
196+
fields=fields,
197+
custom_fields=custom_fields
198+
)
199+
200+
client: WebClient = WebClient(token=self.bot_token)
134201
new_message = client.chat_postMessage(
135202
channel="C014KLZN9M0",
136203
text="dbl check message with metadata",
@@ -140,9 +207,10 @@ def test_publishing_message_entity_metadata_using_models(self):
140207
entity_type=EntityType.TASK,
141208
external_ref=ExternalRef(id="abc123"),
142209
url="https://myappdomain.com",
143-
entity_payload=payload,
210+
entity_payload=entity,
144211
)]),
145212
)
146213

147214
self.assertIsNone(new_message.get("error"))
215+
print(new_message.get("response_metadata"))
148216
self.assertIsNone(new_message.get("warning"))

0 commit comments

Comments
 (0)