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

How to clear chat NODE JS telegram bot (node-telegram-bot-api.)

Hi guys i'm junior nodejs developper! my question: How to clear chat on write text == cls my code const { chat, message_id } = message const chatId = message.chat.id const name = message.from.first_name const text = message.text //…
Umarjon
  • 13
  • 6
0
votes
1 answer

Telegram Bot sendDocument problem with filename

I try to send .pdf file like this: await bot.sendDocument(chatId, fs.readFileSync(outputFilePath), {}, { filename: outputFileName, contentType: 'application/pdf', }) But if the filename includes at least one of these characters "§¤&`£€'",…
0
votes
2 answers

How to print data comming from api in small chunks in loop

I am making a telegram bot where i am receving data from api call. the api is returning me data like this articles is the array and i want to retrive all the news from this . when i do it without loop it work fine with no error But when i am trying…
0
votes
1 answer

node-telegram-bot-api: CHAT_ADMIN_REQUIRED

Hi I am trying to revoke an invite link but when I am providing chat_id and invite_link but still throwing an error Unhandled rejection Error: ETELEGRAM: 400 Bad Request: CHAT_ADMIN_REQUIRED Here is the code which I used to revoke invite…
0
votes
1 answer

Take Input From Python Script To Node.js Telegram Bot

I want to take input from the python script in the Telegram Bot When User asks for it I Have written the code to take input from Python Script But I Can't Figure out how to Use it in Telegram Bot to SendMessage const TelegramBot =…
0
votes
1 answer

Telegram Bot to Download files from Google Drive

how can I utilize my telegram bot (node.js telegram bot api) to send random images saved in my google drive folder
0
votes
1 answer

Npm not installing node-telegram-bot-api

My specifications: C:\Users\new>node -v v14.17.1 C:\Users\new>npm -v 6.14.13 C:\Users\new>py -V Python 3.9.5 C:\Users\new>cmd Microsoft Windows [Version 10.0.19042.1052] (c) Microsoft Corporation. All rights reserved. Windows 32-Bit I create a…
Parvat . R
  • 751
  • 4
  • 21
0
votes
2 answers

Telegram bot webhook send only commands

I'm building a telegram chatbot in nodejs that will work on webhook. Currently, bot hits my webhook URL with every message in chat. Is it possible to only push payload on command execution for the bot? So I would like only to get the payload from…
Mugetsu
  • 1,739
  • 2
  • 20
  • 41
0
votes
1 answer

How can i take user from username?

Good morning everyone, I try to coding a bot for telegram. I need to take a user[object] from a username. It can be done? I tried to google about it, but I didn't find anything and besides I read that there is no way to do…
0
votes
1 answer

Cannot use Inline keyboard and parse mode together in node js telegram bot?

Hey Guys I was making an telegram bot using nodejs telegram bot api when I cam across a problem . I wanted to dispaly a html parsed message and an inline keyboard below it bot.onText(/\/help/, async (msg) => { help_msg = `This is the link for…
Anish
  • 89
  • 1
  • 10
0
votes
0 answers

Telegram too many requests

I have been trying to create a mailing bot in telegram. I get a lot of 429 errors after some time, even though it sends only 8 messages a second which is a lot less than 30 a second (number which is allowed by telegram). Was wandering maybe it is…
0
votes
1 answer

Run telegram bot in multiple clusters using pm2

I'm currently running a telegram bot using the node-telegram-bot-api. But now the project is getting bigger and bigger and more users are using my bot. So I had some difficulties when I had to re-deploy my app while many people are still on…
Alex Won
  • 177
  • 2
  • 11
0
votes
2 answers

How to keep a nodejs program using Wifi running even if pc is in sleep mode?

I am coding a telegram bot with nodejs using node-telegram-bot-api and I run the nodejs code on my windows 10 laptop, on command prompt, and it runs fine when my laptop is connected to Wifi but as soon I make my pc sleep, automatically my pc…
0
votes
1 answer

why my is still hit my endpoint event without triggered

i create new method as webhook in telegram and it has been registered, my method : // https://api.telegram.org/bot[token]/setWebhook?url=https://xxx/main/execute/ // https://telegram.me/TheXXXBot?start=project register function execute(){ //…
kreamik
  • 609
  • 2
  • 11
  • 24
0
votes
0 answers

Command 'pin' not working after deployment to Heroku. Specifically

I got this bot that I made. Every piece of command works just fine after I deployed it via git push heroku master Except this piece of code const Telegraf = require('telegraf'); const Telegram = require('telegraf/telegram') const bot = new…