Skip to content

Commit b0860f5

Browse files
clauderoeniss
authored andcommitted
Match the ics body format to gcal: permalink first, then the intro
DESCRIPTION becomes '슬랙에서 소개글 보기: <permalink>\n\n<intro>', fetched fresh at click time like the intro. No truncation — the ics body has no url-length limit. Either part failing just drops that part. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017VbfqYGNpHuCb8d5mRVjzZ
1 parent c23d569 commit b0860f5

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

src/anna.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,33 @@ def _fetch_bigchat_intro(channel: str, ts: str) -> str:
9191
return ""
9292

9393

94+
def _fetch_permalink(channel: str, ts: str) -> str:
95+
"""원본 메시지 permalink를 클릭 시점에 조회한다. 실패해도 캘린더 제공은 막지 않는다."""
96+
if not channel or not ts:
97+
return ""
98+
try:
99+
web_client = WebClient(token=envs.SLACK_BOT_TOKEN)
100+
resp = web_client.chat_getPermalink(channel=channel, message_ts=ts)
101+
return resp["permalink"]
102+
except Exception as ex:
103+
logging.getLogger(__name__).warning(f"Failed to fetch permalink: {ex}")
104+
return ""
105+
106+
107+
def _build_calendar_description(channel: str, ts: str) -> str:
108+
"""gcal 본문과 같은 포맷: 맨 앞에 permalink, 그 아래 소개글 (ics는 길이 제한이 없어 전문)."""
109+
parts = []
110+
permalink = _fetch_permalink(channel, ts)
111+
if permalink:
112+
parts.append(f"슬랙에서 소개글 보기: {permalink}")
113+
intro = _fetch_bigchat_intro(channel, ts)
114+
if intro:
115+
parts.append(intro)
116+
return "\n\n".join(parts)
117+
118+
94119
def _load_bigchat_calendar_context(worksheet_id: int):
95-
"""ics 다운로드의 검증/조회 경로. 반환: (event, intro_text)"""
120+
"""ics 다운로드의 검증/조회 경로. 반환: (event, description)"""
96121
if not envs.ICS_TOKEN_SECRET:
97122
abort(404)
98123
channel = request.args.get("channel", "")
@@ -116,14 +141,14 @@ def _load_bigchat_calendar_context(worksheet_id: int):
116141
if not event:
117142
abort(404)
118143

119-
return event, _fetch_bigchat_intro(channel, ts)
144+
return event, _build_calendar_description(channel, ts)
120145

121146

122147
@flask_app.route("/bigchat/<int:worksheet_id>/event.ics", methods=["GET"])
123148
def bigchat_ics(worksheet_id: int):
124-
event, intro = _load_bigchat_calendar_context(worksheet_id)
149+
event, description = _load_bigchat_calendar_context(worksheet_id)
125150
return Response(
126-
to_ics(event, uid=f"bigchat-{worksheet_id}@ausg-anna", description=intro),
151+
to_ics(event, uid=f"bigchat-{worksheet_id}@ausg-anna", description=description),
127152
mimetype="text/calendar",
128153
headers={"Content-Disposition": 'attachment; filename="event.ics"'},
129154
)

0 commit comments

Comments
 (0)