RocketChat / RocketChat/Rocket.Chat
UpdateMessage does not work when updates are only in attachments
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
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:
- Version of Rocket.Chat Server: 1.0.0-beta.2
- Operating System: RHEL 7.6
- Deployment Method: docker
- Number of Running Instances: 1
- DB Replicaset Oplog: Disabled
- NodeJS Version: 8.11.4 - x64
- MongoDB Version: 4.0.2
Additional context
This seems to be an side effect of https://github.com/RocketChat/Rocket.Chat/pull/13053
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with @rocket.chat/sdk/dist/lib/message and the driver.asyncCall('updateMessage') path, then compare how sendMessage and updateMessage handle the message fields shown in the reproduction. Done means updating only attachments, including adding a second button, changes the existing message without changing msg.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100