JivoChat Developers API

JivoChat provides developers two tool kits for integration:

Client-side - the widget JavaScript API which allows you to manage a widget which is displayed to the user. It can be used to manage the chat window, and also to send any information from the page on which the chat window is placed, to the JivoChat App (for example, it is possible to send additional information about a user and it will also be kept in the archive).

Server-side - Webhooks API, allows you to receive notifications about the beginning or end of a chat on your server-side, and also to send to JivoChat additional information to display it in the agent's application.

If you find any mistake in documentation please let us know in chat on jivochat.com.br

JavaScript API

JivoChat executes the functions listed below to report about an event on the page. You can declare any of these functions on the page and execute a logic of processing the event that occurred. For example, on jivo_onIntroduction event you can get contact details entered by a client.

Callback functions

FieldTypeDescription
jivo_onLoadCallbackfunctionExecuted when JivoChat widget initialization is over
jivo_onOpenfunctionExecuted when chat window is opened
jivo_onMessageSentfunctionExecuted when a visitor sends the first message
jivo_onAcceptfunctionExecuted when an agent presses the Reply button in the notification of a new chat
jivo_onClosefunctionExecuted when chat window is closed
jivo_onIntroductionfunctionExecuted when a visitor fills the contacts form
jivo_onResizeCallbackfunctionExecuted at any change in the size of the widget
jivo_onCallStartfunctionExecuted when visitor makes phone call
jivo_onCallEndfunctionExecuted when a phone call ends
jivo_onChangeStatefunctionExecuted when chat window state is changed

JavaScript API - jivo_onCallEnd

Executed when phone call ends

Params

FieldTypeDescription
result optionalobjectResult of callback
 function jivo_onCallEnd(res) {
    if (res.result == 'ok') {
        // call finished successfully
    }
    if (res.result == 'fail') {
        // call finished with errors or can not started
        console.log(res.reason); // reason for the unsuccessfull call
    }
} 

JavaScript API - jivo_onChangeState

Executed when chat window state is changed

Params

