Customer verification
By default, VivoChat treats a visitor as anonymous.
If your website has authentication, you can link a dialog to a customer from your own system:
- restore the message history;
- show the operator the customer’s name, phone, and email;
- merge dialogs across devices and sessions.
How it works
Section titled “How it works”1. The website passes the user token
Section titled “1. The website passes the user token”After the user is authenticated, call:
vivo_api.setUserToken(USER_TOKEN);
vivo_api.run({ withIcon: true });setUserToken() must be called before run().
2. VivoChat requests customer verification
Section titled “2. VivoChat requests customer verification”When the chat is first opened, VivoChat sends a POST request of type client_check_token to the customer verification URL.
The URL is configured in the interface:
Settings → Dialogs → Customer verification address
Request example:
{ "type": "client_check_token", "userToken": "USER_TOKEN"}3. Your server returns the customer data
Section titled “3. Your server returns the customer data”The server must:
- verify the token;
- find the customer;
- return
clientId; - if necessary, return the customer’s contact details.
Response example:
{ "result": "ok", "clientId": "customer_123", "contactInfo": { "name": "John Smith", "phone": "+14084987855", }}4. VivoChat links the customer to the dialogs
Section titled “4. VivoChat links the customer to the dialogs”After receiving the clientId, VivoChat:
- links the dialog to the customer;
- restores the message history;
- shows the operator the customer’s contact details.
If clientId is missing, the customer is treated as anonymous.
Important
Section titled “Important”Passing only setUserToken() is not enough to restore the dialog history.
The message history is restored only after a successful response to client_check_token with a correct clientId.
We recommend using a hard-to-guess identifier for clientId to rule out the possibility of spoofing.
When the user logs out of their account, we recommend clearing the token:
vivo_api.setUserToken(null);If you do not clear the token, the next user on the same browser may gain access to the previous chat session.
Difference between client_check_token, setContactInfo, and chat_accepted
Section titled “Difference between client_check_token, setContactInfo, and chat_accepted”These mechanisms solve different problems, but all of them can pass contact details.
| Mechanism | What it is used for |
|---|---|
setContactInfo() |
Passes the customer’s contact details without verification |
client_check_token |
Verifies the customer and displays the customer’s contacts and dialog history |
chat_accepted |
Updates the customer’s contacts after the operator accepts the dialog, passes additional data about the customer |
setContactInfo()
Section titled “setContactInfo()”setContactInfo() lets you pass the customer’s contact details directly from the browser without verification:
vivo_api.setContactInfo({ name: 'John Smith',});
/* ... */
vivo_api.run();The method:
- does not verify the customer;
- does not restore the dialog history;
- does not link dialogs across devices or sessions.
setContactInfo() displays the customer’s data only in the current dialog under the “Contacts” section.
client_check_token
Section titled “client_check_token”Used for:
- identifying the customer;
- restoring the dialog history;
- initially obtaining the customer’s data.
The contactInfo from client_check_token is displayed in the operator’s main customer card.
Without clientId, the dialog history is not restored.
chat_accepted
Section titled “chat_accepted”The chat_accepted event is triggered after the operator accepts the dialog.
Used for:
- updating the customer’s data;
- passing additional data to the operator;
- keeping information from your CRM or system up to date.
The response can return:
contactInfo— updates the main customer card;customData— displayed in the “Additional” tab.
Example:
{ "result": "ok", "contactInfo": { "name": "John Smith", "phone": "+14084987855" }, "customData": [ { "title": "Plan", "content": "Premium" } ]}Recommended integration scenario
Section titled “Recommended integration scenario”On authentication
Section titled “On authentication”vivo_api.setUserToken(USER_TOKEN);When the chat is opened
Section titled “When the chat is opened”- VivoChat calls
client_check_token; - the server returns
clientId; - VivoChat restores the dialog history.
After the operator accepts the dialog
Section titled “After the operator accepts the dialog”- the server updates the current customer data via
chat_accepted; - additional data is displayed in the “Additional” tab.
When the user logs out of their account
Section titled “When the user logs out of their account”- clear the token: vivo_api.setUserToken(null).