puregram icon indicating copy to clipboard operation
puregram copied to clipboard

Issue calling answerPreCheckoutQuery

Open culda opened this issue 2 years ago • 3 comments

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:

  1. send update to bot server
  2. call context.answerPreCheckoutQuery({ ok: true })

expected behavior

Expect the call to not throw an error

environment

package version
puregram 2.25.1
TypeScript 5

culda avatar Mar 06 '24 11:03 culda

Works when I invoke the method from the api object.

    telegram.api.answerPreCheckoutQuery({
      pre_checkout_query_id: context.id,
      ok: true,
    });

culda avatar Mar 06 '24 11:03 culda

have to ask a question: why exactly are you handling updates manually? just to be sure everything is going ok on your side

nitreojs avatar Mar 07 '24 13:03 nitreojs

bump?

nitreojs avatar Mar 28 '24 19:03 nitreojs