n8n
Version:
n8n Workflow Automation Tool
62 lines • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTelegramBridgeExecutionContext = createTelegramBridgeExecutionContext;
exports.createTelegramResumeExecutionContext = createTelegramResumeExecutionContext;
exports.startTelegramTypingIndicator = startTelegramTypingIndicator;
const TELEGRAM_TYPING_REFRESH_MS = 4000;
const TELEGRAM_TYPING_MAX_LIFETIME_MS = 10 * 60 * 1000;
function createTelegramBridgeExecutionContext(params) {
return {
platformAgentContext: {},
statusHandle: startTelegramTypingIndicator(params.thread, {
logger: params.logger,
agentId: params.agentId,
}),
};
}
function createTelegramResumeExecutionContext(params) {
return {
statusHandle: startTelegramTypingIndicator(params.thread, {
logger: params.logger,
agentId: params.agentId,
}),
};
}
function startTelegramTypingIndicator(thread, options) {
let failedStreak = false;
let inFlight = null;
const sendTyping = () => {
if (inFlight)
return;
inFlight = thread
.startTyping()
.then(() => {
failedStreak = false;
})
.catch((error) => {
const log = failedStreak ? options.logger.debug : options.logger.warn;
failedStreak = true;
log.call(options.logger, '[AgentChatBridge] Failed to send Telegram typing indicator', {
agentId: options.agentId,
threadId: thread.id,
error: error instanceof Error ? error.message : String(error),
});
})
.finally(() => {
inFlight = null;
});
};
sendTyping();
const interval = setInterval(sendTyping, TELEGRAM_TYPING_REFRESH_MS);
interval.unref();
const maxLifetime = setTimeout(() => clearInterval(interval), TELEGRAM_TYPING_MAX_LIFETIME_MS);
maxLifetime.unref();
return {
clearBeforeResponse: async () => {
clearInterval(interval);
clearTimeout(maxLifetime);
await inFlight;
},
};
}
//# sourceMappingURL=telegram-bridge-behavior.js.map