Personal Telegram developer console for GitHub

fix: show approved provider errors in Telegram

davoodmehraban89 committed Oct 3, 2026 at 08:45 UTC 75c9e540192ae3b42931329035002a95819f7163
1 file changed +55 -6
src/bot.js
+55 -6
@@ -71,6 +71,34 @@ ${detail}
71 };
72 }
73
74 +function approvedActionFailedView(payload, error) {
75 + const reason = String(error?.message || 'GitHub operation failed');
76 + const permissionDenied = /403|resource not accessible by personal access token/i.test(reason);
77 + const repoId = payload?.input?.repoId;
78 + const runId = payload?.input?.runId;
79 + const fallback = Number.isSafeInteger(Number(repoId)) && Number.isSafeInteger(Number(runId))
80 + ? `run:${repoId}:${runId}`
81 + : 'menu:main';
82 +
83 + const detail = permissionDenied
84 + ? 'تأیید شما معتبر بود، اما GitHub درخواست را با خطای 403 رد کرد. دسترسی توکن فعلی برای GitHub Actions WRITE کافی نیست.'
85 + : 'تأیید شما معتبر بود، اما GitHub عملیات را موفق اعلام نکرد. وضعیت Run را بررسی کنید.';
86 +
87 + return {
88 + text:
89 +`⚠️ <b>اجرای عملیات در GitHub ناموفق بود</b>
90 +➖➖➖➖➖➖➖➖➖➖
91 +${detail}
92 +
93 +این تأیید یک‌بار مصرف شده و با همان دکمه دوباره اجرا نمی‌شود.`,
94 + reply_markup: {
95 + inline_keyboard: [
96 + [{ text: '↩️ بازگشت به Run', callback_data: fallback }]
97 + ]
98 + }
99 + };
100 +}
101 +
102 export class NexaDevBot {
103 constructor(env = {}) {
104 this.env = env;
@@ -177,12 +205,33 @@ export class NexaDevBot {
205 });
206
207 const sourceCallback = approvalSourceCallback(payload);
180 - const routed = await this.router.dispatchCallback(sourceCallback, {
181 - isOwner: true,
182 - approved: true
183 - });
184 - if (!routed || routed.requiresApproval || routed.denied) {
185 - throw new Error('Approved action could not be dispatched');
208 + let routed;
209 + try {
210 + routed = await this.router.dispatchCallback(sourceCallback, {
211 + isOwner: true,
212 + approved: true
213 + });
214 + if (!routed || routed.requiresApproval || routed.denied) {
215 + throw new Error('Approved action could not be dispatched');
216 + }
217 + } catch (error) {
218 + const view = approvedActionFailedView(payload, error);
219 + const res = await this.telegram.editMessageText(
220 + chatId,
221 + messageId,
222 + view.text,
223 + view.reply_markup
224 + );
225 + return {
226 + ok: false,
227 + approved: true,
228 + providerError: true,
229 + actionId: payload.actionId,
230 + error: error?.message || 'GitHub operation failed',
231 + callbackAnswered,
232 + edited: true,
233 + res
234 + };
235 }
236
237 const res = await this.telegram.editMessageText(