Personal Telegram developer console for GitHub
refactor: route github through plugin kernel
davoodmehraban89 committed
Oct 3, 2026 at 01:37 UTC
d628a4ed0b07dfa4c748b6161515565b1eef3073
1 file changed
+61
-6
src/bot.js
+61
-6
@@ -1,6 +1,11 @@
1
import { TelegramClient } from './telegram.js';
2
import { GitHubService } from './github.js';
3
import { MenuManager } from './menu.js';
4
+import { PluginRegistry } from './core/plugin-registry.js';
5
+import { ActionPolicy } from './core/action-policy.js';
6
+import { AuditLogger } from './core/audit.js';
7
+import { PluginRouter } from './core/router.js';
8
+import { createGitHubPlugin } from './plugins/github/plugin.js';
9
10
export class NexaDevBot {
11
constructor(env = {}) {
@@ -8,10 +13,31 @@ export class NexaDevBot {
13
this.telegram = new TelegramClient(env.TELEGRAM_BOT_TOKEN || '');
14
this.github = new GitHubService(env.GITHUB_TOKEN || '', env.GITHUB_OWNER || 'davoodmehraban89');
15
this.menu = new MenuManager(this.github);
16
+
17
+ this.githubPlugin = createGitHubPlugin({
18
+ github: this.github,
19
+ menu: this.menu
20
+ });
21
+ this.registry = new PluginRegistry([this.githubPlugin]);
22
+ this.policy = new ActionPolicy();
23
+ this.audit = new AuditLogger({
24
+ secrets: [
25
+ env.TELEGRAM_BOT_TOKEN,
26
+ env.TELEGRAM_WEBHOOK_SECRET,
27
+ env.GITHUB_TOKEN
28
+ ]
29
+ });
30
+ this.router = new PluginRouter({
31
+ registry: this.registry,
32
+ policy: this.policy,
33
+ audit: this.audit
34
+ });
35
}
36
37
/**
14
- * Process incoming Telegram webhook update
38
+ * Process incoming Telegram webhook update.
39
+ * Owner authorization is enforced at the Worker boundary before this bot is
40
+ * constructed, so routed actions use an owner-authorized internal context.
41
*/
42
async handleUpdate(update) {
43
if (!update) return { ok: false, error: 'Empty update' };
@@ -50,8 +76,29 @@ export class NexaDevBot {
76
}
77
78
try {
53
- // Render requested view
54
- const view = await this.menu.renderByCallback(data);
79
+ // GitHub callbacks pass through the plugin policy boundary. Non-GitHub
80
+ // callbacks remain on the existing compatibility router in Foundation v1.
81
+ const routed = await this.router.dispatchCallback(data, { isOwner: true });
82
+ if (routed?.requiresApproval) {
83
+ return {
84
+ ok: false,
85
+ approvalRequired: true,
86
+ actionId: routed.actionId,
87
+ risk: routed.risk,
88
+ callbackAnswered
89
+ };
90
+ }
91
+ if (routed?.denied) {
92
+ return {
93
+ ok: false,
94
+ denied: true,
95
+ actionId: routed.actionId,
96
+ reason: routed.reason,
97
+ callbackAnswered
98
+ };
99
+ }
100
+
101
+ const view = routed || await this.menu.renderByCallback(data);
102
103
// Edit the existing message in-place to prevent chat flooding
104
const res = await this.telegram.editMessageText(
@@ -84,10 +131,18 @@ export class NexaDevBot {
131
return { ok: true, command: 'start', res };
132
}
133
87
- // Legacy or shortcut command: /repos
134
+ // GitHub shortcut command routed through the plugin kernel.
135
if (text === '/repos') {
89
- const view = await this.menu.getReposListView();
90
- const res = await this.telegram.sendMessage(chatId, view.text, view.reply_markup);
136
+ const routed = await this.router.dispatchCommand(text, { isOwner: true });
137
+ if (routed?.requiresApproval || routed?.denied || !routed) {
138
+ return {
139
+ ok: false,
140
+ command: 'repos',
141
+ error: routed?.reason || 'GitHub repository route unavailable'
142
+ };
143
+ }
144
+
145
+ const res = await this.telegram.sendMessage(chatId, routed.text, routed.reply_markup);
146
return { ok: true, command: 'repos', res };
147
}
148