How to get the visitor's custom fields information using Node JS SDK

Hi,

I have added some custom fields in the Live chat and sending the data from the customer Widget. I have created a bot using Node JS SDK. But I don’t know how to get the custom fields visitor information. I have gone through the documentation but no luck.

The information is not there in the message object. The user object is there but only limited info is there:
u: { _id: ‘XePzirgYNBs9XSt5L’, username: ‘guest-29’, name: null }

Yes, there’s not much user information in the meta from the message stream, but the SDK also includes a module for using the API. So once you’ve got the user ID, you can make a follow up request.

Docs for the endpoint…
https://rocket.chat/docs/developer-guides/rest-api/users/info/

Basic details on usage…

Test file shows it in action…

Thanks Tim,

Actually I tried the users api but for the guest user it’s giving Invalid user error. From the widget I am sending some custom fields like
RocketChat(function() {
this.setDepartment(‘Bot’);
this.setCustomField(‘accountId’, ‘7’);
});

I want to access these fields in my code where I am using Rocket.Chat.js.SDK.

But I didn’t find any way to get this information. I am not sure if this will be a part of User object or some other Object. In the message it’s not present. I am able to see it in the Live Chat agent’s visitor Info(the scope of theese fields is set to Vistors).

I’ve added some snippets to demonstrate similar interactions via the SDK, in Hubot. You might find something there to follow: https://rocket.chat/hubot-rocketchat/snippets - specifically “Use API to check if role exists on given user” - The other thing you might need is to make sure the bot has view-full-other-user-info permission. Since you’re talking about getting custom user data, it won’t be included in the basic user data response.

Hi Tim,

I am able to get the custom field defined in the widget:

   RocketChat(function() {
       this.setCustomField('userToken', 'userToken');  
   });

I am using NodeJS SDK. There are two methods:

  1. var cstmFieldsData = {
    roomId: message.rid,
    departmentId: DEPARTMENT_ID
    }
    var cstmFields = driver.callMethod(‘livechat:getCustomFields’, cstmFieldsData);

    but this only gives the name and other properties of custom field and doesn’t give the value of the custom field.

  2. var roomsData = driver.callMethod(‘rooms/get’, []);

    It gives us all the rooms and then basis the roomId we get from message object we can get our livechat room object. In this room object we get the live chat data. This live chat data contains the custom field name and values.

    But It seems there is some defect because it gives the live chat data only when we reload the widget after sending first message. Without reloading the widget it doesn’t give the live chat data in room object.

Can someone please investigate this issue?