fix: plugin bot user + await plugin detection before session scan
- Add EnsureBotUser on plugin activate (fixes 'Unable to find user' error) - Accept bot_user_id in create session request - Await plugin health check before starting session monitor (prevents race where sessions detect before plugin flag is set) - Plugin now creates custom_livestatus posts with proper bot user
This commit is contained in:
@@ -60,13 +60,24 @@ PluginClient.prototype.isHealthy = function () {
|
||||
* @param {string} agentId
|
||||
* @returns {Promise<string>} post_id
|
||||
*/
|
||||
/**
|
||||
* @param {string} botUserId - Mattermost bot user ID to author the post
|
||||
*/
|
||||
PluginClient.prototype.setBotUserId = function (botUserId) {
|
||||
this.botUserId = botUserId;
|
||||
};
|
||||
|
||||
PluginClient.prototype.createSession = function (sessionKey, channelId, rootId, agentId) {
|
||||
return this._request('POST', '/api/v1/sessions', {
|
||||
var body = {
|
||||
session_key: sessionKey,
|
||||
channel_id: channelId,
|
||||
root_id: rootId || '',
|
||||
agent_id: agentId,
|
||||
}).then(function (data) {
|
||||
};
|
||||
if (this.botUserId) {
|
||||
body.bot_user_id = this.botUserId;
|
||||
}
|
||||
return this._request('POST', '/api/v1/sessions', body).then(function (data) {
|
||||
return data.post_id;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -171,13 +171,17 @@ async function startDaemon() {
|
||||
logger: logger.child({ module: 'plugin-client' }),
|
||||
});
|
||||
|
||||
// Initial plugin detection
|
||||
pluginClient.isHealthy().then(function (healthy) {
|
||||
// Initial plugin detection (awaited before monitor starts — see below)
|
||||
try {
|
||||
var healthy = await pluginClient.isHealthy();
|
||||
usePlugin = healthy;
|
||||
logger.info({ usePlugin, url: config.plugin.url }, healthy
|
||||
? 'Plugin detected — using WebSocket rendering mode'
|
||||
: 'Plugin not available — using REST API fallback');
|
||||
});
|
||||
} catch (_detectErr) {
|
||||
usePlugin = false;
|
||||
logger.warn('Plugin detection failed — using REST API fallback');
|
||||
}
|
||||
|
||||
// Periodic re-detection
|
||||
setInterval(function () {
|
||||
|
||||
Reference in New Issue
Block a user