Set/Update User Profile Data

Register#

To register a new user use the below method. You will get the username and password in the response. By providing that username and password to the connect method you can connect in to the server further.

note

During the initialization, if the isTrialLicenseKey is set to true in the initialization, users will be registered in the trial mode.

await SDK.register(`USER_IDENTIFIER`);

Request Params#

StatusDescriptionTypeRequired
USER_IDENTIFIERUnique Id to Register the User. User identifier can only contain lowercase alphanumeric characters, hyphens (-), and underscores (_)Stringtrue
FORCE_REGISTERdefault value true provide true to force the old session logged out when the registered user has reached the maximum number of multiple-sessions or provide false to allow registration till the maximum no of multiple-sessions reachedBooleanfalse
registerMetaDataregisterMetaData is an optional parameter to provide MetaData of user. Maximum size is 3Objectfalse

Request Input for registerMetaData#

ArgumentsDescriptionType
keyName of the KeyString
valueName of the valueString or Boolean or Number
caution

If FORCE_REGISTER is false and if it reached the maximum no of multiple-sessions, then registration will not success and it will throw a 405 exception. Either FORCE_REGISTER should be true or one of the existing session need to be logged out to continue registration.

Response Params#

ArgumentsDescriptionType
statusCodeStatus CodeNumber
messageSuccess/Error MessageString
dataUsername, Password, isProfileUpdated, isSandbox, userJidObject

Sample Response:#

{
statusCode: 200,
message: "Success",
data: {
username: "123456789",
password: "987654321",
isProfileUpdated: true,
isSandbox: true,
userJid: "1234567890@xmppdomain"
}
}

Connect with Username#

Make a connection to the server by using the credentials got as a response of the register method. Once the connection is made successfully, it returns a Promise with statusCode of 200, else throws an Error.

This will also emit the connection status. It will be received in connectionListener callback function. If any error occurs while making a connection with the server, You will receive the error in the callback.

await SDK.connect(`USERNAME`, `PASSWORD`);

Request Params#

StatusDescriptionTypeRequired
USERNAMEUsernameStringtrue
PASSWORDPasswordStringtrue

Response Params#

ArgumentsDescriptionType
statusCodeStatus CodeNumber
messageSuccess/Error MessageString

Sample Response:#

{
message: "Login Success",
statusCode: 200
}

Login with QR Code#

If Login needs to be done via QR Code scan from Mobile, generate new QR Code with below method.

Once the QR Code scanned successfully, the user will be with XMPP, and username and password will be received in callback response

await SDK.generateQrCode(`DOM_ELEMENT_ID`, `LOGO_ELEMENT_ID`, `SIGNAL_SERVER_URL`, () => {
// Handle Callback Here
});

Request Params#

StatusDescriptionTypeRequired
DOM_ELEMENT_IDCanvas element id in which QR Code has to appendedStringtrue
LOGO_ELEMENT_IDBranding Logo in the QR CodeStringtrue
SIGNAL_SERVER_URLSignal Server URL for Socket ConnectionStringtrue

Example Request#

SDK.generateQrCode(
document.getElementById("canvas"),
document.getElementById("logo"),
"wss://domain.com",
(response) => {
// Handle Response
}
);

Update User Profile Detail#

To set the Profile detail of the user, send a request as described below.

Once the request is successfully made, a callback userProfileListener will be triggered for the current user and also for the friends (Contacts of the current user) to get the latest profile details.

await SDK.setUserProfile(`NAME`, `IMAGE`, `STATUS`, `MOBILE_NUMBER`, `EMAIL`);

Request Params#

StatusDescriptionTypeRequired
NAMENickname of the UserStringtrue
IMAGEProfile Image - Upload an image file or image URLFile / Stringtrue
STATUSProfile StatusStringtrue
MOBILE_NUMBERMobile NumberStringtrue
EMAILEmail AddressStringtrue

Example Request#

Image as a URL

await SDK.setUserProfile(
"Name",
"https://domain/path/image.png",
"status",
"1111111111",
"email@domain",
);

Image as a FILE

await SDK.setUserProfile("Name", FILE, "status", "1111111111", "email@domain");

Set User Token#

To set the user token locally.

await SDK.setUserToken(`TOKEN`);

Request Params#

StatusDescriptionTypeRequired
TOKENUser TokenStringtrue

Response Params#

ArgumentsDescriptionType
statusCodeStatus CodeNumber
messageSuccess/Error MessageString