Error occurs, trying to update message using IMessageBuilder.setData() method
murtaza98 opened this issue · comments
When trying to update an existing message something like this:
const msgBuilder = (await this.modify.getUpdater().message(msgId, sender)).setData(newMessage);
await this.modify.getUpdater().finish(msgBuilder);
I'm getting an error saying
Error: Invalid message, can't update a message without an id.
at ModifyUpdater._finishMessage (/home/murtaza/github_repo/RocketChatRepos/Rocket.Chat/node_modules/@rocket.chat/apps-engine/server/accessors/ModifyUpdater.js:55:19)
at ModifyUpdater.finish (/home/murtaza/github_repo/RocketChatRepos/Rocket.Chat/node_modules/@rocket.chat/apps-engine/server/accessors/ModifyUpdater.js:45:29)
at PostMessageSentHandler.run (evalmachine.<anonymous>:87:48)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at D360Integration.executePostMessageSent (evalmachine.<anonymous>:22:9)
From what I understand, the IMessageBuilder class is deleting the id
from the message object passed here(when we call IMessageBuilder.setData() method).
This behaviour is valid if we are creating an message bcs the message id is generated on server, however in case of update we don't need to delete it.
I am not sure how to fix this, any suggestions?
Hi, @murtaza98!
Thanks for pointing and detailedly describing this issue. In order to fix it, we have just added the setUpdateData
method in the MessageBuilder
, which allows you to do the same as the setData
method, but it keeps the message's ID so that you can use the ModifyUpdater
object to update the message later.
Thus, you will be able to fix this error by calling the setUpdateData
method (which also requires you to inform which user updated the message) instead of the setData
method.
I suggest you to keep track of the pull request #364.
Great! Thanks