Closed mikececco closed 1 month ago
Hi. You need to use the path /YOUR_BOT_TOKEN
for the webhook (as I can see you are using /webhook
), if you haven't changed the path here.
Hi. You need to use the path
/YOUR_BOT_TOKEN
for the webhook (as I can see you are using/webhook
), if you haven't changed the path here.
I did change it to that path now, as webhook URL I have set my bot token as endpoint (?) What do I set as webhook url?
I think it does not matter as long as webhook url finishes with /webhook...no? I did set the webhook manually as
await bot.api.setWebhook(config.BOT_WEBHOOK, {
allowed_updates: config.BOT_ALLOWED_UPDATES,
});
is giving me Error occurred: HttpError: Network request for 'setWebhook' failed!
What did you set in BOT_WEBHOOK
? It should be something like
https://vocal-sensible-hippo.ngrok-free.app/YOUR_BOT_TOKEN
or
https://vocal-sensible-hippo.ngrok-free.app/webhook
(if you changed the path here to /webhook
)
What did you set in
BOT_WEBHOOK
? It should be something likehttps://vocal-sensible-hippo.ngrok-free.app/YOUR_BOT_TOKEN
orhttps://vocal-sensible-hippo.ngrok-free.app/webhook
(if you changed the path here to/webhook
)
The second one
{
"ok": true,
["result"](https://api.telegram.org/bot.../getWebhookInfo): {
"url": ["https://vocal-sensible-hippo.ngrok-free.app/webhook"](https://vocal-sensible-hippo.ngrok-free.app/webhook),
"has_custom_certificate": false,
"pending_update_count": 1,
"last_error_date": 1715693432,
"last_error_message": "Wrong response from the webhook: 404 Not Found",
"max_connections": 40,
"ip_address": "18.158.249.75",
["allowed_updates"](https://api.telegram.org/bot...../getWebhookInfo): [
"message",
"callback_query"
]
}
}
Wrong response from the webhook: 404 Not Found
Looks like the /webhook
path doesn't exist for some reason?
(Also, please revoke your bot token using https://t.me/BotFather, it's leaked in edit history)
Wrong response from the webhook: 404 Not Found
Looks like the
/webhook
path doesn't exist for some reason?
Webhook endpoint exists, if I return like: server.post("/endpoint", () => ({ status: true }));
it works
if I return like:
server.post("/endpoint", () => ({ status: true }));
it works
Are you checking through ngrok or using 127.0.0.1? Maybe some tunneling issue?
if I return like:
server.post("/endpoint", () => ({ status: true }));
it works Are you checking through ngrok or using 127.0.0.1? Maybe some tunneling issue?
Through ngrok. I am also getting Error occurred: HttpError: Network request for 'setWebhook' failed!
if I dont comment that code. Might be something related to bot instance?
Error occurred: HttpError: Network request for 'setWebhook' failed!
You can enable sensitive logs to see why it happens. Change this line: https://github.com/bot-base/telegram-bot-template/blob/679ab0a73c9a4b42a1f47ff7326a765ff6748565/src/main.ts#L10 to
const bot = createBot(config.BOT_TOKEN, {
config: {
client: {
sensitiveLogs: true,
},
},
});
Error occurred: HttpError: Network request for 'setWebhook' failed!
You can enable sensitive logs to see why it happens. Change this line:
to
const bot = createBot(config.BOT_TOKEN, { config: { client: { sensitiveLogs: true, }, }, });
Apparently it is setting it to be empty to be empty:
{
"ok": true,
"result": true,
"description": "Webhook is already deleted"
}
But that is not a problem now as I set it up manually
Are we also sure fastify middleware works @deptyped ?
Are we also sure fastify middleware works @deptyped ?
Hmm, I can confirm that something is broken. It seems to be related to this change in grammY. Reverting it fixes the problem.
Are we also sure fastify middleware works @deptyped ?
Hmm, I can confirm that something is broken. It seems to be related to this change in grammY. Reverting it fixes the problem.
How can I revert it on my end?
How can I revert it on my end?
The simplest way is to manually revert the changes to the node_modules/grammy/out/convenience/frameworks.js
file. Fastify-related code is near 116 line.
I did change it:
const fastify = (req, reply) => ({
update: Promise.resolve(req.body),
header: req.headers[SECRET_HEADER_LOWERCASE],
end: () => reply.status(200).send(),
respond: (json) => reply.send(json),
unauthorized: () => reply.code(401).send(WRONG_TOKEN_ERROR),
});
but still my request comes in, I'm sending /start and no response back:
[19:03:44.302] INFO: incoming request
reqId: "req-3"
req: {
"method": "POST",
"url": "/webhook",
"hostname": "vocal-sensible-hippo.ngrok-free.app",
"remoteAddress": "127.0.0.1",
"remotePort": 46724
}
Any idea?
On Wed, 15 May 2024, 01:48 deptyped, @.***> wrote:
How can I revert it on my end?
The simplest way is to manually revert the changes to the node_modules/grammy/out/convenience/frameworks.js file. Fastify-related code is near 116 line.
— Reply to this email directly, view it on GitHub https://github.com/bot-base/telegram-bot-template/issues/461#issuecomment-2110690691, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVDZXOPKRQHPR26AL4H3N3TZCI57LAVCNFSM6AAAAABHV7EPD2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJQGY4TANRZGE . You are receiving this because you authored the thread.Message ID: @.***>
I replaced Fastify with Hono in the template. If Fastify is not a requirement for you, you can fetch the latest changes to use Hono instead.
How can I do that? (junior developer here)
If you generated a new repository, you need to add the template repository as a remote:
git remote add template git@github.com:bot-base/telegram-bot-template.git
git remote update
And then merge the changes from main
branch:
git merge template/main --squash --no-commit --allow-unrelated-histories
If you just cloned this repository, you need to pull the changes:
git pull origin main
Thank you!
On Wed, 15 May 2024, 18:49 deptyped, @.***> wrote:
How can I do that? (junior developer here)
If you generated a new repository, you need to add the template repository as a remote:
git remote add template @.***:bot-base/telegram-bot-template.git git remote update
And then merge the changes from main branch:
git merge template/main --squash --no-commit --allow-unrelated-histories
If you just cloned this repository, you need to pull the changes:
git pull origin main
— Reply to this email directly, view it on GitHub https://github.com/bot-base/telegram-bot-template/issues/461#issuecomment-2112062040, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVDZXOOHXICUPQSEPMUKDL3ZCMVTJAVCNFSM6AAAAABHV7EPD2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJSGA3DEMBUGA . You are receiving this because you authored the thread.Message ID: @.***>
@deptyped still not working Webhook not responding to /start message
[13:40:32.972] INFO: Webhook was set
url: "https://vocal-sensible-hippo.ngrok-free.app/webhook"
[13:40:32.975] INFO: Server started
url: "http://127.0.0.1:3000"
[13:41:53.379] DEBUG: Incoming request
requestId: "a02e21d2-6df4-4409-afde-7136c093d9cd"
method: "POST"
path: "/webhook"
Hm, according to the logs everything is ok, the request is received on the webhook and passed to the handler. I can't reproduce the problem either. Can you please share the code or provide a minimal reproducible example?
@deptyped I cloned the repo again, I had to remove the following code:
// await bot.init(); --> this
// start server
serve(
{
fetch: server.fetch,
hostname: config.BOT_SERVER_HOST,
port: config.BOT_SERVER_PORT,
},
(info) => {
const url =
info.family === "IPv6"
? `http://[${info.address}]:${info.port}`
: `http://${info.address}:${info.port}`;
logger.info({
msg: "Server started",
url,
});
},
);
// set webhook --> AND THIS
// await bot.api.setWebhook(config.BOT_WEBHOOK, {
// allowed_updates: config.BOT_ALLOWED_UPDATES,
// secret_token: config.BOT_WEBHOOK_SECRET,
// });
but besides that npm run dev accepts requests, but still not working. I am using ngrok, on which I set the /webhook endpoint. Didnt change anything else besides that.
Yes I can confirm there is something with the middleware
I had to remove the following code
Why? await bot.init()
is necessary to ensure that your bot token is correct before you start receiving requests from Telegram. If it doesn't work, it means your bot won't work either.
I had to remove the following code
Why?
await bot.init()
is necessary to ensure that your bot token is correct before you start receiving requests from Telegram. If it doesn't work, it means your bot won't work either.
Any suggestion on that? Its a simple bot
I created a new bot with new token but same issue... bot.init() is pending
* Information about the bot itself as retrieved from `api.getMe()`. Only
* available after the bot has been initialized via `await bot.init()`, or
* after the value has been set manually.
*
* Starting the bot will always perform the initialization automatically,
* unless a manual value is already set.
from grammy documentation, is it the case in which we need to init automatically?
I created a new bot with new token but same issue... bot.init() is pending
That's weird. Can you access Bot API directly?
https://api.telegram.org/botTOKEN/getMe
from grammy documentation, is it the case in which we need to init automatically?
I sometimes encountered this error without manual initialization. Probably automatic initialization doesn't work well enough if the bot receives many requests immediately after startup. However, this was about a year ago, maybe it's fixed now.
But there's another reason to initialize manually. If we have incorrect credentials, what's the point of starting the server, fetching an update, and halting operations in the middle of processing due to an incorrect token? It's much better to fail fast.
if (
// !process.env.IS_BROWSER && // uncomment this line if you use a bundler that sets env.IS_BROWSER during build time
process.versions &&
// check for node
in case we want to use this in "exotic" JS envs
process.versions.node
) {
setDefaultAutoSelectFamily(false);
}
this piece of code fixed it. It has somethind to do with IPv6 / IPv4
It has somethind to do with IPv6 / IPv4
Wow 🤯
I'm glad you found a solution! So, does everything work now?
Everything works now!
@deptyped It is not working in production though, deployed on Vercel
Make sure you turn off Vercel Authentication and set the NODEJS_HELPERS
environment variable to 0
Nothing to do, all endpoints work but Webhookcallback is not being called. I did not add anything besides cloning the repo and deploying it to vercel and configuring env variables. I wonder if it has something to do with IPv4 again
On Sat, May 18, 2024 at 12:04 AM deptyped @.***> wrote:
Make sure you turn off Vercel Authentication https://vercel.com/docs/security/deployment-protection/methods-to-protect-deployments/vercel-authentication#manage-using-the-dashboard and set the NODEJS_HELPERS environment variable to 0
— Reply to this email directly, view it on GitHub https://github.com/bot-base/telegram-bot-template/issues/461#issuecomment-2118433028, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVDZXON6OCMG5YXPFZ6YP5DZCZ5FJAVCNFSM6AAAAABHV7EPD2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJYGQZTGMBSHA . You are receiving this because you modified the open/close state.Message ID: @.***>
Vercel dev works perfectly locally though.
Try getWebhookInfo
method to check if there is any error
https://api.telegram.org/botTOKEN/getWebhookInfo
Did solve it, by changing to polling once and switching back to webhook mode. Don't ask me why.
On Sun, 19 May 2024, 04:46 deptyped, @.***> wrote:
Try getWebhookInfo method to check if there is any error
https://api.telegram.org/botTOKEN/getWebhookInfo
— Reply to this email directly, view it on GitHub https://github.com/bot-base/telegram-bot-template/issues/461#issuecomment-2118987421, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVDZXOPBZS6YTH4YARUQRTTZC6VZJAVCNFSM6AAAAABHV7EPD2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJYHE4DONBSGE . You are receiving this because you modified the open/close state.Message ID: @.***>
I cloned repo, set up the basics, sending a request to telegram bot like /start, request is captured from webhook but not responding.
I am expecting it to respond as stated here:
All env keys are set: BOT_MODE=webhook BOT_TOKEN=...
I also tried to change NODE_ENV to production and run it with npm start but same behaviour