nmlorg / metabot

Modularized, multi-account bot.
https://metabot.readthedocs.io/
5 stars 0 forks source link

"Bad Request: message is not modified" during 12:20 `periodic` run #109

Open nmlorg opened 3 months ago

nmlorg commented 3 months ago

I am very puzzled by the situation that actually triggered #108.

At 12:10 a.m., the bot edited a group's message 1991 successfully. I don't have a record of the text it recorded in daily.pickle, the text it sent, nor the text sent back to it from Telegram.

At 12:20 a.m., the bot attempted to edit message 1991 again, but Telegram rejected the edit because the text was identical to the message's current text:

ntelebot.errors.Error: {'ok': False, 'error_code': 400, 'description': 'Bad Request: message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message'}

The bot did log the text it tried to send, and it included a time string "🔜 ¹⁵ʰ⁴⁰ᵐ Fri 9ᵗʰ, 6–8ᵖᵐ", which would be appropriate for an announcement generated at 12:20 a.m. Pacific for an event at 6 p.m. Central time.

I am not in the group that the announcement was sent to, but a member forwarded the message and it currently does include the string "🔜 ¹⁵ʰ⁴⁰ᵐ Fri 9ᵗʰ, 6–8ᵖᵐ".

According to the logs, I think this would have to mean that at 12:10 the bot sent the countdown for 12:20 (suggesting something to do with the period-start calculation is broken), and either didn't update daily.pickle or stored different text than what it actually sent.

But that seems really far fetched.

My best guess right now is that the bot sent (and recorded) the correct countdown at 12:10 (which would be 15h50m), then the 12:20 edit (with 15h40m) did go through, but Telegram returned a "message is not modified" anyway (giving me oncall2calendar flashbacks).

nmlorg commented 3 months ago

The error comes from:

https://github.com/tdlib/telegram-bot-api/blob/12bbe26692b8c6e347aaf3e32e0e9d11b86bb56d/telegram-bot-api/Client.cpp#L89-L92

    if (error_message == "MESSAGE_NOT_MODIFIED") {
      error_message = td::Slice(
          "message is not modified: specified new message content and reply markup are exactly the same as a current "
          "content and reply markup of the message");

and:

$ grep -r MESSAGE_NOT_MODIFIED
telegram-bot-api/telegram-bot-api/Client.cpp:    if (error_message == "MESSAGE_NOT_MODIFIED") {
td/td/telegram/MessagesManager.cpp:    if (!td_->auth_manager_->is_bot() && status.message() == "MESSAGE_NOT_MODIFIED") {
td/td/telegram/QuickReplyManager.cpp:    if (status.message() == "MESSAGE_NOT_MODIFIED") {
td/td/telegram/PollManager.cpp:    if (!td_->auth_manager_->is_bot() && status.message() == "MESSAGE_NOT_MODIFIED") {
td/td/telegram/MessageReaction.cpp:    if (status.message() == "MESSAGE_NOT_MODIFIED") {

where:

https://github.com/tdlib/td/blob/81dc2e242b6c3ea358dba6b5a750727c378dc098/td/telegram/MessagesManager.cpp#L3528-L3541

  void on_error(Status status) final {
    if (status.code() != 403 && !(status.code() == 500 && G()->close_flag())) {
      LOG(WARNING) << "Failed to edit " << MessageFullId{dialog_id_, message_id_} << " with the error "
                   << status.message();
    } else {
      LOG(INFO) << "Receive error for EditMessageQuery: " << status;
    }
    if (!td_->auth_manager_->is_bot() && status.message() == "MESSAGE_NOT_MODIFIED") {
      return promise_.set_value(0);
    }
    td_->messages_manager_->on_get_message_error(dialog_id_, message_id_, status, "EditMessageQuery");
    promise_.set_error(std::move(status));
  }
};

so it appears to originate somewhere inside Telegram itself.