13 days ago
I have a website that forwards requests to Telegram, and for some reason the host doesn't see the ID I specified.
12 Replies
13 days ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
13 days ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 13 days ago
13 days ago
Could you share a few details? 1. What language are you using? 2. Where did you set the TELEGRAM_CHAT_ID? In the Railway variables tab or a .env
file? 3. Can you post the line of code that's trying to read the variable and can you paste the full deployment logs too?
13 days ago
1. Language: TypeScript (Next.js 15, App Router).
2. Yes, on the Railway variables page
3. export async function sendTelegramMessage(message: TelegramMessage) {
const token = process.env.TELEGRAM_BOT_TOKEN;
const chatId = message.chatId || process.env.TELEGRAM_CHAT_ID;
if (!token || !chatId) {
console.log("[TG] Skipped send (no token/chat)", message.text);
return { ok: false };
}
const url = https://api.telegram.org/bot${token}/sendMessage;
const res = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
chat_id: chatId,
text: message.text,
parse_mode: "HTML",
reply_markup: message.replyMarkup,
disable_web_page_preview: true,
}),
cache: "no-store",
});
return res.json();
}
13 days ago
I'll duplicate the errors like this because they're not really visible on the screenshots:npm error path /app
npm error command failed
npm error signal SIGTERM
npm error command sh -c next start
npm error A complete log of this run can be found in: /root/.npm/_logs/2025-09-22T22_03_56_207Z-debug-0.log
[TG] Skipped send (no token/chat) <b>Новая заявка #gpaq61w</b>
install mise packages: node
ERROR: failed to build: failed to solve: secret TELEGRAM_CHAT_ID: not found
13 days ago
I did as you said, still the same error: ERROR: failed to build: failed to solve: secret TELEGRAM_CHAT_ID: not found
13 days ago
In theory, Railway reads variables from its settings, not from ENV files.
13 days ago
In order to load your environmental variables from a file named .env.local
you'd need to make sure you configure the dotenv
package.
For example:
require('dotenv').config({ path: '.env.local' });
After that you can load environmental variables how you already are.
13 days ago
Why should I download them from ENV if I can do it directly from railway?
13 days ago
ERROR: failed to build: failed to solve: secret TELEGRAM_CHAT_ID: not found
This looks like a build-time error, not a runtime error. Are you sure you’re not referencing it somewhere during the build, such as in next.config.js
or in a top-level variable? (asking this because it is not clear where this exported function is being used)
If you do need an env variable at build time, check the Next.js docs: https://nextjs.org/docs/pages/guides/environment-variables#loading-environment-variables-with-nextenv
or just use a .env
file as stated before
12 days ago
I checked next.config.ts and it doesn't reference any environment variables. env is only read at runtime in server-side code, such as src/utils/telegram.ts and API routes, not at build time.
Where env is read:
const token = process.env.TELEGRAM_BOT_TOKEN;
const chatId = message.chatId || process.env.TELEGRAM_CHAT_ID;
Key points: Next.js automatically loads .env.local, .env, and .env.production for application code (dev/build/runtime).
mihrauder
I checked next.config.ts and it doesn't reference any environment variables. env is only read at runtime in server-side code, such as src/utils/telegram.ts and API routes, not at build time.Where env is read:const token = process.env.TELEGRAM_BOT_TOKEN;const chatId = message.chatId || process.env.TELEGRAM_CHAT_ID;Key points: Next.js automatically loads .env.local, .env, and .env.production for application code (dev/build/runtime).
12 days ago
Hey, while you mentioned that it is technically only ever used on the server side, there may be the possibility that it is leaked on the client and therefore you will have to fix the leaking/being used on the client issue. You can test this theory by prefixing the environment variable with NEXT_PUBLIC_
as specified in the NextJS docs for client side environment variables, if your app can now read the newly defined environment with the prefix, then it would be a problem with how you use supposedly server side environment variable.
Additionally, while you didn't mention it, if you use Turborepo, then you may have to add additional configuration as specified in the Turborepo docs.
uxuz
Hey, while you mentioned that it is technically only ever used on the server side, there may be the possibility that it is leaked on the client and therefore you will have to fix the leaking/being used on the client issue. You can test this theory by prefixing the environment variable with NEXT_PUBLIC_ as specified in the NextJS docs for client side environment variables, if your app can now read the newly defined environment with the prefix, then it would be a problem with how you use supposedly server side environment variable. Additionally, while you didn't mention it, if you use Turborepo, then you may have to add additional configuration as specified in the Turborepo docs.
12 days ago
I don't quite understand what this is for
Status changed to Open itsrems • 12 days ago