Accessing sender's custom fields inside ISlashCommand's executor

I have a simple text-type custom field I would like to access from inside a slash command.
The field is defined in Rocket.Chat server’s settings:

	"Extension": {
		"type": "text",
		"required": false,
		"public": true,
        "private": false,
		"sendToIntegrations": true

Custom fields’ values should be accessible (I think) via the IUser.customFields? optional dictionary, but it seems it is not filled with anything.

public async executor(context: SlashCommandContext, read: IRead, modify: IModify, http: IHttp): Promise<void> {


rocketchat_1          | {
rocketchat_1          |   id: '3Gg7KDwQiGeY9Yp2w',
rocketchat_1          |   username: 'davide',
rocketchat_1          |   emails: [ { address: '', verified: false } ],
rocketchat_1          |   type: 'user',
rocketchat_1          |   isEnabled: true,
rocketchat_1          |   name: 'Davide',
rocketchat_1          |   roles: [ 'admin' ],
rocketchat_1          |   status: 'online',
rocketchat_1          |   statusConnection: 'online',
rocketchat_1          |   utcOffset: 1,
rocketchat_1          |   createdAt: 2020-12-07T11:05:51.516Z,
rocketchat_1          |   updatedAt: 2020-12-15T10:10:26.918Z,
rocketchat_1          |   lastLoginAt: 2020-12-15T09:51:42.335Z,
rocketchat_1          |   appId: undefined
rocketchat_1          | }
rocketchat_1          | undefined

where no attribute customFields is present.
Is this the right way to access custom fields?
I am using the rocketchat/ Docker image to deploy the slash command.

Hi, did you manage to fix the problem?

Hi, thanks for reminding me of this.
I ended up not needing this any more.
However, you can access it through this REST call:
If the custom field Extension exists, the returned object will contain the field

        "customFields": {
             "Extension": "blah"

This call requires authentication, so you need to provide an authentication token in the headers of your request. Not sure if needed inside an app, but probably yes.
This call returns the token provided you have username and password of a registered user:

To make a REST call from a slashcommand, check

Not sure how to add HTTP headers to a GET request, couldn’t find the docs right on the spot.
I will update this answer as soon as I have some time to test some working example.

1 Like

Custom fields in applications are very useful. I was disappointed that there is no explicit way to get them.
I’m currently looking for workarounds in the process.
Have you made progress with this problem?

The room object has a field, but the user object does not. This looks like a bug.