I always get 401 unauthorized error when use test bot
I have read:
I am using the latest version of the library.
I'm trying to connect my bot created in a test environment. However, even though I input the correct bot token, I keep getting a 401 unauthorized error.
this is my code:
import TelegramBot from 'node-telegram-bot-api';
require('dotenv').config();
const bot = new TelegramBot(TELEGRAM_TOKEN, {
polling: true,
});
bot.on('message', (msg) => {
const chatId = msg.chat.id;
bot.sendMessage(chatId, 'Received your message');
});
bot.on('polling_error', (error) => {
console.log({ error });
});
and this is my package.json
"dependencies": {
"dotenv": "^16.4.5",
"express": "^4.19.2",
"node-telegram-bot-api": "^0.65.1"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/node": "^20.12.12",
"@types/node-telegram-bot-api": "^0.64.6",
"nodemon": "^3.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
I saw the testEnvironment option in api docs. However, when I try to input 'testEnvironment' in the options, it says that it's not a valid option. Has the 'testEnvironment' option been removed? How can I develop using a bot deployed in a test environment?
@judy9712 I've just bumped into this issue and suppressing the error helped, the API with test env still works
// @ts-ignore
new TelegramBot(TOKEN || '', {polling: true, testEnvironment: true});
But it is still an issue with ConstructorOptions interface. I hope more comments will help devs to see it.
Same issue. Just created account in test environment, created 2 bots with bot father bot and neither of them works. Both returning 401 Unauthorized on getMy endpoint. Tried to revoke tokens and use new ones - no luck so far. Any thoughts?
@vsolovev have you tried the workaround from my comment above?
Same issue. Just created account in test environment, created 2 bots with bot father bot and neither of them works. Both returning 401 Unauthorized on getMy endpoint. Tried to revoke tokens and use new ones - no luck so far. Any thoughts?