FieldTypeDescription
statestringCurrent state of the widget
 function jivo_onChangeState(state) {
    if (state == 'chat') {
        // widget is in the chat state
    }
    if (state == 'call' || state == 'chat/call') {
        // callback form is opened
    if (state == 'label' || state == 'chat/min'){
        // widget is minimized
    }
} 

JavaScript API - open

Using this method you can open chat window.
jivo_api.open({start: 'call'}): opens form with a phone field for callback

JavaScript API - close

Using this method you can close the chat window.

JavaScript API - chatMode

Using this method you can get the current chat status- online/offline.

JavaScript API - getContactInfo

Reads visitor's contact info from the contacts form as a contact_info structure.

JavaScript API - getVisitorNumber

The asynchronous function to get a unique visitor number in JivoChat. Visitors are numbered sequentially: 1, 2, 3, etc. Visitor number is displayed in the agent's App and archives and can be used to associate JivoChat data to the CRM data.

JavaScript API - setContactInfo

Sets the contact info of the visitor. The data is displayed to the agent is a same as if a visitor introduced in the chat window. It's a special function to set contact info because name, phone number and e-mail are very important in JivoChat - visitor can introduce himself at the beginning of chat.

Params

FieldTypeDescription
namestringClient's name
emailstringClient's email
phonestringClient's phone number
descriptionstringAdditional information about the client
 jivo_api.setContactInfo({
    "name": "John Smith",
    "email": "email@example.com",
    "phone": "+14084987855",
    "description": "Description text"
 }); 

JavaScript API - setCustomData

Using this method you can send any additional info about the client to the agent's App. This info will be shown on the information panel, located on the right side of the agent's App. The method can be called as many times as you need. If chat is established, information in the agent's App will be updated in real time. Fields will be displayed in the same sequence as they are in the array 'fields'.

setCustomData method is the easiest way to send additional info about visitor to the agent's App. But you need to keep in mind that the data transmitted to agent thus cannot be trusted - using the browser debugging tools, an attacker can spoof them.

For organizing more secure transmission of information in case you need to guarantee the security, use setUserToken method and Webhooks.

To avoid the possibility of phishing links sent to agent, you need to set "Safe URL" in Admin panel - Settings - Integration Settings for Developers, and links to another domains will be blocked, agent won't see them.

Method returns {result: 'ok'} if the data has been set successfully or {result: 'fail', reason: 'Custom data must be array.'} if method returns error

Params

FieldTypeDescription
fieldsarrayList of additional data fields of the chat

field

FieldTypeDescription
contentstringContent of data field. Tags will be insulated
titlestringTitle shown above a data field
linkstringURL that opens when you click on a data field
keystringDescription of the data field, bold text before a colon
 jivo_api.setCustomData([
    {
        "title": "Actions",
        "content": "Add contact",
        "link": "..."
    },
    {
        "content": "Open customer profile",
        "link": "..."
    }
 ]); 

JavaScript API - setRules

Using this method you can replace the triggers' rules by transferred object. You can get an example of such object in our admin panel in the Triggers section, just press JSON structure button there.

Params

FieldTypeDescription
rulesobjectDescription of the rules of active invitations in JSON
 jivo_api.setRules(rules); 

JavaScript API - setUserToken

Use this method to open chat window with custom text at the moment you need. This may be useful if you want to show proactive invitation after the client added goods to cart of your online store. If you want to show invitation immediately when page is open, then you need to call showProactiveInvitation in jivo_onLoadCallback (to initialize that all in the right sequence).

Params

FieldTypeDescription
tokenstringVisitor id

JavaScript API - showProactiveInvitation

Use this method to open chat window with custom text at the moment you need. This may be useful if you want to show proactive invitation after the client added goods to cart of your online store. If you want to show invitation immediately when page is open, then you need to call showProactiveInvitation in jivo_onLoadCallback (to initialize that all in the right sequence).

Params

FieldTypeDescription
invitation_textstringInvitation text
department_idnumberDepartment id
 jivo_api.showProactiveInvitation("How can I help you?"); 

JavaScript API - startCall

Method allows you to start a call to the desired number, if calls are available (Callback feature is configured and the balance of calls is positive).

Method returns {result: 'ok'} If the phone number is in the correct format and the request to start the call can be made.
Otherwise returns {result: 'fail', reason: 'Callback disabled'}, where reason - is about the unsuccessful method call.

Params

FieldTypeDescription
phonestringPhone number for the call
 jivo_api.startCall('+14084987855') 

JavaScript API - isCallbackEnabled

Checks if calls are available.

Method returns:
{result: 'fail', reason: 'Callback disabled'} - calls are disabled in admin panel.
{result: 'fail', 'Callback unavaiable'} - сalls are not available for other reasons (not the day of the week, the time of the call, the call is already started).
{result: 'ok'} - calls are avaiable

Params

FieldTypeDescription
callbackfunctionFunction called to determine the availability of a callback from the site.
 jivo_api.isCallbackEnabled(function(res){
    console.log('isCallbackEnabled', res);

    if (res.result == 'ok') {
        jivo_api.open({start: 'call'});
    }
}); 

JavaScript API - sendOfflineMessage

Using this function you can send an offline message directly. Returns {result: 'ok'} if the passed parameters are correct

Returns {result: 'fail', error: errReason}, where errReason is the validation error of the passed fields, or the reason why you can not send an offline message.

Params

FieldTypeDescription
namestringClient's name
emailstringClient's email
phonestringClient's phone number
descriptionstringAdditional information about the client
messagestringOffline message text
 jivo_api.sendOfflineMessage(({
    "name": "John Smith",
    "email": "email@example.com",
    "phone": "+14084987855",
    "description": "Description text",
    "message": "Offline message"
 }); 

Webhooks

Use Webhooks to receive notifications about various events associated with visitor's activity in JivoChat system. You can set an HTTP(S) URL to send requests when some event occurred in Admin panel.

POST request will be sent to the specified URL with the event information in the JSON object as a body.

Event type is specified in the event_name field of the 'event' structure.
The other fields depending on the actual event. In response to the HTTP-request for some types of events you can send the data which will be displayed to the agent who accepted the chat.

Webhooks - chat_accepted

Event will be sent when agent clicks 'Reply'. All known data about visitor and some agent's info will be sent in the request parameters. Also parameters including visitor's id if it was sent to the widget using jivo_api.setUserToken

If response to chat_accepted contains contat_info, this data will be displayed to the agent as if a visitor introduced in the chat window. It's also will be saved in the archive and email with the chat log.

Params

FieldTypeDescription
event_namestringEvent Type Default: chat_accepted
chat_idnumberID of a chat
widget_idstringChannel widget ID, it can be found in the chat code
visitorobjectobject with information about the visitor
agentobjectobject with information about the operator
sessionobjectInformation on user sessions
pageobjectInformation about a page on which the visitor

visitor

FieldTypeDescription
name optionalstringName
email optionalstringEmail
phone optionalstringPhone
numberstringNumber of visitor
descriptionstringAdditional information about the client
social optionalobjectInformation about the user's social networks
chats_countnumberthe number of messages

agent

FieldTypeDescription
idstringOperator ID
namestringName of the operator
emailstringEmail operator
phone optionalstringPhone operator

session

FieldTypeDescription
geoipobjectdata from geoip
utmstringutm
ip_addrstringip addres of active sessions
user_agentstringdescription user_agent

page

FieldTypeDescription
urlstringURL of the page where the user is located
title optionalstringPage Title

geoip

FieldTypeDescription
region_codestringarea code
countrystringCountry name
country_codestringISO country code
regionstringRegion
citystringCity
regionstringRegion
latitudestringLatitude
longitudestringLongitude
organizationstringCompany name

Response

FieldTypeDescription
resultstringstring processing result. If the value is not "OK", the data will not be transmitted to the operator
custom_dataarrayadditional data fields, similar setCustomData
contact_infoobjectFields of contact data, similar setContactInfo
enable_assignbooleanA flag that determines the operator to display the binding key visitor to the card in CRM. The button is displayed in front of all fields custom_data.
crm_linkstringLink to the client card in CRM. Displays the operator a separate button under all fields custom_data.
pageobjectInformation about a page on which the visitor

custom_data

FieldTypeDescription
titlestringArbitrary name of a custom field
contentstringContent

contact_info

FieldTypeDescription
namestringCustomer name
phone optionalstringCustomer phone
email optionalstringCustomer E-mail

page

FieldTypeDescription
urlstringURL of the page where the user is located
title optionalstringPage Title

The request contains a structure:

 {
    "event_name": "chat_accepted",
    "chat_id": 5184,
    "widget_id": "2014",
    "visitor": {
        "name": "John Smith",
        "email": "email@example.com",
        "phone": "+14084987855",
        "number": "2149",
        "description": "Description text",
        "social": {},
        "chats_count": 5
    },
    "agent": {
        "id": "2572",
        "name": "Thomas Anderson",
        "email": "agent@jivosite.com",
        "phone": "+14083682346"
    },
    "session": {
        "geoip": {
            "region_code": "CA",
            "country": "United States",
            "country_code": "US",
            "region": "California",
            "city": "San Francisco",
            "latitude": "37.7898",
            "longitude": "-122.3942",
            "organization": "Wikimedia Foundation"
        },
        "utm": "...",
        "ip_addr": "208.80.152.201",
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
    },
    "page": {
        "url": "http://example.com/",
        "title": "Page title"
    }
} 

The response contains JSON:

 {
    "result": "ok",
    "custom_data": [
        {
            "title": "Title",
            "content": "Content text"
        }
    ],
    "contact_info": {
        "name": "John Smith",
        "phone": "+14084987855",
        "email": "email@example.com"
    },
    "page": {
        "url": "http://example.com/",
        "title": "Page title"
    }
} 

Webhooks - chat_assigned

Event will be sent when a chat connects to CRM using the parameter "crm_link" from reply on Chat Accepted. All known data about visitor and some agent's info will be sent in the request parameters. Also parameters including visitor's id if it was sent to the widget using jivo_api.setUserToken

In response we expect only {"result": "ok or an error message"}

Params

FieldTypeDescription
event_namestringEvent type, default: chat_assigned
chat_idnumberID of a chat
widget_idstringChannel widget ID, it can be found in the chat code
visitorobjectobject with information about the visitor
agentobjectobject with information about the operator
assign_tostringCRM link from the event Chat_accepted
sessionobjectInformation on user sessions
pageobjectInformation about a page where a chat was started

visitor

FieldTypeDescription
name optionalstringName
email optionalstringEmail
phone optionalstringPhone
numberstringNumber of visitor
descriptionstringAdditional information about the client
social optionalobjectInformation about the user's social networks
chats_countnumberthe number of messages

agent

FieldTypeDescription
idstringOperator ID
namestringName of the operator
emailstringEmail operator
phone optionalstringPhone operator

session

FieldTypeDescription
geoipobjectdata from geoip
utmstringutm
ip_addrstringip addres of active sessions
user_agentstringdescription user_agent

page

FieldTypeDescription
urlstringURL of the page where the user is located
title optionalstringPage Title

geoip

FieldTypeDescription
region_codestringarea code
countrystringCountry name
country_codestringISO country code
regionstringRegion
citystringCity
regionstringRegion
latitudestringLatitude
longitudestringLongitude
organizationstringCompany name

Response

FieldTypeDescription
resultstringstring processing result ("OK" or "FAILURE").

The request contains a structure:

 {
    "event_name": "chat_assigned",
    "chat_id": 9674,
    "widget_id": "2014",
    "visitor": {
        "name": "John Smith",
        "email": "email@example.com",
        "phone": "+14084987855",
        "number": "2149",
        "description": "Description text",
        "social": {},
        "chats_count": 5
    },
    "agent": {
        "id": "2572",
        "name": "Thomas Anderson",
        "email": "agent@jivosite.com",
        "phone": "+14083682346"
    },
    "assign_to": "...",
    "session": {
        "geoip": {
            "region_code": "CA",
            "country": "United States",
            "country_code": "US",
            "region": "California",
            "city": "San Francisco",
            "latitude": "37.7898",
            "longitude": "-122.3942",
            "organization": "Wikimedia Foundation"
        },
        "utm": "...",
        "ip_addr": "208.80.152.201",
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
    },
    "page": {
        "url": "http://example.com/",
        "title": "Page title"
    }
} 

The response contains JSON:

 {
    "result": "ok"
} 

Webhooks - chat_finished

Event will be sent when a chat is closed in the agent application. All known data about visitor, agent's info and the chat log will be sent in the request parameters. Also parameters including visitor's id if it was sent to the widget using jivo_api.setUserToken

In response we expect only {"result": "ok or an error message"}

Params

FieldTypeDescription
event_namestringtype of event, default: chat_finished
chat_idnumberid of a chat
widget_idstringChannel widget ID, it can be found in the chat code
visitorobjectobject with information about the visitor
agentsarrayAn array with information about the operators
chatobjectData on completed chatting
sessionobjectInformation on user sessions
pageobjectInformation about a page where a chat was started

visitor

FieldTypeDescription
name optionalstringName
email optionalstringEmail
phone optionalstringPhone
numberstringNumber of visitor
descriptionstringAdditional information about the client
social optionalobjectInformation about the user's social networks
chats_countnumberthe number of messages

agent

FieldTypeDescription
idstringOperator ID
namestringName of the operator
emailstringEmail operator
phone optionalstringPhone operator

chat

FieldTypeDescription
messagesarrayAn array of chat messages
ratestringuser chat rank (positive | negative | null)
blacklistedbooleanA sign that the user was added to the black list

session

FieldTypeDescription
geoipobjectdata from geoip
utmstringutm
ip_addrstringip addres of active sessions
user_agentstringdescription user_agent

page

FieldTypeDescription
urlstringURL of the page where the user is located
title optionalstringPage Title

message

FieldTypeDescription
timestampnumberThe time of receipt message (timestamp)
typestringMessage Type (visitor - a message from a client, agent - a message from an agent)
agent_idnumberAgent ID, which responded to the message (exists only if type = agent)
blacklisted optionalbooleanA sign that the user was added to the black list

geoip

FieldTypeDescription
region_codestringarea code
countrystringCountry name
country_codestringISO country code
regionstringRegion
citystringCity
regionstringRegion
latitudestringLatitude
longitudestringLongitude
organizationstringCompany name

Response

FieldTypeDescription
resultstringstring processing result ("OK" or "FAILURE").

The request contains a structure:

 {
    "event_name": "chat_finished",
    "chat_id": 3556,
    "widget_id": "2014",
    "visitor": {
        "name": "John Smith",
        "email": "email@example.com",
        "phone": "+14084987855",
        "number": "2149",
        "description": "Description text",
        "social": {},
        "chats_count": 5
    },
    "agents": [
        {
            "id": "2572",
            "name": "Thomas Anderson",
            "email": "agent@jivosite.com",
            "phone": "+14083682346"
        }
    ],
    "chat": {
        "messages": [
            {
                "timestamp": 1431955090,
                "type": "agent",
                "agent_id": 3173,
                "blacklisted": false
            }
        ]
    },
    "session": {
        "geoip": {
            "region_code": "CA",
            "country": "United States",
            "country_code": "US",
            "region": "California",
            "city": "San Francisco",
            "latitude": "37.7898",
            "longitude": "-122.3942",
            "organization": "Wikimedia Foundation"
        },
        "utm": "...",
        "ip_addr": "208.80.152.201",
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
    },
    "page": {
        "url": "http://example.com/",
        "title": "Page title"
    }
} 

The response contains JSON:

 {
    "result": "ok"
} 

Webhooks - chat_updated

Event will be sent when a visitor's information has been updated - for example a visitor filled the contacts form in the chat. All known data about visitor and agent's info will be sent in the request parameters. Also parameters including visitor's id if it was sent to the widget using jivo_api.setUserToken

In response we expect only {"result": "ok or an error message"}

Params

FieldTypeDescription
event_namestringEvent type, default: chat_updated
chat_idnumberid of a chat
widget_idstringChannel widget ID, it can be found in the chat code
visitorobjectobject with information about the visitor
agentobjectobject with information about the operator
sessionobjectInformation on user sessions
pageobjectInformation about a page on which the visitor

visitor

FieldTypeDescription
name optionalstringName
email optionalstringEmail
phone optionalstringPhone
numberstringNumber of visitor
descriptionstringAdditional information about the client
social optionalobjectInformation about the user's social networks
chats_countnumberthe number of messages

agent

FieldTypeDescription
idstringOperator ID
namestringName of the operator
emailstringEmail operator
phone optionalstringPhone operator

session

FieldTypeDescription
geoipobjectdata from geoip
utmstringutm
ip_addrstringip addres of active sessions
user_agentstringdescription user_agent

page

FieldTypeDescription
urlstringURL of the page where the user is located
title optionalstringPage Title

geoip

FieldTypeDescription
region_codestringarea code
countrystringCountry name
country_codestringISO country code
regionstringRegion
citystringCity
regionstringRegion
latitudestringLatitude
longitudestringLongitude
organizationstringCompany name

Response

FieldTypeDescription
resultstringstring processing result ("OK" or "FAILURE").

The request contains a structure:

 {
    "event_name": "chat_updated",
    "chat_id": 3300,
    "widget_id": "2014",
    "visitor": {
        "name": "John Smith",
        "email": "email@example.com",
        "phone": "+14084987855",
        "number": "2149",
        "description": "Description text",
        "social": {},
        "chats_count": 5
    },
    "agent": {
        "id": "2572",
        "name": "Thomas Anderson",
        "email": "agent@jivosite.com",
        "phone": "+14083682346"
    },
    "session": {
        "geoip": {
            "region_code": "CA",
            "country": "United States",
            "country_code": "US",
            "region": "California",
            "city": "San Francisco",
            "latitude": "37.7898",
            "longitude": "-122.3942",
            "organization": "Wikimedia Foundation"
        },
        "utm": "...",
        "ip_addr": "208.80.152.201",
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
    },
    "page": {
        "url": "http://example.com/",
        "title": "Page title"
    }
} 

The response contains JSON:

 {
    "result": "ok"
} 

Webhooks - offline_message

Event will be sent when a visitor sends an offline message through the chat offline form. All known data about visitor and offline message will be sent in the request parameters. Also parameters including visitor's id if it was sent to the widget using jivo_api.setUserToken

In response we expect only {"result": "ok or an error message"}

Params

FieldTypeDescription
event_namestringEvent type, default: offline_messages
widget_idstringChannel widget ID, it can be found in the chat code
visitorobjectobject with information about the visitor
offline_message_idstringID offline messages
messagestringMessage
sessionobjectInformation on user sessions
pageobjectInformation about a page on which the visitor

visitor

FieldTypeDescription
name optionalstringName
email optionalstringEmail
phone optionalstringPhone
numberstringNumber of visitor
descriptionstringAdditional information about the client
social optionalobjectInformation about the user's social networks
chats_countnumberthe number of messages

session

FieldTypeDescription
geoipobjectdata from geoip
utmstringutm
ip_addrstringip addres of active sessions
user_agentstringdescription user_agent

page

FieldTypeDescription
urlstringURL of the page where the user is located
title optionalstringPage Title

geoip

FieldTypeDescription
region_codestringarea code
countrystringCountry name
country_codestringISO country code
regionstringRegion
citystringCity
regionstringRegion
latitudestringLatitude
longitudestringLongitude
organizationstringCompany name

Response

FieldTypeDescription
resultstringstring processing result ("OK" or "FAILURE").

The request contains a structure:

 {
    "event_name": "offline_message",
    "widget_id": "2014",
    "visitor": {
        "name": "John Smith",
        "email": "email@example.com",
        "phone": "+14084987855",
        "number": "2149",
        "description": "Description text",
        "social": {},
        "chats_count": 5
    },
    "offline_message_id": "2923",
    "message": "Message text",
    "session": {
        "geoip": {
            "region_code": "CA",
            "country": "United States",
            "country_code": "US",
            "region": "California",
            "city": "San Francisco",
            "latitude": "37.7898",
            "longitude": "-122.3942",
            "organization": "Wikimedia Foundation"
        },
        "utm": "...",
        "ip_addr": "208.80.152.201",
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
    },
    "page": {
        "url": "http://example.com/",
        "title": "Page title"
    }
} 

The response contains JSON:

 {
    "result": "ok"
}