RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.77k stars 10.71k forks source link

UpdateMessage does not work when updates are only in attachments #14098

Open tomonorisugiura opened 5 years ago

tomonorisugiura commented 5 years ago

Description:

I use updateMessage via Rocket.Chat.sdk to update existing message. A message has text in msg field with 1 button. If I try to add 2nd button to the message without updating text in msg filed, nothing to occur.

Steps to reproduce:

I created an example code.

const { Message }  = require('@rocket.chat/sdk/dist/lib/message');
const random = require('meteor-random');

const { driver } = require('@rocket.chat/sdk');
// customize the following with your server and BOT account information
const HOST = 'hostname:port';
const USER = 'username';
const PASS = 'password';
const SSL = false;  // server uses https ?
const ROOMS = ['GENERAL'];

var myuserid;
// this simple bot does not handle errors, different message types, server resets 
// and other production situations 

const runbot = async () => {
    const conn = await driver.connect( { host: HOST, useSsl: SSL})
    myuserid = await driver.login({username: USER, password: PASS});
    const roomsJoined = await driver.joinRooms(ROOMS);
    console.log('joined rooms');

    const generalRoomId = await driver.getRoomId('GENERAL');

    const messageAttachments = {
        color: 'good',
        text: 'attachment text',
        button_alignment: 'horizontal',
        actions: [{
            type: 'button',
            name: 'TEST',
            text: 'TEST',
            msg: 'TEST button',
            msg_in_chat_window: true,
        }],
    };

    const messageAttachments2 = {
        color: 'good',
        text: 'attachment text 2',
        button_alignment: 'horizontal',
        actions: [
            {
                type: 'button',
                name: 'TEST',
                text: 'TEST',
                msg: 'TEST button',
                msg_in_chat_window: true,
            },
            {
                type: 'button',
                name: 'TEST2',
                text: 'TEST2',
                msg: 'TEST button2',
                msg_in_chat_window: true,
            },
        ],
    };

    let m = new Message('', '');
    m.setRoomId(generalRoomId);
    m.groupable = false;

    // If I do not update msg, even if I udpate attachments, the message is not updated.
    const messageID1 = random.id();
    m._id = messageID1;
    m.msg = 'In case we do not change text in msg field';
    m.attachments = [ messageAttachments ];
    await driver.sendMessage(m);
    m.attachments = [ messageAttachments2 ];
    await driver.asyncCall('updateMessage', m);    // ---> nothing to occur

    // 2nd message - change text in msg field and call updateMessage.
    const messageID2 = random.id();
    m._id = messageID2;
    m.msg = 'In case we change text in msg field';
    m.attachments = [ messageAttachments ];
    await driver.sendMessage(m);
    m.msg = 'In case we change text in msg field --- UPDATED';
    m.attachments = [ messageAttachments2 ];
    await driver.asyncCall('updateMessage', m);    // ---> message is updated with 2 buttons
}

runbot()

After calling updateMessage, the message is not updated if I did not change msg.

Expected behavior:

The message is updated even if only attachments field has been changed.

Actual behavior:

If changes are only in attachments field, updateMessage does not update message.

Server Setup Information:

Additional context

This seems to be an side effect of https://github.com/RocketChat/Rocket.Chat/pull/13053

Kailash0311 commented 5 years ago

Hi, I would like to clarify that this is not the side-effect of the PR as you had pointed at the end.

This seems to be an side effect of #13053

This is resulting because Rocketchat's update-message only lets the text of the message to be updated and not anything else.

tomonorisugiura commented 5 years ago

Thanks you for comment.

https://rocket.chat/docs/developer-guides/realtime-api/method-calls/update-message/

In the above document,

The only parameter that needs to be passed in is the Message Object which contains the updated message properties, such as the text.

So, I think updateMessage should handle update in any portion of a message, not only text...