edisonchee / slimbot

Telegram Bot API for Node.js
MIT License
223 stars 37 forks source link

answerPreCheckoutQuery #50

Open iwdok opened 3 years ago

iwdok commented 3 years ago

I get an error when trying to respond to an event "pre_checkout_query".

My Code

slimbot.on('pre_checkout_query', async payment => {
    console.log(payment);
    if (payment.invoice_payload.includes('pay')){
        let user = await database.select('*').from('users').where({telegram_id: payment.from.id});
        if (user.length === 0){
            slimbot.answerPreCheckoutQuery(payment.id, true);
        } else {
            slimbot.answerPreCheckoutQuery(payment.id, false, 'Ошибка оплаты, обратитьсе в поддержку бота');
        }
    } else {
        slimbot.answerPreCheckoutQuery(payment.id, false, 'Ошибка оплаты, обратитьсе в поддержку бота');
    }
});

My Error

D:\Рабочий стол\auto-bot\node_modules\slimbot\src\telegram.js:1241
    return this._request('answerShippingQuery', params, callback);
                                                        ^

ReferenceError: callback is not defined
    at Slimbot.answerPreCheckoutQuery (D:\Рабочий стол\auto-bot\node_modules\slimbot\src\telegram.js:1241:57)
    at Slimbot.<anonymous> (file:///D:/%D0%A0%D0%B0%D0%B1%D0%BE%D1%87%D0%B8%D0%B9%20%D1%81%D1%82%D0%BE%D0%BB/auto-bot/app.js:69:21)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

And I see strange code in your library, maybe it's a typo. Or am I misapplying your library

answerPreCheckoutQuery(preCheckoutQueryId, ok, errorMessage) {
    let params = {
      pre_checkout_query_id: preCheckoutQueryId,
      ok: ok,
      error_message: errorMessage
    };

    return this._request('answerShippingQuery', params, callback); // On this line answer is not answerPreCheckoutQuery
  }