Personal Telegram developer console for GitHub
feat: route pending Telegram documents into workspace drafts
davoodmehraban89 committed
Oct 3, 2026 at 14:41 UTC
86e57027f1e4bd06d4033a9167a2c1342df7387e
1 file changed
+42
-2
src/bot.js
+42
-2
@@ -289,8 +289,48 @@ export class NexaDevBot {
289
if (ownerId !== undefined && ownerId !== null && this.workspaceStore.isConfigured()) {
290
const pending = await this.workspaceStore.getPendingInput({ ownerId: String(ownerId) });
291
if (pending) {
292
+ let payload = { pending, text: rawText };
293
+ if (pending.mode === 'draft_file') {
294
+ const document = message.document;
295
+ if (!document?.file_id) {
296
+ const view = {
297
+ text: '📎 <b>یک فایل متنی ارسال کنید</b>\nاین Workspace در حالت بارگذاری فایل است. فایل باید UTF-8 معتبر و حداکثر 12,000 بایت باشد.',
298
+ reply_markup: { inline_keyboard: [[{ text: '↩️ بازگشت به Draft', callback_data: `ws:${pending.workspaceId}` }]] }
299
+ };
300
+ const res = await this.telegram.sendMessage(chatId, view.text, view.reply_markup);
301
+ return { ok: true, workspaceInput: true, inputRequired: 'document', res };
302
+ }
303
+ if (Number.isFinite(Number(document.file_size)) && Number(document.file_size) > 12000) {
304
+ const view = {
305
+ text: '⚠️ <b>فایل پذیرفته نشد</b>\nحجم فایل بیشتر از سقف 12,000 بایت است. Draft تغییر نکرد؛ یک فایل کوچکتر ارسال کنید.',
306
+ reply_markup: { inline_keyboard: [[{ text: '↩️ بازگشت به Draft', callback_data: `ws:${pending.workspaceId}` }]] }
307
+ };
308
+ const res = await this.telegram.sendMessage(chatId, view.text, view.reply_markup);
309
+ return { ok: false, workspaceInput: true, inputRejected: true, error: 'Telegram file exceeds 12000 byte size limit', res };
310
+ }
311
+ let downloaded;
312
+ try {
313
+ downloaded = await this.telegram.downloadTextFile(document.file_id, { maxBytes: 12000 });
314
+ } catch (error) {
315
+ const view = {
316
+ text: `⚠️ <b>فایل پذیرفته نشد</b>\n${escapeHtml(error?.message || 'Telegram file download failed')}\n\nDraft تغییر نکرد و میتوانید فایل دیگری ارسال کنید.`,
317
+ reply_markup: { inline_keyboard: [[{ text: '↩️ بازگشت به Draft', callback_data: `ws:${pending.workspaceId}` }]] }
318
+ };
319
+ const res = await this.telegram.sendMessage(chatId, view.text, view.reply_markup);
320
+ return { ok: false, workspaceInput: true, inputRejected: true, error: error?.message || 'Telegram file download failed', res };
321
+ }
322
+ payload = {
323
+ pending,
324
+ file: {
325
+ name: String(document.file_name || 'uploaded.txt'),
326
+ text: downloaded.text,
327
+ byteLength: downloaded.byteLength
328
+ }
329
+ };
330
+ }
331
+
332
const routed = await this.router.dispatchMessage(
293
- { pending, text: rawText },
333
+ payload,
334
{ isOwner: true, ownerId: String(ownerId) }
335
);
336
if (routed?.requiresApproval || routed?.denied || !routed) {
@@ -311,4 +351,4 @@ export class NexaDevBot {
351
const res = await this.telegram.sendMessage(chatId, view.text, view.reply_markup);
352
return { ok: true, default: true, res };
353
}
314
-}
354
+}
\ No newline at end of file