S
S
S10LI2021-02-16 11:34:44
JavaScript
S10LI, 2021-02-16 11:34:44

How to send a message from a group to a person who wrote a bot in Telegram?

Good afternoon. I'm not a programmer at all, but I'm trying to make a simple bot for a client to communicate with a supergroup.

The bot is written on node-telegram-bot-api

There is a bot. There is a supergroup. Bot added to it

Here is part of the code

const fwdId = #ID СУПЕРГРУППЫ#;
const first_name = msg.chat.first_name;

bot.on('message', (msg) => {
  const chatId = msg.chat.id;
   if (msg.text) {
    const text = msg.text.toLowerCase();
        if (~text.indexOf("привет")) {bot.sendMessage(chatId, 'Привет, ' + first_name + '!');}
        else if (~text.indexOf("start")) {}
        else (chatId != fwdId) {bot.forwardMessage(fwdId, chatId, msg.message_id);}
  }
});


When a user writes a message to the bot that does not match any condition, the message is sent to the supergroup. It works without problems

. How can I make the bot send a message back to the user if someone in the supergroup Replied (highlighted the message and clicked "Reply") to this message?

I saw a similar implementation in this bot, but just taking it and using it does not suit me

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2021-02-16
@Kozack

Checking what

  1. The message was in a supergroup
  2. The message has a reply_to_message field. This property stores the original message.

A
Alex K, 2021-02-16
@alexk111

If not a programmer, then here is a ready-made thread for the Botodrome that implements this logic.
1. Import the JSON code from the window below into your Botodrome
2. In the settings of the "My Telegram Bot" config node, set the token of your Telegram bot
3. In the "Supergroup Id" node, set the id of your supergroup where the messages coming to the bot will be forwarded
4 .Click Expand
5. Then click the Configure Storage node button
6. Done
602b93d6be8ac408845624.png

[{"id":"20fc1f49.0ac97","type":"drom-tg-updates","z":"816191d5.cb781","name":"","method":"longpoll","property":"tgUpdate","client":"8ab3ffbd.097a1","x":440,"y":320,"wires":},{"id":"581f6191.a03c4","type":"drom-tg-switch-update","z":"816191d5.cb781","name":"Какое событие?","tgUpdate":"tgUpdate","property":"tgUpdateObj","updates":["message"],"outputs":1,"x":770,"y":320,"wires":},{"id":"9a5462b0.20203","type":"drom-tg-api-call","z":"816191d5.cb781","name":"Форвард сообщения","data":"apiData","dataType":"msg","method":"forwardMessage","methodType":"str","property":"apiRes","client":"8ab3ffbd.097a1","x":1400,"y":300,"wires":},{"id":"1f5ca683.997369","type":"change","z":"816191d5.cb781","name":" Id супергруппы","rules":[{"t":"set","p":"apiData.chat_id","pt":"msg","to":"-123456","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1390,"y":220,"wires":},{"id":"f1b47a6d.c871d8","type":"switch","z":"816191d5.cb781","name":"Сообщение в личку Боту?","property":"tgUpdateObj.from.id","propertyType":"msg","rules":[{"t":"eq","v":"tgUpdateObj.chat.id","vt":"msg"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":1100,"y":320,"wires":,"outputLabels":["Да","Нет"]},{"id":"63e53df1.7d73a4","type":"drom-tg-api-call","z":"816191d5.cb781","name":"Отправка ответа","data":"apiData","dataType":"msg","method":"sendMessage","methodType":"str","property":"payload","client":"8ab3ffbd.097a1","x":1690,"y":420,"wires":},{"id":"6c4344ad.334b9c","type":"change","z":"816191d5.cb781","name":"Данные tg api","rules":[{"t":"set","p":"apiData.chat_id","pt":"msg","to":"message_sender[0].value2","tot":"msg"},{"t":"set","p":"apiData.text","pt":"msg","to":"tgUpdateObj.text","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1680,"y":380,"wires":},{"id":"a2ffad93.bc7eb","type":"change","z":"816191d5.cb781","name":"Данные tg api","rules":[{"t":"set","p":"apiData.from_chat_id","pt":"msg","to":"tgUpdateObj.from.id","tot":"msg"},{"t":"set","p":"apiData.message_id","pt":"msg","to":"tgUpdateObj.message_id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1380,"y":260,"wires":},{"id":"7e643f.62614bc","type":"drom-data-relationships-num","z":"816191d5.cb781","storage":"6c999ed1.7d41f","action":"setup-rels","rels":"message_sender","relsType":"storId","value1":"inviter","value1Type":"msg","value2":"invitee","value2Type":"msg","value1Req":"inviter","value1ReqType":"msg","value2Req":"invitee","value2ReqType":"msg","limitRes":"20","limitResType":"num","offsetRes":"0","offsetResType":"num","name":"","property":"payload","x":800,"y":140,"wires":},{"id":"f553b75.a386048","type":"inject","z":"816191d5.cb781","name":"Настроить хранение данных","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":460,"y":140,"wires":},{"id":"d700d74.3b99228","type":"drom-data-relationships-num","z":"816191d5.cb781","storage":"6c999ed1.7d41f","action":"add","rels":"message_sender","relsType":"storId","value1":"inviter","value1Type":"msg","value2":"invitee","value2Type":"msg","value1Req":"apiRes.message_id","value1ReqType":"msg","value2Req":"tgUpdateObj.from.id","value2ReqType":"msg","limitRes":"20","limitResType":"num","offsetRes":"0","offsetResType":"num","name":"Добав в message_sender","property":"payload","x":1710,"y":260,"wires":},{"id":"7b7d959c.a503ac","type":"switch","z":"816191d5.cb781","name":"Ответ?","property":"tgUpdateObj","propertyType":"msg","rules":[{"t":"hask","v":"reply_to_message","vt":"str"}],"checkall":"false","repair":false,"outputs":1,"x":1160,"y":380,"wires":,"outputLabels":["Да"]},{"id":"3c811c29.b17d74","type":"drom-data-relationships-num","z":"816191d5.cb781","storage":"6c999ed1.7d41f","action":"get","rels":"message_sender","relsType":"storId","value1":"tgUpdateObj.reply_to_message.message_id","value1Type":"msg","value2":"","value2Type":"undef","value1Req":"apiRes.message_id","value1ReqType":"msg","value2Req":"tgUpdateObj.from.id","value2ReqType":"msg","limitRes":"","limitResType":"undef","offsetRes":"0","offsetResType":"num","name":"Найти в message_sender","property":"message_sender","x":1410,"y":380,"wires":},{"id":"ed52d334.5457c","type":"switch","z":"816191d5.cb781","name":"Есть?","property":"message_sender","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"false","repair":false,"outputs":1,"x":1470,"y":420,"wires":,"outputLabels":["Да"]},{"id":"35df003b.499d4","type":"comment","z":"816191d5.cb781","name":"Настройка","info":"","x":400,"y":100,"wires":[]},{"id":"8ab3ffbd.097a1","type":"drom-tg-api-config","name":"Мой Telegram Бот"},{"id":"6c999ed1.7d41f","type":"drom-data-config","name":"","dbType":"sqlite","sqliteFile":"my-data.sqlite"}]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question