windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
264 stars 117 forks source link

chatId when editing threaded message #306

Closed PeterHunt closed 1 year ago

PeterHunt commented 1 year ago

Hi Karl,

I recently started using threaded groups with your Telegram BOT.

When I send a message to a thread, I can use :

        msg.payload.chatId = 123456789;
        msg.payload.options.message_thread_id = 123;

When I want to edit a message, the chatId property does not seem to be valid.

For now, I've managed to edit the message via:

        msg.payload.chatId = 123456789;
        msg.payload.options.chat_id = 123456789;
        msg.payload.options.message_thread_id = 123;
        msg.payload.options.message_id = 37;

To be honest, I'm not sure whether both chatIds are necessary, but as I said, this seems to be working.

Can you please test this? I'm not sure if this is as expected? I would expect, like posting a message, editing would be like:

        msg.payload.chatId = 123456789;
        msg.payload.options.message_thread_id = 123;
        msg.payload.options.message_id = 37;

Kind regards,

Peter Hunt.

PeterHunt commented 1 year ago

Hello Karl-Heinz,

Sorry to bother you, but did you manage to check/reproduce this issue maybe?

windkh commented 1 year ago

Maybe after vacation sry

PeterHunt commented 1 year ago

No problem. Be sure to enjoy your holiday :) I was just wondering because you did not reply. Take your time and please allow me to buy you a beer in stead of a coffee :)

windkh commented 1 year ago

Hehe... thanks alot!

windkh commented 1 year ago

So what are you using "editMessageText" or "editMessageCaption" or "editMessageReplyMarkup" or "editMessageMedia"?

PeterHunt commented 1 year ago

msg.payload.type = 'editMessageText';

windkh commented 1 year ago

In case of "editMessageText" you can have a look here: https://core.telegram.org/bots/api#editmessagetext

Only text is a required property, but as you can read in the documentation you can pass chat_id, message_id, ... as optional parameters.

The explanation of chat_id says: "Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)"

windkh commented 1 year ago

I know that this is weird, but the underlying lib implemented it like this:

/**

PeterHunt commented 1 year ago

I know, I just wanted to point out that behaviour is not as expected. But, it's working for me. So actually, I have no issue (no more). I was just wondering if this is as it should be?

In one situation I use

msg.payload.chatId = 123456789;

In the other

msg.payload.options.chat_id = 123456789;

No problem for me, though. It was more a heads up than an issue.

windkh commented 1 year ago

msg.payload.content is the first parameter and msg.payload.options is the second one for the lib.

msg.payload.chatId however is used by the node itself for all kind of functions like sendMessage, forwardMessage, copyMessage,... as far as I can see this is not used in editMessageText.

I know this is a little bit inconsistent, but don't ask me why it was implemented like that. So in you case you do not really need msg.payload.chatId when calling editMessageText

windkh commented 1 year ago

The same goes for editMessageCaption, editMessageReplyMarkup, editMessageMedia stopMessageLiveLocation, editMessageLiveLocation

Maybe I should extend the table in the readme by adding an additional column that indicates whether msg.payload.chatId is required or not

PeterHunt commented 1 year ago

Oke, clear now. I thought this 'oddity' was in your telegrambot. But in fact it's due to the lib. Maybe an addition to the table makes it more clear. It took me some time to figure out, but eventually I managed :)

windkh commented 1 year ago

I will adapt the code in a way that the code will work as you expected it. msg.payload.chatId will be copied to the options.chat_id

You are not the first one who had troubles with that pitfall