Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessageBuilder should be able to add/set custom fields for message #309

Closed
cuonghuunguyen opened this issue Sep 4, 2020 · 4 comments · Fixed by #363
Closed

MessageBuilder should be able to add/set custom fields for message #309

cuonghuunguyen opened this issue Sep 4, 2020 · 4 comments · Fixed by #363
Assignees
Labels
Hacktoberfest Good candidate for Hacktoberfest 2020 🙋‍♂️ help wanted We want YOU to help! triaged This has been triaged

Comments

@cuonghuunguyen
Copy link
Contributor

In App-engine's IMessage interface, we have the field for storing custom fields but in the MessageBuilder, there is no way to add a custom field to the Message. Could you provide a method to add custom fields to the message?

@d-gubert d-gubert added 🙋‍♂️ help wanted We want YOU to help! Hacktoberfest Good candidate for Hacktoberfest 2020 triaged This has been triaged labels Sep 10, 2020
@matheusbsilva137
Copy link
Member

Hi, @meomay503 !

There is one method (addCustomField) already implemented and available in the messageExtender object, which can just be used after the message is sent.
The following repository may guide you through the usage of the messageExtender: https://github.com/RocketChat/Apps.RocketChat.Tester/tree/recipes/extending-messages

In brief, the process of sending a message returns an ID, which can be used in order to obtain the messageExtender that allows the addition of custom fields and attachments. The described process can be done as follows:

public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp, persis: IPersistence): Promise<void> {
    const messageId = await this.sendMessage(context, modify, 'Sending a message!');
    const messageExtender = await this.getMessageExtender(context, modify, messageId);
    const value = 1;
    const img = new ImageAttachment('https://open.rocket.chat/images/logo/logo.svg');
        
    messageExtender.addCustomField('key', value);
    messageExtender.addAttachment(img);

    await modify.getExtender().finish(messageExtender);
}

The complete file for the piece of code above can be found in: https://github.com/RocketChat/Apps.RocketChat.Tester/blob/recipes/extending-messages/slashcommands/ExtendSlashcommand.ts

@cuonghuunguyen
Copy link
Contributor Author

Hi @matheusbsilva137, thank you for the hint. Well, your approach works and I tried it before for my use case. The problem is the latency between the moment the message is sent and the time it gets updated.
It seems possible to create a message with custom fields and attachments by API or DDP. The current Apps Engine API also allows us to send messages with custom fields by IMessageBuilder when using with tsignore. I think the only missing thing here is the ts definition for that :D. Please correct me if you guys have any intention to disable that feature ^^

@matheusbsilva137
Copy link
Member

Hi, @meomay503!

We have performed some tests on the latency time using the messageExtender, and the results we obtained show that the elapsed time between sending a message and editing it depends on the quantity of new data attached to the message.
However, if the latency time is still a problem for you, I suggest you to keep track of our new Pull Request #363. The addCustomField method may be available soon for you using only the messageBuilder object (which does not perform message extensions; hence, there is no latency time). 😄

About the API, it is currently possible to send messages with attachments with no editions, but it still does not support custom fields within messages.
Finally, I must say that we highly suggest you to apply the implementation described in the Pull Request #363 rather than using tsignore.

@cuonghuunguyen
Copy link
Contributor Author

cuonghuunguyen commented Jan 12, 2021

Thank you for the fantastic work @matheusbsilva137 ^^. I am waiting for your PR, I've taken a look and it looks good so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Good candidate for Hacktoberfest 2020 🙋‍♂️ help wanted We want YOU to help! triaged This has been triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants