Rocket.Chat.Apps-engine icon indicating copy to clipboard operation
Rocket.Chat.Apps-engine copied to clipboard

Start message from context

Open sampaiodiego opened this issue 5 years ago • 3 comments

When creating a message being triggered by a slash command, I found really frustrating having to set the room (and even the thread id) of that message, because I just had to set the properties from the context and set them on the message creator. Since I think this is the most common and expected behavior, it would be nice to have an API that can do that for me, something like:

public async executor(context: SlashCommandContext, read: IRead, modify: IModify): Promise<void> {
  const builder = modify.getCreator()
    .startMessage()
    .fromContext(context)
    .setText('My message');

  modify.getCreator().finish(builder);
}

sampaiodiego avatar Nov 26 '20 18:11 sampaiodiego

This could also be applied to other UIKit contexts, it's a very interesting approach.

Regarding behavior: some contexts (if not all) have a userId in them. Would you expect this user to be assigned as the sender of the message? Or would you expect the app user to be the sender (ignoring the user in the context)?

d-gubert avatar Nov 26 '20 19:11 d-gubert

Regarding behavior: some contexts (if not all) have a userId in them. Would you expect this user to be assigned as the sender of the message? Or would you expect the app user to be the sender (ignoring the user in the context)?

I'd say the app user should be used as sender by default, but I can see it may look inconsistent. 🤔

sampaiodiego avatar Nov 26 '20 19:11 sampaiodiego

@d-gubert Can I take this issue up? The .fromContext() function will be able to take in contexts (types) which have the user and the room in them.

I'd say the app user should be used as sender by default, but I can see it may look inconsistent. 🤔

Also, can you please tell me who should be default sender when using this function.

aditya-mitra avatar May 02 '21 13:05 aditya-mitra