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

How to make Telegram BOT reply to a specific message?

I would like to make my BOT reply to a specific message like this: I am using the "reply_to_msg_id" with the ID of the message to replies to, but it doesn't work. Anyone can help me? Thanks in advance, Giacomo
0
votes
1 answer

Can I extract and automatically message users on a TG group?

I’m part of a telegram group. I can see other users on the group, and I can message them individually (and manually). Is it possible to automatically (programmatically) message all the users on the group individually? Note I am not the admin. If it…
0
votes
1 answer

Is it possible for a telegram bot that is an “admin” of a channel to make a user of a channel an admin?

I have a telegram bot that asks a channel user a certain set of questions. Based on these answers, I would like that user to automatically become the admin of the telegram channel. Is that possible?
0
votes
1 answer

Can a Telegram bot create a survey on a channel?

I’m looking to allow members of a TG channel to generate their own surveys and have the bot post those surveys to the channel. Is this possible? As an extension to this, would it be possible to have the results (votes, not identities) of the survey…
0
votes
1 answer

Node.js Telegram bot can't kick user from supergroup

I'm trying to create a logic system to kick a username from a private supergroup. But, when function is running I'm returning: Api error: Body: { ok: false, error_code: 400, description: 'Bad Request: wrong user_id specified' } (node:11272)…
0
votes
2 answers

Node giving error "internal/modules/cjs/loader.js:638" - Telegraf - Telegram bot api - Windows

I recently downloaded and installed Telegraf - telegram bot api. It works with Node.js. I looked at 17 sites, including github, and did not find a solution for myself. Here is the error: node .\src\bot.js internal/modules/cjs/loader.js:638 throw…
hitman47
  • 237
  • 2
  • 14
0
votes
0 answers

Update message in Telegram bot

I'm getting familiar with Telegram API and wondering if there is any possibility to update a button title on a message from bot after a user licks on it? Here is my code example: const TelegramBot = require('node-telegram-bot-api'); // Insert token…
0
votes
3 answers

Why is a new instance of a object undefined?

I am unable to use the same instance of an object in another java-script file using nodejs. I'm working on a bot for telegram. Because the file gets large and chaotic, i would like to split the functions of my bot into a few extra js files. But i…
Drake
  • 33
  • 6
0
votes
2 answers

How to make a bot responding once if an user sends more than one photo at the same time?

I'm developing a Telegram bot in nodejs. I create an instance of node-telegram-bot-api and I'm using the method on('photo') to manage if a user sends a photo to my bot. The problem is when a user sends more than one photo together by multi selecting…
0
votes
0 answers

Can someone explain me how can I access a variable value when I'm inside a callback function?

I have this function which is called whenever a user types "/play" or "/register" to the bot and it's used for querying the database if the user has already his data store in the database or not. I'm trying to make this function return true or false…
0
votes
1 answer

Update menu in telegram bot

I have a bot that he only show the user a menu. Written using node-telegram-bot-api. I have updated the links in the menu and I want to update all the users to the new menu without clicking "start" again. I tried resetting the bot and deleting…
Sagiw
  • 75
  • 1
  • 14
0
votes
2 answers

In webhook what is has_custom_certificate: false?

I have a teegram bot that has an issue because send many times same message. Maybe because bot don't say to telegram the first operation is correct. Is really slowly and so telegram send again message. I'm tring to understand the reason but…
0
votes
1 answer

Telegram Bot EditMessageReplayMarkup Error (Nodejs)

I want to change my InlineKeyboard buttons when i press another button but I keep getting this error. TypeError: Cannot create property 'reply_markup' on number '750548132' 2019-04-13T06:42:14.374318+00:00 app[web.1]: at…
0
votes
3 answers

Node.js - Insert into adds 0 instead of string

I am trying to insert some data with node.js. I installed MySQL support via npm, but It still seems to fail to input the right strings with INSERT INTO. (the row types in the database are tinytext and the strings are smaller then 255…
0
votes
1 answer

Telegram bot and CouchDB insert new user to DB

How Can I insert New Telegram Bot user to CouchDB? I inserted a Sample Data jack johnsin db and was ok, But I Don't Know How Should I Take Telegram users Username and Put That in Db. This is My Code: import 'babel-polyfill'; import './env'; import…
Saeed Heidarizarei
  • 8,406
  • 21
  • 60
  • 103
1 2 3
10
11