node-red-contrib-telegrambot icon indicating copy to clipboard operation
node-red-contrib-telegrambot copied to clipboard

editMessageText documentation/proper message handling

Open grahamPegNetwork opened this issue 5 years ago • 1 comments

Hello, I spent a couple of hours digging through github issues, documentation, and testing before bringing this to an issue. I was looking for a way to call editMessageText, and it definitely does not behave how I would expect it to.

My expectation would be to somewhat mirror the API being wrapped and should be able to be set up in a function node something like this:

msg.payload={};
msg.payload.type = "editMessageText";
msg.payload.chatId=1122334455;
msg.payload.messageId=88
msg.payload.text="Hello world";
return msg;

The key data being the type editMessageText, a chatID, messageId, and text to update.

Per issue #75 (deleting messages) I discovered that "Msg.payload.content should be the messageId to delete. " which is rather neither intuitive nor documented. I tested by using msg.payload.content for the messageId, however that also did not work.

Finally, by browsing the source code, brute force testing, and seeing the error messages being passed back, I discovered that the only way to get editMessageText to work was to put the chatId (chat_id) both into the payload, as well as the options. If this value is not in both locations, the call throws an error.

My final function is as follows:

msg.payload={};
msg.payload.options = {};
msg.payload.type = "editMessageText";
msg.payload.chatId=1122334455;
msg.payload.options.chat_id=msg.payload.chatId;
msg.payload.options.message_id=88;
msg.payload.content="Abcdefghij";

return msg;

My suspicion is that error handling requires the chatId in the payload, while the underlying API library requires it in the options.

Please review, consider adjusting, and at minimum update the documentation to reflect the fact that the chat ID is required in two locations. Ideally allow the options to pull the chatId from the payload above.

grahamPegNetwork avatar Jan 12 '21 06:01 grahamPegNetwork

Yes that is a flaw in the design ... I will try to change this so that you only nee to set chatId once.

windkh avatar Jan 19 '21 15:01 windkh