S
S
Sergey2019-03-08 20:43:36
JavaScript
Sergey, 2019-03-08 20:43:36

How to change one message in different Telegram bot chats?

There is a bot for placing orders. All orders come to managers in the same bot.
It is necessary to make it so that when a message about a new order arrives, by clicking on the "accept" button for all people who received this message, this button disappears and the status changes.
Example:
before pressing
5c82a94bb5b09121935549.png
after pressing
5c82a971ddba0000914802.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Somewhere Intech, 2019-03-09
@john36allTa

chat_id as I understand one, so keep the message_id until someone takes the order. Next, call editMessageText chat_id message_id and the desired text
upd... If the chats are different, you can implement it in a similar way:

var Offer = function(_chats, _task){
  this.sendedTo = [];
  this.user = '';
  this.task = _task;
  this.tMsg = `Заказ #${_task.id}\n${_task.info}\nСтоимость: ${_task.cost}`;
  for (chat of _chats){
    bot.sendMessage({
      chat_id: chat,
      text: this.tMsg,
      reply_markup: {
        text: 'беру',
        callback_data: _task.id
      }
    }).then((result)=>this.sendedTo.push({id: result.chat, msg: result.message_id}));
  }
}
bot.addUpdateListener((upd)=>{
  function offerComplete(chat, msg){
    bot.editMessageText({
      chat_id: chat.id,
      message_id: chat.msg,
      text: msg,
      reply_markup: null
    });
  }
  if ('callback_data_id' in upd){
    if (let offer = offers.find(i=>i.task.id === upd.data)){
      if (offer.user === '' || upd.time < offer.time){
        offer.user = upd.from.id;
        offer.time = upd.time;
        db.updateOfferInfo({telegramUserId: upd.from.id});
        let msg = `\nЗаказ принял: @${upd.from.username}`;
        if (/Заказ принял/i.test(offer.tMsg)) offer.tMsg=offer.tMsg.replace(/Заказ принял:\[email protected]*/i, msg);
        else offer.tMsg += msg; 
        for (chat of offer.sendedTo){
          offerComplete(chat, offer.tMsg);
        }
      }
      else {
        let chat = offer.sendedTo.find(i=>i.id === upd.chat);
        offerComplete(chat, offer.tMsg);
      }
    }
  }
});

var offers = [];
offers.push(new Offer([
    ...chats_id
  ],{
    info: "Some offer for sales",
    cost: 1000,
    id: id_from_db
  }));

it is obvious that the implementation of the bot is not known to me, so I wrote according to api.telegram

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question