mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:48:27 +00:00
Handle Telegram poll vote updates for agent context
This commit is contained in:
35
src/telegram/poll-vote-cache.ts
Normal file
35
src/telegram/poll-vote-cache.ts
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user