puregram
puregram copied to clipboard
Issue calling answerPreCheckoutQuery
the bug
I'm trying to handle pre_checkout_query updates and I have this code which throws an error
TypeError: Cannot read properties of undefined (reading 'telegram')
at answerPreCheckoutQuery (file:///var/task/src/functions/shopTelegramWebhook/handler.mjs:37707:21)
at handleUpdate (file:///var/task/src/functions/shopTelegramWebhook/handler.mjs:66424:11)
at Runtime.handler (file:///var/task/src/functions/shopTelegramWebhook/handler.mjs:66369:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Code:
async function handleUpdate({
update,
telegram,
}: {
update: TelegramUpdate;
telegram: Telegram;
}) {
const context = telegram.updates.handleUpdate(update);
if (context?.is("pre_checkout_query")) {
console.log(context.invoicePayload);
await context.answerPreCheckoutQuery({ ok: true });
}
}
Note the invoicePayload is correctly logged from the context.
steps to reproduce
steps to reproduce the behavior:
- send update to bot server
- call
context.answerPreCheckoutQuery({ ok: true })
expected behavior
Expect the call to not throw an error
environment
| package | version |
|---|---|
puregram |
2.25.1 |
TypeScript |
5 |
Works when I invoke the method from the api object.
telegram.api.answerPreCheckoutQuery({
pre_checkout_query_id: context.id,
ok: true,
});
have to ask a question: why exactly are you handling updates manually? just to be sure everything is going ok on your side
bump?