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

Why does a telegram bot every time send a photo to channel as many times as the Upload Photo button was pressed?

If you press the Upload Photo button once, the bot will send the photo 1 time. But, if u press this button more than 1 times, photo will be sent to u as many times as this button was pressed earlier. Including the number of clicks before previous…
-1
votes
1 answer

create button 'copy' telegram api

I am creating a simple telegram bot. I send a message from the server: https://api.telegram.org/bot{API_KEY}/sendMessage?chat_id={CHAT_ID}&text={TEXT_MESSAGE} I would like to attach a button to it, when clicked, a certain link would be copied to the…
-1
votes
1 answer

Run node.js app from html by pressing a button

I made a telegram bot in node js and I would like to be able to start it by pressing a button from an html page, how can I do it? also I would like that even after the web page is closed, the bot continues to work. To run the bot from the console I…
-1
votes
1 answer

How do I convert this chained promises code with callback to async/await

How do I convert this chained promises code with callback to async/await I have no idea on how to go about converting this code to async/await so that its more readable var responseCallbacks = {}; bot.onText(/\/something/, async (msg) => { var…
-1
votes
1 answer

Nested element object

I would to navigate inside json to parsing json'data'. I tried to use JSON Stringfy but nothing. Another i would to navigate inside data to parse 'hometeam' for example. Thank you for your eventually help var TelegramBot = require…
-1
votes
1 answer

How can I take some messages from a Telegram channel, change something and forward it?

I want take some messages from a Telegram channel (not mine), change something (not filter but for example modify some words) and forward the message changed to other channels (mine or not). I would like to see some structured code to start (NodeJS…
Antonio
  • 11
  • 1
-2
votes
1 answer

How to get chat id in telegram bot without message from user? Is it even real?

I am making a telegram bot who will work like schedule and it is deployed on heroku. When server is restarting, chat id is clearing and the bot is not working So I have a question. Can I somehow get chat id without user message? And is it even real?
-2
votes
2 answers

Telegram bot analytics

I have checked telegram bot api web but could not find analytics api for bot, is telegram provide analytics api for bots, if yes any one have reference it will helps me a lot
-4
votes
1 answer

tow message send to telegram bot (Same Time)

I am making a contest bot. I have a problem. When the user sends the answer to the question in one breath, it gives a point to both users and repeat next question. I want a point to be calculated for the one with the fastest answer. Thank you click…
1 2 3
10
11