Personal Telegram developer console for GitHub
fix: render workspace-aware callback recovery
davoodmehraban89 committed
Oct 4, 2026 at 07:32 UTC
34d4a4757532c6b631785703e855e1a7d40db714
1 file changed
+77
src/core/callback-failure-view.js
new
+77
@@ -0,0 +1,77 @@
1
+const WORKSPACE_CALLBACK = /^(?:ws|wfile|wtext|wmsg|wdiff|wready|wcancel):([A-Za-z0-9_-]{10})$/;
2
+
3
+function legacyFailureView(data, error) {
4
+ const reason = String(error?.message || 'Provider read failed');
5
+ const permissionDenied = /403|resource not accessible by personal access token/i.test(reason);
6
+ const repoMatch = String(data || '').match(/^[^:]+:(\d+)/);
7
+ const fallback = repoMatch ? `repo:${repoMatch[1]}` : 'menu:main';
8
+ const isIssues = String(data || '').startsWith('issues:');
9
+ const detail = permissionDenied
10
+ ? isIssues
11
+ ? 'GitHub درخواست Issues را با خطای 403 رد کرد. در Fine-grained token، مجوز Repository permissions → Issues را روی Read قرار دهید.'
12
+ : 'GitHub این درخواست خواندنی را با خطای 403 رد کرد. مجوز Read مربوط به این بخش در توکن فعلی کافی نیست.'
13
+ : 'دریافت اطلاعات از سرویس با خطا مواجه شد. هیچ تغییری انجام نشد.';
14
+
15
+ return {
16
+ text:
17
+`⚠️ <b>دریافت اطلاعات با خطا مواجه شد</b>
18
+➖➖➖➖➖➖➖➖➖➖
19
+${detail}
20
+
21
+این خطا هیچ عملیات تغییردهندهای اجرا نکرد.`,
22
+ reply_markup: { inline_keyboard: [[{ text: repoMatch ? '↩️ بازگشت به پروژه' : '↩️ منوی اصلی', callback_data: fallback }]] },
23
+ validationError: false
24
+ };
25
+}
26
+
27
+export async function buildCallbackFailureView({ data, error, ownerId, workspaces } = {}) {
28
+ const callback = String(data || '');
29
+ const reason = String(error?.message || 'Provider read failed');
30
+ const match = callback.match(WORKSPACE_CALLBACK);
31
+ if (!match) return legacyFailureView(callback, error);
32
+
33
+ const workspaceId = match[1];
34
+ let workspace = null;
35
+ if (ownerId !== undefined && ownerId !== null && typeof workspaces?.getWorkspace === 'function') {
36
+ try {
37
+ workspace = await workspaces.getWorkspace({ ownerId: String(ownerId), workspaceId });
38
+ } catch {
39
+ // Recovery must remain usable even if durable context lookup itself fails.
40
+ }
41
+ }
42
+
43
+ const repoId = Number(workspace?.repoId);
44
+ const hasRepo = Number.isSafeInteger(repoId);
45
+ const missingCommitMessage = /^Commit message is required$/i.test(reason);
46
+ const longCommitMessage = /^Commit message must be 120 characters or fewer$/i.test(reason);
47
+ const noDraftChange = /^No draft change to commit$/i.test(reason);
48
+ const validationError = missingCommitMessage || longCommitMessage || noDraftChange;
49
+
50
+ let title = '⚠️ <b>عملیات Workspace متوقف شد</b>';
51
+ let detail = 'Workspace و Draft شما حذف نشدهاند. میتوانید دوباره تلاش کنید یا به Draft برگردید.';
52
+ if (missingCommitMessage) {
53
+ title = '✍️ <b>پیام Commit لازم است</b>';
54
+ detail = 'قبل از «آماده Commit»، یک پیام Commit ثبت کنید. Draft فعلی محفوظ است و هیچ تغییری در GitHub انجام نشده است.';
55
+ } else if (longCommitMessage) {
56
+ title = '✍️ <b>پیام Commit بیش از حد طولانی است</b>';
57
+ detail = 'پیام Commit باید حداکثر 120 کاراکتر باشد. Draft فعلی محفوظ است و هیچ تغییری در GitHub انجام نشده است.';
58
+ } else if (noDraftChange) {
59
+ title = '📝 <b>تغییری برای Commit وجود ندارد</b>';
60
+ detail = 'محتوای Draft با نسخهٔ اصلی یکسان است. ابتدا Draft را تغییر دهید؛ هیچ تغییری در GitHub انجام نشده است.';
61
+ }
62
+
63
+ const rows = [];
64
+ if (missingCommitMessage || longCommitMessage) {
65
+ rows.push([{ text: '✍️ ثبت پیام Commit', callback_data: `wmsg:${workspaceId}` }]);
66
+ }
67
+ rows.push([{ text: '🔄 تلاش مجدد', callback_data: callback }]);
68
+ rows.push([{ text: '📝 ادامه Draft', callback_data: `ws:${workspaceId}` }]);
69
+ if (hasRepo) rows.push([{ text: '📦 بازگشت به پروژه', callback_data: `repo:${repoId}` }]);
70
+ rows.push([{ text: '🏠 منوی اصلی', callback_data: 'menu:main' }]);
71
+
72
+ return {
73
+ text: `${title}\n➖➖➖➖➖➖➖➖➖➖\n${detail}`,
74
+ reply_markup: { inline_keyboard: rows },
75
+ validationError
76
+ };
77
+}