Handle Telegram poll vote updates for agent context

This commit is contained in:
Krish
2026-02-16 21:19:54 +05:30
committed by Peter Steinberger
parent 5cbfaf5cc7
commit 0a02b91638
6 changed files with 139 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
const TTL_MS = 24 * 60 * 60 * 1000;
export type TelegramSentPoll = {
pollId: string;
chatId: string;
question: string;
options: string[];
accountId?: string;
createdAt: number;
};
const pollById = new Map<string, TelegramSentPoll>();
function cleanupExpired() {
const now = Date.now();
for (const [pollId, poll] of pollById) {
if (now - poll.createdAt > TTL_MS) {
pollById.delete(pollId);
}
}
}
export function recordSentPoll(poll: Omit<TelegramSentPoll, "createdAt">) {
cleanupExpired();
pollById.set(poll.pollId, { ...poll, createdAt: Date.now() });
}
export function getSentPoll(pollId: string): TelegramSentPoll | undefined {
cleanupExpired();
return pollById.get(pollId);
}
export function clearSentPollCache() {
pollById.clear();
}