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 · 5 comments
Open

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

judy9712 opened this issue May 14, 2024 · 5 comments

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.

@vsolovev
Copy link

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?

@rock1nbvv
Copy link

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

@timurrakhimzhan
Copy link

@rock1nbvv
you just supressed ts error, it does not have anything to do with 401 error

@rock1nbvv
Copy link

rock1nbvv commented Dec 24, 2024

@timurrakhimzhan
As far as i remember i have suppressed the ts-error so the ts config would allow me to build the app using the configuration parameter that enables test env.

So technically you are correct i just made ts to allow tweaking my configuration. And as I remember it worked well(though i had other issues with test env) as lib itself already has this setting.

401 error happens when you try to login to live env with your test env credentials what can be changed by editing configuration.

Yet i did quite a while ago so correct me if i am wrong.

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

4 participants