fix(bot): harden webhook processing and purchase defaults

This commit is contained in:
2026-03-11 03:25:16 +04:00
parent dc09a07e21
commit ac5f11f8da
12 changed files with 674 additions and 148 deletions

View File

@@ -0,0 +1,55 @@
import type { Context } from 'grammy'
const TYPING_REFRESH_INTERVAL_MS = 4_000
export interface ActiveChatAction {
stop(): void
}
export function startTypingIndicator(ctx: Context): ActiveChatAction {
const chatId = ctx.chat?.id
if (!chatId) {
return {
stop() {}
}
}
const messageThreadId =
ctx.msg && 'message_thread_id' in ctx.msg ? ctx.msg.message_thread_id : undefined
let active = true
const sendTypingAction = async () => {
if (!active) {
return
}
const options =
messageThreadId !== undefined
? {
message_thread_id: messageThreadId
}
: undefined
try {
await ctx.api.sendChatAction(chatId, 'typing', options)
} catch {}
}
void sendTypingAction()
const interval = setInterval(() => {
void sendTypingAction()
}, TYPING_REFRESH_INTERVAL_MS)
if (typeof interval.unref === 'function') {
interval.unref()
}
return {
stop() {
active = false
clearInterval(interval)
}
}
}