Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(plugins): expose translation configSchema + apply config changes live

dallascyclist897deaeb2c51
diff --git a/src/plugins/extensions/extensions.module.ts b/src/plugins/extensions/extensions.module.ts
index 2539eec0b..0d0a8089e 100644
--- a/src/plugins/extensions/extensions.module.ts
+++ b/src/plugins/extensions/extensions.module.ts
@@ -40,6 +40,37 @@ export class ExtensionsRegistrar implements OnModuleInit {
main: 'index.ts',
permissions: ['messages:send'],
sessions: ['*'],
+ // Exposed via GET /plugins so the dashboard renders an editable config form (URL + API key, etc.).
+ configSchema: {
+ type: 'object',
+ properties: {
+ libretranslateUrl: {
+ type: 'string',
+ title: 'LibreTranslate URL',
+ description:
+ 'Base URL of the LibreTranslate instance (e.g. http://libretranslate:7001 or https://libretranslate.com).',
+ default: 'http://localhost:7001',
+ required: true,
+ },
+ libretranslateApiKey: {
+ type: 'string',
+ title: 'LibreTranslate API key',
+ description:
+ 'Optional API key, if your LibreTranslate instance requires one (e.g. hosted libretranslate.com).',
+ secret: true,
+ },
+ timeoutMs: { type: 'number', title: 'Translate timeout (ms)', default: 5000 },
+ commandPrefix: { type: 'string', title: 'Command prefix', default: '/tr' },
+ minLength: { type: 'number', title: 'Min message length to translate', default: 2 },
+ maxLength: { type: 'number', title: 'Max message length to translate', default: 2000 },
+ denyReply: {
+ type: 'boolean',
+ title: 'Reply on denied commands',
+ description: "Reply with an 'admins only' message when a non-admin runs a restricted command.",
+ default: false,
+ },
+ },
+ },
};
this.pluginLoader.registerBuiltInPlugin(translationManifest, new TranslationPlugin());
diff --git a/src/plugins/extensions/translation/index.ts b/src/plugins/extensions/translation/index.ts
index c059f3c6a..6c006ecdf 100644
--- a/src/plugins/extensions/translation/index.ts
+++ b/src/plugins/extensions/translation/index.ts
@@ -36,8 +36,22 @@ export class TranslationPlugin implements IPlugin {
private coordinator: TranslationCoordinator | null = null;
onEnable(context: PluginContext): Promise<void> {
- const cfg = context.config;
+ this.coordinator = this.buildCoordinator(context);
+ context.registerHook('message:received', ctx => this.onMessage(context, ctx as HookContext<IncomingMessage>));
+ context.logger.log('Translation plugin enabled', { action: 'translation_enabled' });
+ return Promise.resolve();
+ }
+ onConfigChange(context: PluginContext): Promise<void> {
+ // Rebuild the coordinator so a config edit (e.g. a new LibreTranslate URL/key saved from the
+ // dashboard) takes effect immediately, without a disable/enable cycle.
+ this.coordinator = this.buildCoordinator(context);
+ context.logger.log('Translation plugin config updated', { action: 'translation_config_changed' });
+ return Promise.resolve();
+ }
+
+ private buildCoordinator(context: PluginContext): TranslationCoordinator {
+ const cfg = context.config;
const translator = new LibreTranslateClient({
url: readString(cfg, 'libretranslateUrl', 'http://localhost:7001'),
apiKey: readOptionalString(cfg, 'libretranslateApiKey'),
@@ -51,11 +65,7 @@ export class TranslationPlugin implements IPlugin {
maxLength: readNumber(cfg, 'maxLength', 2000),
denyReply: readBool(cfg, 'denyReply', false),
};
- this.coordinator = new TranslationCoordinator(translator, store, gateway, opts);
-
- context.registerHook('message:received', ctx => this.onMessage(context, ctx as HookContext<IncomingMessage>));
- context.logger.log('Translation plugin enabled', { action: 'translation_enabled' });
- return Promise.resolve();
+ return new TranslationCoordinator(translator, store, gateway, opts);
}
onDisable(context: PluginContext): Promise<void> {