-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun-bot-local.ts
More file actions
30 lines (26 loc) · 891 Bytes
/
run-bot-local.ts
File metadata and controls
30 lines (26 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* Local run: polling (getUpdates). Only BOT_TOKEN needed.
* Run: npx tsx scripts/run-bot-local.ts (or npm run bot:local)
* Do not run with the same token while webhook is set in production.
*/
import { createBot } from '../bot/grammy';
import { loadEnv } from './load-env';
loadEnv();
const token = (process.env.BOT_TOKEN || process.env.TELEGRAM_BOT_TOKEN || '').trim();
if (!token) {
console.error('Missing BOT_TOKEN (or TELEGRAM_BOT_TOKEN)');
process.exit(1);
}
async function main() {
const bot = createBot(token);
await bot.api.deleteWebhook();
await bot.start();
console.log('Bot running locally (getUpdates). Press Ctrl+C to stop.');
}
main().catch((err) => {
console.error(err);
if (err?.error_code === 401) {
console.error('[bot] 401 Unauthorized: check BOT_TOKEN in .env (valid token from @BotFather, no extra spaces).');
}
process.exit(1);
});