RocketChat / Rocket.Chat.Apps-engine

The Rocket.Chat Apps engine and definitions.

Home Page:https://rocketchat.github.io/Rocket.Chat.Apps-engine/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Update Message requires `room`

juzser opened this issue · comments

Hi,
I'm not sure it's a bug or not but I get this error when I tried to update the message:

Apps-Engine version: 1.12.1#master
Rocket.Chat server: 3.1.0

[
  "{\"stack\":\"Error: The \\\"room\\\" property is required.
    at MessageBuilder.getMessage (/opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine/server/accessors/MessageBuilder.js:121:19)
    at ModifyUpdater._finishMessage (/opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine/server/accessors/ModifyUpdater.js:53:32)
    at ModifyUpdater.finish (/opt/Rocket.Chat/programs/server/npm/node_modules/@rocket.chat/apps-engine/server/accessors/ModifyUpdater.js:45:29)
    at Object.updateMessage (evalmachine.<anonymous>:58:42)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Object.StartCommand (evalmachine.<anonymous>:60:9)
    at DutyCommand.executor (evalmachine.<anonymous>:44:17)\",\"message\":\"The \\\"room\\\" property is required.\"}"
]

Here is my updateMessage helper:

export async function updateMessage({ app, modify, messageId, sender, message, attachments, blocks }: {
    app: appClass,
    modify: IModify,
    messageId: string,
    sender: IUser,
    message?: string,
    attachments?: Array<IMessageAttachment>,
    blocks?: BlockBuilder,
}): Promise<void> {
    const msg = await modify.getUpdater().message(messageId, sender);
    msg.setEditor(msg.getSender());

    if (message && message.length > 0) {
        msg.setText(message);
    }
    if (attachments && attachments.length > 0) {
        msg.setAttachments(attachments);
    }
    if (blocks !== undefined) {
        msg.setBlocks(blocks);
    }

    try {
        return await modify.getUpdater().finish(msg);
    } catch (error) {
        app.getLogger().log(error);
        return;
    }
}

Maybe because the message was removed?

Yes, this might be the case. Actually, if the getUpdater method is not able to find any message with the messageId provided, this error is going to occur internally.

The error happens in the MessageBuilder.getMessage method, which validates the basic information needed for a message to be valid.

I'll be closing this one. If you think this is still an issue, feel free to reopen :)