Webhook Fails for Telegram Bot – APP_URL Trailing Semicolon Causes 404 (Despite Not Being in ENV)/RAILWAY VARIABLE

valescaray
HOBBY

a month ago

Description of the Issue:

I'm deploying a Telegram bot using Node.js and the Telegraf library on Railway. The bot works fine locally and also when deployed to Render, but fails on Railway when trying to set a webhook.

The failure seems to be caused by a semicolon (;) being appended automatically to the webhook URL constructed using process.env.APP_URL, even though the environment variable in Railway does not contain a semicolon in the value.

Error Message and Description:

When setting the webhook via:

CopyEdit

await bot.telegram.setWebhook(`${process.env.APP_URL}/webhook`);

I get this error:

CopyEdit

TelegramError: 404: Not Found payload: { url: 'https://bot-test-production-1293.up.railway.app/webhook'; }

Note the semicolon at the end of the webhook URL:
'https://bot-test-production-1293.up.railway.app/webhook';

This is not present in my variable value. It breaks the Telegram API call.

I also tested this via manual curl:

curl -X POST https://api.telegram.org/bot<my_token>/setWebhook \ -H "Content-Type: application/json" \ -d '{"url": "https://bot-test-production-1293.up.railway.app/webhook"} Telegram returned {"ok":true}, proving the endpoint is correct and reachable when the semicolon is not present.

Build/Deploy Logs:

There’s no error during build. Error occurs during runtime when the webhook is being set:

Failed to launch bot: TelegramError: 404: Not Found payload: { url: 'https://bot-test-production-1293.up.railway.app/webhook'; }

This shows the invalid semicolon.

Code Repository (If applicable):

[Private repo] – But I can provide a stripped-down minimal version if needed. The important code snippet:

const WEBHOOK_PATH = "/webhook"; const WEBHOOK_URL = $`{process.env.APP_URL}${WEBHOOK_PATH}`; await bot.telegram.setWebhook(WEBHOOK_URL);

Conclusion and Request:

I believe Railway is injecting a semicolon when interpolating or exporting APP_URL, even though it’s not in the variable editor. This causes third-party API integrations (like Telegram webhooks) to break silently.

Please help confirm:

  • Is this a known issue?

  • Can it be fixed or worked around?

  • Is there an internal sanitization step I need to disable?

This issue only happens on Railway and cost me a lot of debugging time. Happy to assist with more info or test cases.

$10 Bounty

4 Replies

at a first glance i see 2 things, the semicolon is outside of the url: 'http...'; not sure why it is there

you are missing the backticks for interpolation

const WEBHOOK_URL = `${process.env.APP_URL}${WEBHOOK_PATH}`;

alexwebgr

at a first glance i see 2 things, the semicolon is outside of the url: 'http...'; not sure why it is thereyou are missing the backticks for interpolationconst WEBHOOK_URL = `${process.env.APP_URL}${WEBHOOK_PATH}`;

valescaray
HOBBY

a month ago

Thank you for your reply

  1. for the semicolon being outside of the url: 'http..';: This is exactly the core issue that am reporting — the semicolon is not in my.env / railway service variable or code, but it somehow appears in the payload sent to Telegram, causing a 404.

  2. for the bacticks for interpolation: it was added, its an error on my path for not adding it to the above complaint


curl -X POST https://bot-test-production-3b22.up.railway.app/webhook

{"status":"error","code":404,"message":"Application not found","request_id":"oXPfDmBYQKayYBesqE4W0Q"}


alexwebgr

curl -X POST https://bot-test-production-3b22.up.railway.app/webhook{"status":"error","code":404,"message":"Application not found","request_id":"oXPfDmBYQKayYBesqE4W0Q"}

valescaray
HOBBY

a month ago

Thank you for your response.

Please note that the HTTP endpoint is currently disabled. You can use the active HTTPS URL below to run your test, as it is live and running my code:

https://bot-test-production-1293.up.railway.app

Kindly modify the test accordingly to target this HTTPS endpoint.


Webhook Fails for Telegram Bot – APP_URL Trailing Semicolon Causes 404 (Despite Not Being in ENV)/RAILWAY VARIABLE - Railway Help Station