Skip to content

Commit 6d4435b

Browse files
committed
feat(slack): implement dynamic block kit builders for draft card and modal
1 parent 480cdd3 commit 6d4435b

File tree

3 files changed

+159
-48
lines changed

3 files changed

+159
-48
lines changed

backend/config/lexicon.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,15 @@
1919
"interact_approved_section": "✅ *Опубліковано!*\nДрафт відправлено в чергу на публікацію.",
2020
"interact_rejected_text": "❌ Драфт відхилено.",
2121
"interact_rejected_section": "❌ *Відхилено!*\nЦей варіант видалено. Можете спробувати іншу тему.",
22+
# --- Draft Card ---
23+
"btn_edit": "Редагувати",
24+
"btn_regenerate": "Перегенерувати",
25+
"fact_check_ok": "✅ Fact-check: Пройдено",
26+
"fact_check_sources": "📚 Джерела: PubMed",
27+
# --- Modal ---
28+
"modal_title": "Редагування посту",
29+
"modal_submit": "Зберегти",
30+
"modal_cancel": "Скасувати",
31+
"modal_input_label": "Текст публікації",
32+
"modal_platform_label": "Платформа",
2233
}

backend/workers/callbacks.py

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from backend.config.lexicon import SLACK_UI
77
from backend.config.settings import settings
8+
from slack_app.utils.block_builder import build_draft_card
89

910
logger = structlog.get_logger()
1011

@@ -51,53 +52,7 @@ async def notify_slack_on_complete(
5152
payload = {
5253
"channel": channel_id,
5354
"text": SLACK_UI["draft_ready_fallback"].format(topic=topic),
54-
"blocks": [
55-
{
56-
"type": "header",
57-
"text": {
58-
"type": "plain_text",
59-
"text": SLACK_UI["draft_ready_header"].format(topic=topic),
60-
"emoji": True,
61-
},
62-
},
63-
{"type": "section", "text": {"type": "mrkdwn", "text": f"```{draft}```"}},
64-
{
65-
"type": "context",
66-
"elements": [
67-
{
68-
"type": "mrkdwn",
69-
"text": SLACK_UI["ordered_by"].format(user_id=user_id),
70-
}
71-
],
72-
},
73-
{
74-
"type": "actions",
75-
"elements": [
76-
{
77-
"type": "button",
78-
"text": {
79-
"type": "plain_text",
80-
"text": SLACK_UI["btn_publish"],
81-
"emoji": True,
82-
},
83-
"style": "primary",
84-
"value": "publish",
85-
"action_id": "action_publish_draft",
86-
},
87-
{
88-
"type": "button",
89-
"text": {
90-
"type": "plain_text",
91-
"text": SLACK_UI["btn_reject"],
92-
"emoji": True,
93-
},
94-
"style": "danger",
95-
"value": "reject",
96-
"action_id": "action_reject_draft",
97-
},
98-
],
99-
},
100-
],
55+
"blocks": build_draft_card(topic=topic, draft=draft, user_id=user_id),
10156
}
10257
await _send_slack_message(payload)
10358

slack_app/utils/block_builder.py

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,146 @@
1-
# slack_app/utils/block_builder.py
1+
from typing import Any
2+
3+
from backend.config.lexicon import SLACK_UI
4+
5+
6+
def build_draft_card(topic: str, draft: str, user_id: str) -> list[dict[str, Any]]:
7+
"""Генерує картку чернетки з кнопками дій."""
8+
return [
9+
{
10+
"type": "header",
11+
"text": {
12+
"type": "plain_text",
13+
"text": SLACK_UI["draft_ready_header"].format(topic=topic),
14+
"emoji": True,
15+
},
16+
},
17+
{"type": "section", "text": {"type": "mrkdwn", "text": f"```{draft}```"}},
18+
{
19+
"type": "context",
20+
"elements": [
21+
{
22+
"type": "mrkdwn",
23+
"text": SLACK_UI["ordered_by"].format(user_id=user_id),
24+
},
25+
{
26+
"type": "mrkdwn",
27+
"text": f"{SLACK_UI['fact_check_ok']} | {SLACK_UI['fact_check_sources']}",
28+
},
29+
],
30+
},
31+
{
32+
"type": "actions",
33+
"elements": [
34+
{
35+
"type": "button",
36+
"text": {
37+
"type": "plain_text",
38+
"text": SLACK_UI["btn_publish"],
39+
"emoji": True,
40+
},
41+
"style": "primary",
42+
"value": "publish",
43+
"action_id": "action_publish_draft",
44+
},
45+
{
46+
"type": "button",
47+
"text": {
48+
"type": "plain_text",
49+
"text": SLACK_UI["btn_edit"],
50+
"emoji": True,
51+
},
52+
"value": "edit",
53+
"action_id": "action_edit_draft",
54+
},
55+
{
56+
"type": "button",
57+
"text": {
58+
"type": "plain_text",
59+
"text": SLACK_UI["btn_regenerate"],
60+
"emoji": True,
61+
},
62+
"value": "regenerate",
63+
"action_id": "action_regenerate_draft",
64+
},
65+
{
66+
"type": "button",
67+
"text": {
68+
"type": "plain_text",
69+
"text": SLACK_UI["btn_reject"],
70+
"emoji": True,
71+
},
72+
"style": "danger",
73+
"value": "reject",
74+
"action_id": "action_reject_draft",
75+
},
76+
],
77+
},
78+
]
79+
80+
81+
def build_approval_modal(topic: str, draft: str, platform: str = "telegram") -> dict[str, Any]:
82+
"""Генерує модальне вікно для редагування тексту перед публікацією."""
83+
return {
84+
"type": "modal",
85+
"callback_id": "modal_edit_draft",
86+
"private_metadata": topic, # Зберігаємо тему для контексту
87+
"title": {"type": "plain_text", "text": SLACK_UI["modal_title"], "emoji": True},
88+
"submit": {
89+
"type": "plain_text",
90+
"text": SLACK_UI["modal_submit"],
91+
"emoji": True,
92+
},
93+
"close": {
94+
"type": "plain_text",
95+
"text": SLACK_UI["modal_cancel"],
96+
"emoji": True,
97+
},
98+
"blocks": [
99+
{
100+
"type": "input",
101+
"block_id": "block_draft_content",
102+
"element": {
103+
"type": "plain_text_input",
104+
"action_id": "input_draft_content",
105+
"multiline": True,
106+
"initial_value": draft,
107+
},
108+
"label": {
109+
"type": "plain_text",
110+
"text": SLACK_UI["modal_input_label"],
111+
"emoji": True,
112+
},
113+
},
114+
{
115+
"type": "input",
116+
"block_id": "block_platform_select",
117+
"element": {
118+
"type": "static_select",
119+
"action_id": "input_platform_select",
120+
"initial_option": {
121+
"text": {"type": "plain_text", "text": platform.capitalize()},
122+
"value": platform.lower(),
123+
},
124+
"options": [
125+
{
126+
"text": {"type": "plain_text", "text": "Telegram"},
127+
"value": "telegram",
128+
},
129+
{
130+
"text": {"type": "plain_text", "text": "Twitter"},
131+
"value": "twitter",
132+
},
133+
{
134+
"text": {"type": "plain_text", "text": "Threads"},
135+
"value": "threads",
136+
},
137+
],
138+
},
139+
"label": {
140+
"type": "plain_text",
141+
"text": SLACK_UI["modal_platform_label"],
142+
"emoji": True,
143+
},
144+
},
145+
],
146+
}

0 commit comments

Comments
 (0)