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
1
vote
1 answer

How to avoid getting duplicate responses from my telegram bot?

I wrote a simple telegram bot that after inputting a command it displays some stats. It works flawlessly except when it's being fed the same command more than once (different users using the command). Right now looks something like this: me:…
1
vote
1 answer

Dynamic inlineKeyboard buttons (nodejs, telegraf)

I need to create a menu using inlineKeyboard from an array of "n" element that can change in value and number. I'm working with telegraf API and this is how i create a static one: const bookMenu = Telegraf.Extra .markdown() .markup((m) =>…
Marco Lampis
  • 403
  • 5
  • 15
1
vote
1 answer

Telegram bot response too late

I created simple telegram bot to filter bad words, it works perfectly when I run on local, but response too late after I deployed to Heroku service. Full Code const TelegramBot = require('node-telegram-bot-api') const bot = new…
U.A
  • 2,991
  • 3
  • 24
  • 36
1
vote
1 answer

How do I export the bot instance and use its methods?

I'm trying to set up a bot using the node-telegram-bot-API, I have created the bot instance as follows in Foo.js const TelegramBot = require('node-telegram-bot-api'); const bot = new TelegramBot(config.telegram.TELEGRAM_TOKEN, {polling:…
user7244184
1
vote
2 answers

Unhandled rejection Error: ETELEGRAM: 400 Bad Request: message text is empty

I'm new to telegram bot and node js, I'm developing a simple bot that calls api urls to get json objects, but I've this error with a command. This is the command's code: bot.onText(/\/fixtures/, (msg) => { const chatId = msg.chat.id; var out =…
1
vote
1 answer

Can't remove Telegram keyboard using ReplyKeyboardRemove

I'm making bot on Node.js. I have so me problem with removing keyboard. Here is how my message looks: chat_id: *****, text: '', reply_markup: JSON.stringify({ ReplyKeyboardRemove: { remove_keyboard: true } }) I'm receiving this…
Yevhen
  • 791
  • 9
  • 24
1
vote
2 answers

Telegram bot Nested previous button,node.js

How Can I Back from 3th Level node to Secend level node after That to First Level node? My Problem is Back Name, Because That is Same,,, This is my Code: bot.onText(/\/start/, function onLoveText(msg) { const opts = { …
Saeed Heidarizarei
  • 8,406
  • 21
  • 60
  • 103
0
votes
0 answers

Deploying Telegram bot to Vercel

I'm learning how to make a telegram bot. If i navigate to my site https://telebot-delta.vercel.app/api/app , it permanently displays error 500. When I send a message to the bot, I only get a reply after i refresh the page. Is this a bug in…
Dlorej
  • 83
  • 1
  • 5
0
votes
0 answers

How to get answer from user Telegram Bot JS

I'm using node-telegram-bot-api. My question - how create function like this (on screen) enter image description here I'am using this code, but code working in definite ID user How make to has been answer available everyone // Create bot const…
neutrino
  • 1
  • 1
0
votes
0 answers

Telegram Bot WebApp Long Loading

I'm developing a telegram bot with a web app using React for the web interface and Node.js (node-telegram-bot-api) for the bot functionality. On some devices, the initial loading of the web app is fast, but sometimes (mostly on iPhones), the first…
m4xx1k
  • 1
  • 1
0
votes
0 answers

Async function nodeJS with node-telegram-bot-api

I have a function that checks for the presence of user data in the table, returns the status (true or false) and passes the values to the next function that processes this value and processes the corresponding logic. The status is transmitted…
0
votes
0 answers

Assistance Needed with Telegram Bot Development - Handling multiple user input built on nodejs

I have a question regarding the development of a Telegram bot that involves sending the nearest location to a user. I'm facing an issue with handling user locations. Here's the scenario: When users press the "nearest loc" button, they are prompted…
0
votes
0 answers

typescript takes the next function overload in order

I want to create wrapper for node-telegram-bot-api, but typescript is able to resolve only last overload of function TelegramBot.on() on(event: 'callback_query', listener: (query: TelegramBot.CallbackQuery) => void): this; on(event:…
0
votes
1 answer

Axios request inside Telegrams inline_query and onText

I have code which makes just one request and returns some data I want. Here it is: let res = await axios({ method: 'get', url: `https://www.instagram.com/p/${videoId}/?utm_source=ig_web_copy_link?&__a=1&__d=1`, headers: { …
Bohdan
  • 53
  • 5
0
votes
0 answers

Send response to the website indicating a successful login after the user clicks the "start" button using the Telegram Bot API

How can I send a response to the website indicating a successful login after the user clicks the "start" button using the Telegram Bot API and the provided code snippet? Explanation: I have implemented a Telegram bot using the Telegram Bot API, and…