Questions tagged [node-telegram-bot-api]

Node.js Telegram Bot API Node.js module to interact with official Telegram Bot API.

Node.js module to interact with official Telegram Bot API. A bot token is required and can be obtained by talking to @botfather.

Install

npm install --save node-telegram-bot-api

Usage

const TelegramBot = require('node-telegram-bot-api');

// replace the value below with the Telegram token you receive from @BotFather
const token = 'YOUR_TELEGRAM_BOT_TOKEN';

// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});

// Matches "/echo [whatever]"
bot.onText(/\/echo (.+)/, (msg, match) => {
  // 'msg' is the received Message from Telegram
  // 'match' is the result of executing the regexp above on the text content
  // of the message

  const chatId = msg.chat.id;
  const resp = match[1]; // the captured "whatever"

  // send back the matched "whatever" to the chat
  bot.sendMessage(chatId, resp);
});

// Listen for any kind of message. There are different kinds of
// messages.
bot.on('message', (msg) => {
  const chatId = msg.chat.id;

  // send a message to the chat acknowledging receipt of their message
  bot.sendMessage(chatId, 'Received your message');
});
159 questions
0
votes
1 answer

Want to filter more then 10 million numbers on Telegram

I need a little help. I have more then 10 millions number and i want to filter those contacts on telegram like which number exist on telegram or not. I have search a lot but not get any method which fulfil my needs. I have checked IsphoneRegistered…
0
votes
0 answers

callback_query working more than once in inline keyboard

Below is the code. When my code runs for the first time it works like a charm, but when I again input the URL and click on any of the buttons it shows me 2 pics (1 pic is from the previous result), and for 3rd time it shows 3 pics (2 pics are from…
Ankit Kumar
  • 3
  • 2
  • 3
0
votes
1 answer

How to split long list of commands to different files

I'm making telegram bot with node-telegram-bot-api and everything is fine until the command list become very long. It's not comfortable to serve many commands in single .js file where bot was initialized. I'm understand one basic thing with…
0
votes
1 answer

ETELEGRAM: 400 Bad Request: poll can't be stopped

I am trying to invoke the telegramBot.stopPoll() function but I am getting error ETELEGRAM: 400 Bad Request: poll can't be stopped I want to stop the poll when a desired person (userId) answers the poll. Here is my function which create the poll…
Qadir Hussain
  • 8,721
  • 13
  • 89
  • 124
0
votes
2 answers

How to get messages that were not delivered while Telegram Bot web-server was down?

Curious, if there is way to avoid skipping messages sent from Telegram Bot while web-server that accepts Webhooks is down (because of redeploy, failure or maintenance). When you use polling - Telegram API sends messages starting from last retrieved…
0
votes
4 answers

TELEGRAM: 400 Bad Request: wrong type of the web page content

While sending documents via external link in telegram bot I am getting error of "Unhandled rejection Error: ETELEGRAM: 400 Bad Request: wrong type of the web page content". I just don't understand why this error occured? P.S I'm using node.js…
vecume
  • 46
  • 1
  • 4
0
votes
1 answer

How to start a new poll only after answering for a previous one?

I have a simple code here. Im using https://github.com/yagop/node-telegram-bot-api telegram framework to make my first bot. I have array with 10 questions in it. So i can't understarnd what should i do if i want to start a new poll only after user…
0
votes
0 answers

How to use proxy in typescript?

I want to create a simple telegram robot using typescript with the help of this repo. I need set a proxy, used following code: const bot = new TelegramBot(config.bot.token, { polling: true, request: { agentClass: Agent, …
mostafa8026
  • 273
  • 2
  • 12
  • 25
0
votes
1 answer

Problem with running telegram bot on windows server 2012 r2

I've created a telegram bot using node.js and it worked successfully on my local system... but when I tried to run it on a 2012/r2 windows server, I've constantly got the error: [polling_error] {"code":"ETELEGRAM","message":"ETELEGRAM: 409…
Mohammad
  • 194
  • 5
  • 14
0
votes
1 answer

Telegram - Node api. How do I get the userID of the user to whom im replying to when I trigger a specific regex match?

Imagine that theres one user message in the chat, and I, as another user, do the following Answer to his text with: /tip 50 I basically want to somehow receive , the user to whom I have answered to, (his id) , and the second parameter. I cant seem…
mouchin777
  • 1,428
  • 1
  • 31
  • 59
0
votes
1 answer

How to enable telegram node app to keep running endlessly

I'm building a node Telegram bot using node-telegram-bot-api which is amazing so far. However, I want to listen to messages constantly sent to my bot, so I'm using: bot.on('message', (msg) => { const Hi = "hi"; if…
Nir Tzezana
  • 2,275
  • 3
  • 33
  • 56
0
votes
1 answer

Heroku deployment for a nodejs based telegram bot

I am trying to deploy a chess telegram bot for which the developer has a demo and it works well. However that code has a mistake in that black and white pieces are reversed and bishop and pawn are interchanged for both colours. So I decided to fork…
techbolt
  • 103
  • 8
0
votes
1 answer

How can I send a message to @BotFather programmatically?

I know that a bot can be created in a telegram if you send the command /newbot to the bot @BotFather. But to do this, you need to take your device, open Telegram, open a chat with @BotFather and send him the command /newbot. Can all of the above be…
0
votes
0 answers

How to restrict user? telegram-bot

I want to make a bot that can restrict new user that join to the group, below is my code, but when I run this, it seemed that it is not working. I guess I misunderstood the way of how 'chatpermission' work, but can't find it. Here is the 'restrict'…
0
votes
1 answer

Using telegram bot as live chat with nodeJS

In the bot menu, I have an online chat option with me. If a user clicks this button, bot saves this users state as chatMode. The scenario is like if the user's state is chatMode each of his messages should be forwarded to me, and when I reply to…