Personal Telegram developer console for GitHub
feat: add github plugin adapter
davoodmehraban89 committed
Oct 3, 2026 at 01:34 UTC
c9aed93bc1a3bd8ac047a3639722633bcd9c624e
1 file changed
+49
src/plugins/github/plugin.js
new
+49
@@ -0,0 +1,49 @@
1
+import { githubPluginManifest } from './manifest.js';
2
+
3
+const CALLBACK_ACTIONS = Object.freeze([
4
+ ['repo:', 'github.repo.detail'],
5
+ ['files:', 'github.files.list'],
6
+ ['tree:', 'github.tree.read'],
7
+ ['blob:', 'github.blob.read'],
8
+ ['pr:', 'github.pr.list'],
9
+ ['commits:', 'github.commits.list'],
10
+ ['status:', 'github.status.read']
11
+]);
12
+
13
+function resolveCallbackAction(data) {
14
+ const value = String(data || '');
15
+ if (value === 'menu:repos') return 'github.repos.list';
16
+
17
+ for (const [prefix, actionId] of CALLBACK_ACTIONS) {
18
+ if (value.startsWith(prefix)) return actionId;
19
+ }
20
+
21
+ return null;
22
+}
23
+
24
+export function createGitHubPlugin({ github, menu } = {}) {
25
+ if (!github) throw new Error('GitHub plugin requires github service');
26
+ if (!menu) throw new Error('GitHub plugin requires menu manager');
27
+
28
+ return {
29
+ manifest: githubPluginManifest,
30
+
31
+ resolveCommand(command) {
32
+ if (command !== '/repos') return null;
33
+ return {
34
+ actionId: 'github.repos.list',
35
+ execute: () => menu.getReposListView()
36
+ };
37
+ },
38
+
39
+ resolveCallback(data) {
40
+ const actionId = resolveCallbackAction(data);
41
+ if (!actionId) return null;
42
+
43
+ return {
44
+ actionId,
45
+ execute: () => menu.renderByCallback(data)
46
+ };
47
+ }
48
+ };
49
+}