cotestatnt / AsyncTelegram2

Powerful, flexible and secure Arduino Telegram BOT library. Hardware independent, it can be used with any MCU capable of handling an SSL connection.
MIT License
83 stars 25 forks source link

Adding a delete message method #107

Closed MicDG closed 1 year ago

MicDG commented 1 year ago

Hello, just wondering if something like this could be added to delete a message:

bool AsyncTelegram2::deleteMessage(const TBMessage &msg)
{
    char payload[BUFFER_SMALL];
    snprintf(payload, BUFFER_SMALL,
        "{\"chat_id\":%lld,\"message_id\":%" INT32 "}",
        msg.chatId, msg.messageID);

    const bool result = sendCommand("deleteMessage", payload);
    log_debug("%s", payload);
    return result;
}

Thank you very much!

cotestatnt commented 1 year ago

Hi @MicDG In order to delete a message you need two things as I assume you have already checked:

With that method you will be able to delete just in case you are replying to a received message you. So I think it would be better defining something more "general" and then ovverride the method:

bool AsyncTelegram2::deleteMessage(const char* chatId, const char* messageId)
{
    char payload[BUFFER_SMALL];
    snprintf(payload, BUFFER_SMALL,
        "{\"chat_id\":%lld,\"message_id\":%" INT32 "}",
         chatId, messageId);

    const bool result = sendCommand("deleteMessage", payload);
    log_debug("%s", payload);
    return result;
}

bool AsyncTelegram2::deleteMessage(const TBMessage &msg) 
{
    return deleteMessage(msg.chatId, msg.messageID);
}
MicDG commented 1 year ago

That makes sense, should I make a pull request to add it to the library?

cotestatnt commented 1 year ago

Yes, if you can.

Otherwise I will add in the next release.