Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I always get 401 unauthorized error when use test bot #1198

Open
judy9712 opened this issue May 14, 2024 · 1 comment
Open

I always get 401 unauthorized error when use test bot #1198

judy9712 opened this issue May 14, 2024 · 1 comment

Comments

@judy9712
Copy link

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?

@rock1nbvv
Copy link

rock1nbvv commented May 29, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants