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
8
votes
1 answer

What is Difference between `msg.chat.id` and `msg.from.id` in Telegeram Bot?

What is Difference between msg.chat.id and msg.from.id in Telegeram Bot? Apparently, both are the same and Return user id. bot.sendMessage(msg.chat.id, 'Hi', opts) and bot.sendMessage(msg.from.id, 'Hi', opts)
Saeed Heidarizarei
  • 8,406
  • 21
  • 60
  • 103
6
votes
6 answers

How to manage invite link in private channel?

What I did: I developed a Telegram bot using TelegrafJS framework. This bot allow the user to subscribe to a paid channel, this channel is privated. So after that the payment is completed, the bot send the invitation link to let the user join to the…
sfarzoso
  • 1,356
  • 2
  • 24
  • 65
6
votes
2 answers

Change telegram bot name on the fly

I have a telegram bot that messages on a group. I want the telegram bot to change its “name” from time to time - just like a user can. Is this possible? This means that when I see a message from the bot it can say “ABCbot”, but later it can say…
5
votes
2 answers

Get user location latitude and longitude via telegram bot

How to Get user location latitude and longitude via telegram bot? Module: Link Code: bot.onText(/getLocation/, (msg) => { const opts = { reply_markup: JSON.stringify({ keyboard: [ [{text: 'Location', request_location: true}], …
Saeed Heidarizarei
  • 8,406
  • 21
  • 60
  • 103
4
votes
1 answer

Send schedule message to telegram channel by bot telegram API nodejs

In order to send a regular message I use - const uri = `https://api.telegram.org/bot${token}/sendMessage?chat_id=${channelId}&text=${text}`; await fetch(uri); But how to send a schedule message?
SirGrey
  • 43
  • 1
  • 3
4
votes
1 answer

Deeplinking into a telegram bot

I have a simple use case. When a user clicks the link below, T.me/MycompanynameBot?start=Microsoft I want to show him 3 inline buttons corresponding to 3 Telegram channels within Microsoft. Is this possible? The key is the bot must be able to…
4
votes
1 answer

Background continuous access to a users live location

I want my TG bot to have continuous access to a user’s live location. Is this possible? I understand that TG can be given continuous access - but it seems to me that this privilege is not relayed to bots running on TG. Is this correct? For the…
Carlos F
  • 893
  • 2
  • 12
  • 30
4
votes
1 answer

Can Telegram bot detect a new member joining a channel event?

I have a Telegram bot and I set this bot as admin of a channel. Now, when a new user ordinarily joins a channel (not a group) there is no message on the channel and no message we could get with getUpdates method. Is it technically possible to post a…
4
votes
1 answer

Show the ”welcome” message only for the new users in the Telegram group

I am an admin of some Telegram group. I added a bot to it. For every new user, I deleting the old welcome message and adding the new one, to reduce the number of irrelevant messages. Is there any way to show the ”welcome” message only to a specific…
Pumych
  • 1,368
  • 3
  • 18
  • 31
4
votes
2 answers

Telegram bot sendMessage problem. Parse_mode='HTML' is not working

I want to send a message from Telegram Bot to user with parse_mode 'HTML' . I use node.js with telegram.bot.api. But I've got an error I've tried to write a code without parse_mode='HTML'. And it is working. But if I only add parse_mode=''(html or…
Paul Helios
  • 43
  • 1
  • 1
  • 3
4
votes
2 answers

Method editMessageReplyMarkup removes inline keybord

I am making a telegram bot using node.js and node-telegram-bot-api library. I answer on callback_query and want to change my inline keybord. The code below shows how I am trying to use this method, but when I tap on keyboard in telegram, it just…
ExsaNik
  • 143
  • 2
  • 10
3
votes
0 answers

How to get chat history of Telegram using node-telegram-bot?

I am developing a telegram chatbot using node-telegram-bot in Node.js that requires getting the previous messages or chat history of user and bot. I tried using bot.getChat(chatId) method but it returns the following response { id: , first_name:…
Dummy Cron
  • 143
  • 2
  • 11
3
votes
0 answers

call back query send duplicate messages node-telegram-bot-api

Whenever inline button clicked by user call back query send duplicate messages so what type of changes I need to do to bot not send duplicate messages. var keyboard = []; movieRatingList.map((movie, idx) => { var movieRating =…
3
votes
2 answers

Why do I get a 400 error when i'm trying to edit an inline keyboard (node-telegram-bot-api)?

I am making a message with a simple inline keyboard. The expected result would be that when I click on the button it changes together with the message text. However the button doesn't change and i get this error: TelegramError: ETELEGRAM: 400 Bad…
3
votes
1 answer

node-telegram-bot-api / How to get user message on a question?

So, i'm actually tired to find any asks about that... I need to get user message only after bot question and nowhere else like: bot: What is your name? user: Oleg bot: Hi, Oleg how it should work I am also using require system with…
saykono
  • 31
  • 1
  • 2
1
2 3
10 11