Open tomi229 opened 1 year ago
Hi @tomi229 I will check as soon as possible.
@tomi229 I am also having trouble but I attempted to use the function differently than you. Notice (near the end of my code snippet) that I have an additional parameter in editMessage() because I tried to follow the structure in AsyncTelegram2.h. I am keenly awaiting updates about this from @cotestatnt!
Serial Monitor output from running my code example:
Button pressed Starting message messageID: 0 CallbackQuery received: /updateInlineKb2 messageID: 1008 edit messageID 1007 Button pressed Starting message messageID: 1008 CallbackQuery received: /updateInlineKb2 messageID: 1009 edit messageID 1008 CallbackQuery received: /updateInlineKb2 messageID: 1009 edit messageID 1008
//AsyncTelegram2.h
// Edit a previous sent message
// params:
// chat_id: the iD of chat
// message_id: the message ID to be edited
// txt: the new text
// keyboard: the new inline keyboard (if present)
// return:
// true if success
bool editMessage(int32_t chat_id, int32_t message_id, const String &txt, const String &keyboard);
inline bool editMessage(const TBMessage &msg, const String &txt, const String &keyboard)
{
return editMessage(msg.chatId, msg.messageID, txt, keyboard);
}
inline bool editMessage(int32_t chat_id, int32_t message_id, const String &txt, InlineKeyboard &keyboard)
{
return editMessage(chat_id, message_id, txt, keyboard.getJSON());
}
inline bool editMessage(const TBMessage &msg, const String &txt, InlineKeyboard &keyboard)
{
return editMessage(msg.chatId, msg.messageID, txt, keyboard.getJSON());
}
//My code which is a revision of the example program "AsyncTelegram2/keyboards"
//There is more code which I have left out. This is the important part and it's triggered by pressing a button.
InlineKeyboard kb1;
InlineKeyboard kb2;
void addKeyboards()
{
kb1.addButton("First text", "/updateInlineKb2", KeyboardButtonQuery);
kb2.addButton("Updated text", "/bogusCommand", KeyboardButtonQuery);
kb2.addButton("third text", "/bogusCommand2", KeyboardButtonQuery);
}
void buttonPress()
{
myBot.sendMessage(msg, "Starting message", kb1);
Serial.print("Starting message messageID: ");
Serial.println(msg.messageID);
}
void asyncGetMessage()
{
if (myBot.getNewMessage(msg))
{
MessageType msgType = msg.messageType;
String msgText = msg.text;
switch (msgType)
case MessageQuery:
msgText = msg.callbackQueryData;
Serial.print("CallbackQuery received: ");
Serial.print(msg.callbackQueryData);
Serial.print(" messageID: ");
Serial.println(msg.messageID);
if (msgText.equalsIgnoreCase("/updateInlineKb2"))
{
setRed();
myBot.editMessage(msg.chatId, (msg.messageID - 1), "updated", kb2);
Serial.print("edit messageID ");
Serial.println(msg.messageID - 1);
}
}
}
I'm sorry for late reply, but in last months I was very busy and I hadn't free time to dedicate at this library.
I've checked and fixed a lot of things with latest commits and release.
The issue which was related to editMessage()
was really dumb!
The chat ID is a int64 data type, but the method was defined with int32 data type. This cause the chat id to be a wrong number :(
@cotestatnt This fixed it! Thank you so much for the incredibly fast turnaround! It was fantastic to watch the inline keyboard and its associated caption message all transform into a new message!
@cotestatnt I am not a programmer. However, I did a half-approach at extending your library to include the deleteMessage() Telegram API function. I edited the asyncTelegram2.cpp and asyncTelegram2.h files by copying and adapting the editMessage() functions, below. I invoke my function like this:
void deleteLastMessage()
{
myBot.deleteMessage(msg.chatId, msg.messageID);
msg.messageID++;
Serial.print("deleteMessage ID:");
Serial.println(msg.messageID);
}
asyncTelegram2.cpp addition:
bool AsyncTelegram2::deleteMessage(int64_t chat_id, int32_t message_id)
{
DynamicJsonDocument root(m_JsonBufferSize);
root["chat_id"] = chat_id;
root["message_id"] = message_id;
root.shrinkToFit();
String payload;
serializeJson(root, payload);
return sendCommand("deleteMessage", payload.c_str());
}
asyncTelegram2.h addition:
bool deleteMessage(int64_t chat_id, int32_t message_id);
If this is helpful to you, please feel free to use this to clean up and implement my addition!
I am making a controller to make my washing machine and clothes dryer become smart appliances. The controller sends a Telegram message and then, through a combination of messageDelete() and editMessage() replies, I send updated message captions with dynamic buttons. This creates a sort of simple UI app to get 1) Phone notifications. 2) One button interaction. 3) Automatically rescheduling reminder messages are updated by menu button tap.
The controller can detect appliance status by looking for the Power light and Done lights to illuminate. Messages send the minimum amount of information necessary to control with minimal interaction but while still being easily+sufficiently understood to inform the interaction. The deleteMessage() function is necessary for generating new phone notifications while outside the Telegram app. This was all too much for the UniversalTelegramBot library so your async library has been very helpful. I use the flashing LED "busy" routine as a status indicator by alternating between two sets of RGB colors. This has been very useful during development.
Again, my thanks to you!
I will add soon, thanks!
editMessage() command doesn't seem to do anything. This is the test code I used: