G
G
Grigory Zhovtun2021-03-15 12:25:14
Google Apps Script
Grigory Zhovtun, 2021-03-15 12:25:14

Google Apps Script Telegram Bot editing old messages?

I'm trying to save the id and text of the message to a global variable.
I want to have access to them later to edit
Here is the code:

let id_messages = {};

function doPost(e) {
    const contents = JSON.parse(e.postData.contents);
    const key = contents.message.from.id;
    const value = contents.message.message_id;
    id_messages[key] = value;

    switch (contents.message.text) {
      case "/start":
        id_messages.forEach(item => {
          bot.sendText(contents.message.from.id, item);
        });
        break;
}


In theory, the doPost function is constantly called and new messages should get into the id_messages variable, but in fact only the most recent one is stored there.

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question