Personal Telegram developer console for GitHub
feat: add persistent quick menu and focused paste input
davoodmehraban89 committed
Oct 4, 2026 at 06:58 UTC
9e8efa4157899e5b224b6689213e5d5af0a9e344
1 file changed
+60
-1
src/bot.js
+60
-1
@@ -11,12 +11,40 @@ import { PluginRouter } from './core/router.js';
11
import { createGitHubPlugin } from './plugins/github/plugin.js';
12
13
const INTENT_ID_PATTERN = /^[A-Za-z0-9_-]{8}$/;
14
+const QUICK_MENU = Object.freeze({
15
+ '🏠 منوی اصلی': 'main',
16
+ '📁 پروژهها': 'repos',
17
+ '📊 وضعیت': 'status',
18
+ '🔧 ابزارها': 'tools',
19
+ '🔐 امنیت': 'security'
20
+});
21
const escapeHtml = value => String(value ?? '')
22
.replaceAll('&', '&')
23
.replaceAll('<', '<')
24
.replaceAll('>', '>')
25
.replaceAll('"', '"');
26
27
+function persistentQuickMenuMarkup() {
28
+ return {
29
+ keyboard: [
30
+ [{ text: '🏠 منوی اصلی' }, { text: '📁 پروژهها' }],
31
+ [{ text: '📊 وضعیت' }, { text: '🔧 ابزارها' }],
32
+ [{ text: '🔐 امنیت' }]
33
+ ],
34
+ resize_keyboard: true,
35
+ is_persistent: true,
36
+ input_field_placeholder: 'Nexa Dev — یک گزینه را انتخاب کنید'
37
+ };
38
+}
39
+
40
+function focusedCodeInputMarkup() {
41
+ return {
42
+ force_reply: true,
43
+ selective: true,
44
+ input_field_placeholder: 'کد یا متن را اینجا Paste کنید…'
45
+ };
46
+}
47
+
48
function approvalSourceCallback(payload = {}) {
49
const repoId = payload.input?.repoId;
50
if (!Number.isSafeInteger(Number(repoId))) throw new Error('Approval input is invalid');
@@ -241,6 +269,10 @@ export class NexaDevBot {
269
if (routed?.denied) return { ok: false, denied: true, actionId: routed.actionId, reason: routed.reason, callbackAnswered };
270
271
const view = routed || await this.menu.renderByCallback(data);
272
+ if (data.startsWith('wtext:') && routed) {
273
+ const res = await this.telegram.sendMessage(chatId, view.text, focusedCodeInputMarkup());
274
+ return { ok: true, inputPrompt: true, callbackAnswered, sent: true, res };
275
+ }
276
const res = await this.telegram.editMessageText(chatId, messageId, view.text, view.reply_markup);
277
return { ok: true, edited: true, callbackAnswered, res };
278
} catch (err) {
@@ -265,9 +297,36 @@ export class NexaDevBot {
297
if (!chatId) return { ok: false, error: 'Missing chat_id' };
298
299
if (text === '/start' || text === '/menu' || text.startsWith('/start')) {
300
+ const quickMenuRes = await this.telegram.sendMessage(
301
+ chatId,
302
+ '⌨️ <b>منوی سریع Nexa Dev فعال شد</b>\nاین منو پایین صفحه میماند و از هر بخش قابل استفاده است.',
303
+ persistentQuickMenuMarkup()
304
+ );
305
const view = this.menu.getMainMenuView();
306
const res = await this.telegram.sendMessage(chatId, view.text, view.reply_markup);
270
- return { ok: true, command: 'start', res };
307
+ return { ok: true, command: 'start', persistentMenu: true, quickMenuRes, res };
308
+ }
309
+
310
+ const quickMenu = QUICK_MENU[text];
311
+ if (quickMenu) {
312
+ let view;
313
+ if (quickMenu === 'main') {
314
+ view = this.menu.getMainMenuView();
315
+ } else if (quickMenu === 'repos') {
316
+ const routed = await this.router.dispatchCommand('/repos', { isOwner: true });
317
+ if (routed?.requiresApproval || routed?.denied || !routed) {
318
+ return { ok: false, quickMenu, error: routed?.reason || 'GitHub repository route unavailable' };
319
+ }
320
+ view = routed;
321
+ } else if (quickMenu === 'status') {
322
+ view = this.menu.getServiceStatusView();
323
+ } else if (quickMenu === 'tools') {
324
+ view = this.menu.getToolsView();
325
+ } else {
326
+ view = this.menu.getSecurityView();
327
+ }
328
+ const res = await this.telegram.sendMessage(chatId, view.text, view.reply_markup);
329
+ return { ok: true, quickMenu, res };
330
}
331
332
if (text === '/repos') {