| 182 | * `offset > drainFence` after this call. |
| 183 | */ |
| 184 | export async function drainUpdates(): Promise<number> { |
| 185 | let highestUpdateId = -1; |
| 186 | // Keep fetching until we get an empty page (queue exhausted). |
| 187 | for (;;) { |
| 188 | const updates = await getUpdates(highestUpdateId + 1, 100); |
| 189 | if (updates.length === 0) break; |
| 190 | for (const u of updates) { |
| 191 | if (u.update_id > highestUpdateId) highestUpdateId = u.update_id; |
| 192 | } |
| 193 | } |
| 194 | return highestUpdateId; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Poll the bot's updates for a message FROM THE BOT in `chatId` after |