Use the following built-in functions to get user data.

New to scripting functions? Please review the Introduction.

Get user platform ID and platform type

Get User Platform Id and Get User Platform Type are the functions that are used to get the user’s unique platform ID and their platform type (FACEBOOK, HTMLCLIENT, etc.).

Function Name Arguments Returns
getUserPlatformId() None string: unique User platform ID
getUserPlatformType() None string: User platform type

Example

// get the user’s platform ID
var userId = botContext.getUserPlatformId();
// gets the user’s platform type
var platformType = botContext.getUserPlatformType();
// display the results...
botContext.printDebugMessage('The userPlatformId = ' + userId + 'and the userPlatformType = ' + platformType);

Get authenticated customer info

There are two built in methods to return authenticated customer information. You can attempt to see if either of these 2 methods return true or not. If the visitor is authenticated, (typically they would set personal or customer info being logged in) you can access the Personal Info or Customer Info object array.

Each function refers to its corresponding authenticated engagement attribute object.

Function Name Arguments Returns
getLPUserPersonalInfo() See below for accessing attributes personal info object or nothing
getLPCustomerInfo() See below for accessing attributes customer info object or nothing

Personal info example

This is an example JSON object for the Personal Info. Keep in mind that not all fields may be available for your conversation. In addition, one of the following fields (firstname, lastname, company) must be populated for this object to return, otherwise it will be null.

{
    "type": "personal",
    "personal": {
        "firstname": "John",
        "lastname": "Doe",
        "age": {
            "age": 34,
            "year": 1980,
            "month": 4,
            "day": 1
        },
        "contacts": [
            {
                "email": "myname@example.com",
                "phone": "+1 555-333-7777"
            }
        ],
        "gender": "MALE",
        "language": "en-US",
        "company": "company"
    }
}

Here is how you might use the getLPUserPersonalInfo() method in JavaScript to check for a user’s first and last name.

var personalInfo = botContext.getLPUserPersonalInfo();
botContext.printDebugMessage('PERSONAL INFO:'+personalInfo);
if(personalInfo){
    var fullName = personalInfo.firstname+" "+personalInfo.lastname;
    botContext.printDebugMessage('Full Name: '+fullName);
    botContext.setBotVariable("fullName",fullName,true,false);
}

Customer info example

Here is an example JSON object for the Customer Information.

{
    "type": "ctmrinfo",
    "info": {
        "companyBranch": "test",
        "ctype": "vip",
        "customerId": "138766AC",
        "balance": -400.99,
        "currency": "USD",
        "socialId": "11256324780",
        "imei": "99887766554433",
        "userName": "user000",
        "companySize": 500,
        "accountName": "bank corp",
        "role": "broker",
        "lastPaymentDate": {
            "day": 15,
            "month": 10,
            "year": 2014
        },
        "registrationDate": {
            "day": 23,
            "month": 5,
            "year": 2013
        },
        "storeNumber": "123865",
        "storeZipCode": "20505"
    }
}

Here is how you might use the getLPCustomerInfo() method in JavaScript to check for a user’s customerId.

var customerInfo = botContext.getLPCustomerInfo();
if(customerInfo){
    var customerId = customerInfo.customerId;
    botContext.printDebugMessage('customerId: '+customerId);
    botContext.setBotVariable("customerId",customerId,true,false);
}