fix: make dave telegram alerts conversational
This commit is contained in:
@@ -146,6 +146,74 @@ test('Telegram conversation delivery strips visible markdown and splits large AI
|
||||
assert.equal('reply_to_message_id' in sent[1].body, false);
|
||||
});
|
||||
|
||||
test('Telegram conversation defaults to short human-sized chat chunks', async () => {
|
||||
const alerter = new TelegramAlerter({ botToken: 'test-token', chatId: '42' });
|
||||
const requests = [];
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = async (url, options = {}) => {
|
||||
requests.push({ url, body: options.body ? JSON.parse(options.body) : null });
|
||||
return { ok: true, json: async () => ({ ok: true, result: { message_id: requests.length } }) };
|
||||
};
|
||||
|
||||
try {
|
||||
const text = [
|
||||
'Das ist die erste kurze Einschaetzung. Sie soll separat lesbar bleiben und nicht wie ein Bericht wirken.',
|
||||
'Hier kommt mehr Kontext, aber auch dieser Kontext bleibt in natuerlichen Chat-Haeppchen. '.repeat(8),
|
||||
'Soll ich die Details danach sauber aufdrillen?',
|
||||
].join('\n\n');
|
||||
const result = await alerter.sendConversation(text, { delayMs: 0 });
|
||||
assert.equal(result.ok, true);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
|
||||
const sent = requests.filter(request => request.url.includes('/sendMessage'));
|
||||
assert.ok(sent.length >= 3);
|
||||
for (const message of sent) {
|
||||
assert.ok(message.body.text.length <= 420, `message too long: ${message.body.text.length}`);
|
||||
assert.equal('parse_mode' in message.body, false);
|
||||
}
|
||||
});
|
||||
|
||||
test('Telegram tiered fallback alert is sent as conversational DAVE messages', async () => {
|
||||
const alerter = new TelegramAlerter({ botToken: 'test-token', chatId: '42' });
|
||||
const requests = [];
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = async (url, options = {}) => {
|
||||
requests.push({ url, body: options.body ? JSON.parse(options.body) : null });
|
||||
return { ok: true, json: async () => ({ ok: true, result: { message_id: requests.length } }) };
|
||||
};
|
||||
const memory = {
|
||||
getAlertedSignals: () => ({}),
|
||||
markAsAlerted: () => {},
|
||||
};
|
||||
const delta = {
|
||||
summary: { totalChanges: 1, criticalChanges: 1, direction: 'mixed' },
|
||||
signals: {
|
||||
new: [{
|
||||
key: 'source_degradation',
|
||||
severity: 'critical',
|
||||
label: '7 additional sources failing',
|
||||
direction: 'up',
|
||||
}],
|
||||
escalated: [],
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
const sent = await alerter.evaluateAndAlert(null, delta, memory, { language: 'de', delayMs: 0 });
|
||||
assert.equal(sent, true);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
|
||||
const texts = requests.filter(request => request.url.includes('/sendMessage')).map(request => request.body.text);
|
||||
assert.ok(texts.length >= 2);
|
||||
assert.match(texts[0], /^\[DAVE \/\/ HINWEIS\]/);
|
||||
assert.doesNotMatch(texts.join('\n'), /CRUCIX ROUTINE|Confidence:|Direction:|Cross-correlation:|Werkzeuge|Tools used/);
|
||||
for (const text of texts) assert.ok(text.length <= 380, `alert chunk too long: ${text.length}`);
|
||||
});
|
||||
|
||||
test('Telegram OSINT extraction excludes private AI chat messages', () => {
|
||||
const messages = extractBotChannelMessages([
|
||||
{ update_id: 1, message: { text: 'private question', chat: { id: 42, type: 'private' } } },
|
||||
|
||||
Reference in New Issue
Block a user