yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.13k stars 1.49k forks source link

How does my telegram bot connect to my computer? #1118

Closed y0unghe closed 2 months ago

y0unghe commented 10 months ago

I am following the tutorial on how to create a telegram bot. I got the token and am listening to messages. But when I was typing in my bot, nothing happened. I am wondering how the telegram bot connects to my computer.

import TelegramBot from 'node-telegram-bot-api';

const token = '6588289377:AAGENT2zoM-19hCIlgE2Woss2RQXsB5-nOM';

const bot = new TelegramBot(token, { polling: true });

bot.on('message', (msg) => {
    console.log(msg);
    var Hi = "hi";
    if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) {
        bot.sendMessage(msg.chat.id, "Hello dear user");
    }
});
VDS13 commented 9 months ago

Hello, @y0unghe. What's in the logs?

sojinsamuel commented 3 months ago

Could be an issue related to location. It was mine too. i see you are from china. still i cant say for sure without seeing the logs. But try using a vpn and set it to any country like US. I'm from india and it worked for me

danielperez9430 commented 2 months ago

I am following the tutorial on how to create a telegram bot. I got the token and am listening to messages. But when I was typing in my bot, nothing happened. I am wondering how the telegram bot connects to my computer.

import TelegramBot from 'node-telegram-bot-api';

const token = '6588289377:AAGENT2zoM-19hCIlgE2Woss2RQXsB5-nOM';

const bot = new TelegramBot(token, { polling: true });

bot.on('message', (msg) => {
    console.log(msg);
    var Hi = "hi";
    if (msg.text.toString().toLowerCase().indexOf(Hi) === 0) {
        bot.sendMessage(msg.chat.id, "Hello dear user");
    }
});

If you have a error you can get more information adding this code:

bot.on('polling_error', (error) => {
  // console.log(error)
  console.log("Polling error code: ",error.code);
  console.log("Error Message: ", error.message);
  console.log("Stack trace: ", error.stack);
});

The problem could be that you are in a country or under an internet provider that has the domain "https://api.telegram.org" blocked, so your bot cannot communicate with the Telegram servers to receive updates.