nitreojs / puregram

powerful and modern telegram bot api sdk for node.js and typescript 😁
https://puregram.cool
Do What The F*ck You Want To Public License
188 stars 10 forks source link

Issue calling answerPreCheckoutQuery #101

Closed culda closed 3 months ago

culda commented 8 months ago

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 commented 8 months ago

Works when I invoke the method from the api object.

    telegram.api.answerPreCheckoutQuery({
      pre_checkout_query_id: context.id,
      ok: true,
    });
nitreojs commented 8 months ago

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

nitreojs commented 7 months ago

bump?

nitreojs commented 3 months ago

i will close this issue as no further answer was provided, assuming the issue is not present anymore. feel free to reopen it if it happens again!