mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 06:30:45 +08:00
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
import { TokenBotController } from '../shared/token-bot-controller.mjs';
|
|
import {
|
|
deriveTelegramBotIdentity,
|
|
maskTelegramBotId,
|
|
normalizeTelegramAccessPolicy,
|
|
} from './config-store.mjs';
|
|
import { inspectTelegramToken } from './telegram-api.mjs';
|
|
import { TELEGRAM_DESCRIPTOR } from './telegram-bridge.mjs';
|
|
|
|
export class TelegramController extends TokenBotController {
|
|
#configStore;
|
|
|
|
constructor(options) {
|
|
super({
|
|
...options,
|
|
descriptor: TELEGRAM_DESCRIPTOR,
|
|
inspectToken: options.inspectToken ?? inspectTelegramToken,
|
|
deriveIdentity: deriveTelegramBotIdentity,
|
|
maskPlatformId: maskTelegramBotId,
|
|
});
|
|
this.#configStore = options.configStore;
|
|
}
|
|
|
|
status() {
|
|
const snapshot = super.status();
|
|
return {
|
|
...snapshot,
|
|
bots: snapshot.bots.map((bot) => {
|
|
const config = this.#configStore.get(bot.botId);
|
|
const accessPolicy = normalizeTelegramAccessPolicy(config ?? {});
|
|
return { ...bot, accessPolicy };
|
|
}),
|
|
};
|
|
}
|
|
|
|
async setAccessPolicy(botId, value) {
|
|
const accessPolicy = normalizeTelegramAccessPolicy(value);
|
|
return this.updateBotConfig(botId, (config) => ({ ...config, ...accessPolicy }));
|
|
}
|
|
}
|