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
0 answers

inline keyboard handlers in node-telegram-bot-api package

I'm currently build a telegram bot and i have one issue. In my case has had a few inline keyboard. here are but all inline keyboard has a one handler bot.on('callback_query',query=>{ …
0
votes
0 answers

How to store user messages without losing markup in telegram bots?

How do I store user messages without losing markup (HTML or Markdown) in the Telegram bots? I'm working with node_telegram_bot_api It's clear when sending a message from the bot to the user: specify parse_mode and everything is fine. await…
0
votes
1 answer

Build dynamic Telegram ReplyKeyboard

Context: Building a simple telegram bot to allow me to check on model and year of cars available on a garage. It should show a ReplyKeyboard with available Brands. Upon tapping on a Brand, it should update to a new ReplyKeyboard, now with all…
0
votes
1 answer

Buttons and bold text in bot.sendMessage

help me understand what the problem is. Why are the buttons (menuOptions) not displayed? if (text === '/start') { ust[chatId] = 0; bot.sendMessage(chatId, `${msg.from.first_name}, Добро пожаловать
kh0dan
  • 1
0
votes
1 answer

Output at the same time {parse_mode: 'HTML'} and buttons

Friends. Tell me, please: how to display both buttons and {parse_mode: 'HTML'} through node-telegram-bot-api on Node JS? bot.sendMessage(chatId, `${msg.from.first_name}, Hello! ✌ `, {parse_mode: 'HTML', menuOptions}) But the telegram bot…
kh0dan
  • 1
0
votes
1 answer

How to avoid hitting 429 error with telegram bot using sendMediaGroup?

Here is my piece of code: let interval = chatType === 'private' ? 1000 : 5000; let it = 0; dl.imgs.forEach(function (el, index) { it += interval * index; if (index===2) it += 60000; …
0
votes
1 answer

How to edit the text of a message send by my telegram bot with node-telegram-bot-api?

I am currently using Telegram as a tool to start & watch/log a script with the node-telegram-bot-api. The idea is to have a text with 'Uploaded Files: 1/10' and then will be edited according to the status of the upload in the…
cinemandre
  • 62
  • 8
0
votes
0 answers

How to make session i.e wizard on node-telegram-api?

i want to make something like this: user: /addname bot: hi what is your name? user: turtleman bot: welcome, turtlename! But i have no idea how that can be done
0
votes
0 answers

Issue when running an AWS Lambda Node.js function with a simple Telegram bot example

I'm exploring Telegram bots and have two AWS Lambda functions, one written in Python and another in Node. The Python lambda works fine and is able to send messages to a Telegram chat. However I've tried to do the same with a very simple example in…
0
votes
1 answer

ReactJS - node-telegram-bot-api (Uncaught TypeError: Cannot read properties of undefined (reading 'split'))

I am trying to import the node-telegram-bot-api in my react app like so:` import TelegramBot from "node-telegram-bot-api"; But upon doing this I get the following error in my console. Error Image This error is created upon importing alone and…
wnmarc
  • 13
  • 3
0
votes
0 answers

How to download files to my server using telegram bot API in nodejs?

I need to download big files(1gb) which are sent to my bot by telegram users. I had rented a server to run the bot but i am not able to find a way to download the files to my server. Please can any of you help me with my problem.
0
votes
1 answer

How to get the message id of previous message in Telegram using node-telegram-bot-api?

I'm developing a Telegram bot using Node.js and node-telegram-bot-api library. I want to get the id of the previous message in the chat. How can I achieve this? I tried using this https://api.telegram.org/botХХХХ:ХХХХХХ/getUpdates?offset=-1 but it…
Dummy Cron
  • 143
  • 2
  • 11
0
votes
1 answer

How to add callable link to inline button url in telegram bot api?

I need to create inline_keyboard with callable url link in telegram bot api. The problem is that the telegram does not accept a link similar to 'tel:+99891....', is it possible to somehow add a link that opens the call window to the inline…
0
votes
1 answer

How to subscribe and unsubscribe a user from a telegram bot using Node.js node-telegram-bot-api?

I'm writing a program to develop a telegram chatbot using Node.js and node-telegram-bot-api module. I want to set command such that when received /unsubscribe the user should be unsubscribed from the bot. I read the github document for the module…
Dummy Cron
  • 143
  • 2
  • 11
0
votes
2 answers

Telegram Bot -UnhandledPromiseRejectionWarning: Error: 400: Bad Request: chat not found

I am trying to get chat from one user using my telegram bot. Below is my code so far const { Telegraf } = require('telegraf') const bot = new Telegraf(process.env.BOT_TOKEN); bot.telegram.getChat('username', async (ctx) =>{'incoming message ',…
yongchang
  • 503
  • 6
  • 18