Skip to content

Chat API

WhosOn Chat API

Introduction

The Chat API is designed to create custom desktop, product embedded or browser-based visitor facing WhosOn Chat applications. Using Chat API, it is possible to completely replace the standard WhosOn Chat Window with your own, using any developer platform that supports WebSockets.

The WebSocket chat interface uses port 8009 by default. The port can be changed using the WhosOn Service Manager. The WebSocket chat interface only accepts connections from IP addresses in the WhosOn Server Whitelist, since it is designed to be used via a secure Web Server proxy to the WhosOn Server.

Use Cases

  • Create your own custom chat window using familiar web design tools and existing company styles.
  • Embed chat into existing applications.
  • Easily create custom mobile applications to provide to your customers for chat.

Regardless of how you use the Chat API, the standard WhosOn Chat Window can still be used. You can use the WhosOn Chat Window in combination with any custom chat applications you create or use your own exclusively.

API Key

An API key must be supplied with the Connect command. Please contact Parker Software to obtain your API key before you start development against the Chat API.

Connecting

Connect a WebSocket on URL ws://{server}:{port} (or wss://{server}:{port} for a secure connection). Replace {server} with the IP address of the WhosOn Server or the Web Server if connecting via a proxy.

Important: WebSocket connections should always be secure (wss://). If you are connecting via a proxy then the web server will need a SSL Certificate. The WhosOn Server does not - since traffic between the proxy and WhosOn will be internal. If connecting to WhosOn directly then the WhosOn Server must be assigned a certificate and the 'Secure' setting of the Chat Server WebSocket must be enabled.

Once a WebSocket connection is established it should remain open for the duration of the Chat session.

UTF8 encoding should be used for sending & receiving.

Sending Commands

JSON text is used for all messages.

All commands sent to the server have the following format:

{
    "Command": "commandname",
    "Parameters": [
        "param1",
        "param2"
    ]
}

Copy

The commandname is the name of the command to send to the WhosOn Server. Command names are not case sensitive. Parameters contains a list of parameters (if any) associated with the command. All parameters are case sensitive strings. If there are no parameters for a command send "Parameters": null

The Parameters list should be ordered correctly for the specific command.

Example:

{
  "Command": "Connect",
  "Parameters": [
      "myauthstring",
      "www.mycompany.com",
      "193.22.32.21",
      "287-3882882",
      "edge",
      "",
      "abcdefg12345"
  ]
}

Copy

Receiving Data

The WhosOn Server will send data to the chat as events occur. This will not only be in response to commands sent, but also when events happen (Eg: An operator sending a message). Your chat application should monitor for events received and process each one accordingly.

All messages received are in the following format:

{
  "EventName": "eventname",
  "ChatUid": "chatuid",
  "Data": "data"
}

Copy

Where EventName is the name of the WhosOn Server Event. The ChatUid property will contain the current server assigned Chat UID after a chat session has been established.

The Data property will either be a single string, null or an object (or list of objects).

Example:

{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "pagingmessage",
    "Content": "Please wait. An operator will be with you shortly."
  }
}

Copy

All data sent by the WhosOn Server to your chat connection will only contain data relevant to the current chat session. It is not possible to request or receive data outside of the chat session scope.

Establishing A New Chat Session

To establish a new chat session, send the Connect command.

Connect (Command)

{
  "Command": "Connect",
  "Parameters": [
      "myauthstring",
      "www.mycompany.com",
      "195.62.193.194",
      "287-3882882",
      "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134",
      "https://www.google.com"
      "abcdefg124567"
  ]
}

Copy

Parameters:

  • Server Authentication String. This must match the Authentication String defined in the WhosOn Server settings.
  • Domain Name. This must match one of the site domain names that have been setup in WhosOn.
  • Visitor IP Address. If blank the WebSocket connection IP (or X-Forwarded-For) will be used.
  • Visitor tracking Cookie Session ID.
  • Visitor UserAgent string.
  • Visitor Referrer. Optional referrer URL.
  • API key. You must obtain your API key from Parker Software. The supplied API key must be valid.

The WhosOn Server will respond with either an error event or a connected event.

The Visitor IP and Cookie Session ID are used to match the chatting visitor to a visitor already being tracked in WhosOn. If a tracked visitor for the IP+Cookie Session ID is not found, then the WhosOn Server will create a new tracked visitor. If a new tracked visitor is created then the Visitor UserAgent and Visitor Referrer fields are used.

The Visitor UserAgent should be set to the user-agent field of the visitor's browser prior to starting a chat session (this will update the Browser and Operating System fields assigned to the visitor). If this field is blank, then the user-agent header header on the WebSocket connection itself will be used.

Error (Event)

{
  "EventName": "error",
  "ChatUid": null,
  "Data": "The specified site (www.test.co.uk) is not being monitored by WhosOn. A chat session cannot be started."
}

Copy

Data will contain a description of the error.

You will receive an error event with Data 'Access Denied' if the Authentication string passed does not match the server Authentication String or the Domain string does not match a site setup in WhosOn.

If an error event is returned from a Connect command the server will disconnect the WebSocket. Multiple invalid connection attempts will result in the WebSocket client IP (or X-Forwarded-For) being blacklisted.

Security

The WhosOn Server checks the WebSocket host IP address and any 'X-Forwarded-For' address against the global blacklist and blocks blacklisted hosts. It will also temporarily blacklist hosts that send invalid data or invalid commands. The WhosOn Server will block multiple requests from the same IP (as defined in the Server Settings - Maximum Concurrent Chats From The Same IP setting).

When using IIS ARR Proxy to forward WebSocket connections from IIS to the WhosOn Server the 'X-Forwarded-For' header will be used for the IP.

Connected (Event)

The connected event provides information about the WhosOn Site specified in the Connect command Domain Name parameter.

{
  "EventName": "connected",
  "ChatUid": null,
  "Data": {
    "SessionID": "2c61f576-330e-4127-af83-90809776fa9c",
    "Domain": "www.mycompany.com",
    "SiteName": "My Company",
    "UTCBias": 0,
    "OpeningMessage": "<h3>Welcome</h3>Please enter your name and click the <b>Start Chat</b> button to begin<br><br>If we are available we will respond, if not please leave us a message.",
    "ClosingMessage": "Thank you for chatting to us today.",
    "ForwardingURL": "",
    "Layout": "standard",
    "Color": "office",
    "Lang": "fr",
    "Height": 550,
    "Width": 470,
    "OperatorPreview": false,
    "WebServicesURL": "https://chat.mycompany.com/whosoncharts/",
    "GeoIP": {
      "IPAddress": "195.62.193.194",
      "IsProxy": false,
      "IsSatellite": false,
      "PostCode": "ST1",
      "Latitude": 53.0278,
      "Longitude": -2.1658,
      "Radius": 20,
      "ISP": "Internet Central Limited",
      "CountryISO": "GB",
      "CountryName": "United Kingdom",
      "City": "Stoke-on-Trent",
      "MetroCode": "",
      "Organization": "",
      "RegionName": "England",
      "RegionISO": "ENG"
    },
    "AllowedFileTypes": "pdf, doc, docx, xls, xlsx, pptx, rtf, txt, jpg, gif, bmp, png, xml",
    "PreChatSurvey": {
      "Enabled": true,
      "Fields": [
        {
          "FieldName": "VisitorName",
          "FieldType": "name",
          "Enabled": true,
          "Prompt": "Please enter your name:",
          "Length": 100,
          "MultiLine": false,
          "Lines": 0,
          "Password": false,
          "ChangeCase": 0,
          "Mask": "",
          "DefaultValue": "",
          "DefaultDateToday": false,
          "DefaultTimeToday": false,
          "SelectType": "",
          "ValidateLow": -1,
          "ValidateHigh": -1,
          "RequiredField": true,
          "SelectOptions": [],
          "HTML5Type": "text"
        },
        {
          "FieldName": "Company",
          "FieldType": "company",
          "Enabled": true,
          "Prompt": "Please enter your company name:",
          "Length": 200,
          "MultiLine": false,
          "Lines": 0,
          "Password": false,
          "ChangeCase": 2,
          "Mask": "",
          "DefaultValue": "",
          "DefaultDateToday": false,
          "DefaultTimeToday": false,
          "SelectType": "",
          "ValidateLow": -1,
          "ValidateHigh": -1,
          "RequiredField": false,
          "SelectOptions": [],
          "HTML5Type": "text"
        }
      ]
    },
    "PostChatSurvey": {
      "Enabled": true,
      "Fields": [
        {
          "FieldName": "Rating",
          "FieldType": "rating",
          "Enabled": true,
          "Prompt": "Please rate your chat experience:",
          "Length": 0,
          "MultiLine": false,
          "Lines": 0,
          "Password": false,
          "ChangeCase": 0,
          "Mask": "",
          "DefaultValue": "",
          "DefaultDateToday": false,
          "DefaultTimeToday": false,
          "SelectType": "",
          "ValidateLow": -1,
          "ValidateHigh": 5,
          "RequiredField": false,
          "SelectOptions": [],
          "HTML5Type": "range"
        },
        {
          "FieldName": "transEmail",
          "FieldType": "text",
          "Enabled": true,
          "Prompt": "Enter your email address to receive a transcript of this chat",
          "Length": 250,
          "MultiLine": false,
          "Lines": 0,
          "Password": false,
          "ChangeCase": 0,
          "Mask": "",
          "DefaultValue": "",
          "DefaultDateToday": false,
          "DefaultTimeToday": false,
          "SelectType": "",
          "ValidateLow": 0,
          "ValidateHigh": 0,
          "RequiredField": false,
          "SelectOptions": [],
          "HTML5Type": "email"
        },
        {
          "FieldName": "Mailing",
          "FieldType": "boolean",
          "Enabled": true,
          "Prompt": "Join our mailing list?",
          "Length": 0,
          "MultiLine": false,
          "Lines": 0,
          "Password": false,
          "ChangeCase": 0,
          "Mask": "",
          "DefaultValue": "Y",
          "DefaultDateToday": false,
          "DefaultTimeToday": false,
          "SelectType": "",
          "ValidateLow": -1,
          "ValidateHigh": -1,
          "RequiredField": false,
          "SelectOptions": [],
          "HTML5Type": "checkbox"
        },
        {
          "FieldName": "FindMethod",
          "FieldType": "select",
          "Enabled": true,
          "Prompt": "How did you find us?",
          "Length": 0,
          "MultiLine": false,
          "Lines": 0,
          "Password": false,
          "ChangeCase": 0,
          "Mask": "",
          "DefaultValue": "",
          "DefaultDateToday": false,
          "DefaultTimeToday": false,
          "SelectType": "select",
          "ValidateLow": -1,
          "ValidateHigh": -1,
          "RequiredField": false,
          "SelectOptions": [
            "Google",
            "LinkedIn Ad",
            "Twitter Ad"
          ],
          "HTML5Type": "text"
        }
      ]
    },
    "Translation": {
      "Enabled": true,
      "DefaultLanguage": "en",
      "Languages": [
        {
          "ISO2": "en",
          "DisplayAs": "English",
          "Selected": false
        },
        {
          "ISO2": "fr",
          "DisplayAs": "French",
          "Selected": false
        },
        {
          "ISO2": "de",
          "DisplayAs": "German",
          "Selected": false
        }
      ],
      "ShowLanguageSelector": false,
      "ShowAsOverlay": false,
      "ForceTranslation": false
    },
    "CallbackEnabled": true,
    "LeaveMessageEnabled": true,
    "VisitorSingleUseFiles": 0,
    "ServerBuild": "19.1.385.800"
  }
}

Copy

The SessionID property is a unique server created Session ID that can be used for the chat session. A new Session ID is created each time a valid Connect command is sent. Most commands following a Connect command require a session ID to uniquely identify the current chat session.

The OpeningMessage property contains the site-defined opening message text. You should display this text in your chat window.

The PreChatSurvey list contains a list of fields that the visitor should complete before starting the chat. The PostChatSurvey list contains a list of fields that the visitor should complete after the chat session has ended.

The GeoIP object contains the Visitor Geo-IP location information obtained from the Visitor IP address parameter passed with the Connect command.

The AllowedFileTypes property contains a comma separated list of file extensions that visitors can upload during chat sessions. If this field is blank, then no file uploading is allowed.

The Translation object contains chat translation options defined for the WhosOn Site. If Translation is enabled then the WhosOn Server will automatically translate chat messages if the visitor's language is not the same as the operator.

Survey Fields

The connected event contains a list of pre and post chat survey fields. For example:

{
  "FieldName": "FindMethod",
  "FieldType": "select",
  "Enabled": true,
  "Prompt": "How did you find us?",
  "Length": 0,
  "MultiLine": false,
  "Lines": 0,
  "Password": false,
  "ChangeCase": 0,
  "Mask": "",
  "DefaultValue": "",
  "DefaultDateToday": false,
  "DefaultTimeToday": false,
  "SelectType": "select",
  "ValidateLow": -1,
  "ValidateHigh": -1,
  "RequiredField": false,
  "SelectOptions": [
       "Google",
       "LinkedIn Ad",
       "Twitter Ad"
    ],
  "HTML5Type": "text"
}

Copy

Any number of fields can be created for the pre and post chat survey using the WhosOn Settings Portal.

Your chat application should ask the visitor to input data for each field before the chat starts (Pre-Chat) and after the chat has finished (Post-Chat).

Field Properties

Property Name Details
FieldName A unique name for the field.
FieldType The type of field being one of (text, numeric, date, time, boolean, select, rating, company, email)
Enabled 'true' if the field is currently enabled.
Prompt The prompt text to display.
Length The maximum number of characters allowed (or zero for no limit).
MultiLine 'true' if the input can be over multiple lines (a textarea).
Lines The maximum number of lines for a MultiLine input.
Password 'true' if the field is a password (password masking should be used).
ChangeCase A numeric value (0=No Change, 1=Upper Case, 2=Word Capitalize, 3=Lower Case).
Mask A regular expression mask has been defined for the field.
DefaultValue The default value for the field if any.
DefaultDateToday If FieldType is 'date' then the input should default to today's date.
DefaultTimeToday If FieldType is 'time' then the input should default to the current time.
SelectType If FieldType is 'select' then this will be either 'select' where the options should be displayed as a Select Box or 'radio' where the options should be displayed as Radio buttons.
ValidateLow If FieldType is 'numeric' this is the lowest value that should be accepted (or -1 for no lower limit).
ValidateHigh If FieldType is 'numeric' this is the highest value that should be accepted (or -1 for no upper limit).
RequiredField 'true' if the field is required.
SelectOptions If FieldType is 'select' then this will contain a list of allowed values.
HTML5Type This field indicates the HTML5 input type that can be used for the field. You do not need to use this and can use whatever input methods you choose.

The fields passed with the connected event are based on the Survey Fields setup in the WhosOn Settings Portal against the selected site. It is up to you how you collect the information for the fields from the visitor.

Survey Field data is passed back to the WhosOn Server using an XML block:

<Fields><Field><Name>fieldname</Name><Value>fieldvalue</Value</Field>…. </Fields>

Copy

You can also include additional fields here – they do not need to be setup in WhosOn. The WhosOn Server will record all fields passed in the XML block against the chat – regardless of if they are setup in the Site Properties. This enables you to pass additional data to a chat session without defining Survey Fields in advance.

Chat Sessions

Once you have sent the Connect command and received the connected event you should store the Session ID & Domain Name to use on subsequent commands.

You should then construct the Pre-Chat Survey and offer this to the visitor to complete. Display the OpeningMessage at the start of the pre-chat survey.

To start a chat, send the Hello command:

Hello (Command)

{
  "Command": "Hello",
  "Parameters": [
    "Thomas",
    "www.mycompany.com",
    "",
    "",
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "195.62.193.194",
    "287-3883882",
    "en",
    "false",
    "<Fields><Field><Name>Company</Name><Value>IBM</Value></Field></Fields>"
  ]
}

Copy

Parameters:

  1. Visitor Name.
  2. Domain Name.
  3. Department.
  4. Operator Name.
  5. Chat Session ID.
  6. Visitor IP Address. If blank the WebSocket connection IP (or X-Forwarded-For) will be used.
  7. Visitor Cookie Session ID.
  8. Language code (two-letter).
  9. Translation required.
  10. Pre-Chat Survey (XML).

The Chat Session ID should be the SessionID value from the connected event.

The Pre-Chat Survey should be an XML block enclosed in <Fields> tags. Each field should be:

<Field>
    <Name>fieldname</Name>
    <Value>fieldvalue</Value>
</Field>

Copy

You do not need to pass the Visitor Name in the Pre-Chat survey – however it can be included (the Visitor Name should still be passed as the first parameter). You can include additional fields in the Pre-Chat Survey XML that are not part of the server returned pre-chat survey (field names must be unique). Additional fields will still be recorded against the chat.

The Translation Required parameter can be 'true' or 'false'. If True, then Translation will be activated using the Visitor's language specified with the Language Code parameter. Translation will not be performed if the chat is picked up by an operator that has the same language as the visitor.

If a Department is specified, then the chat request will be sent to only those operators with a matching department (or no department). This is optional (pass a blank string for no department).

If an Operator Name is specified, then the chat request will be sent only to the specified operator. This is optional. Pass a blank string to send the chat request to all operators - based on the WhosOn Server routing rules.

The server will respond to the Hello command with either an accepted or notaccepted event.

Accepted (Event)

{
  "EventName": "accepted",
  "ChatUid": "gq0i7smlen",
  "Data": "Please wait. An operator will be with you shortly."
}

Copy

If the chat is accepted the server will send the accepted event.

ChatUid will contain the server generated unique ID for the current chat session.

Data contains the default Paging Message. The paging message will also be sent as the first newline event.

After this event is received you should display the OnlineMessage as specified in the connected event.

The WhosOn Server will then send the chat request to operators (based on status & routing rules). Whilst waiting for an operator to pick up the chat the server will send waiting & queueing messages to the chat session as newline events.

NotAccepted (Event)

{
  "EventName": "notaccepted",
  "ChatUid": "gq0i7smlen",
  "Data": "No operators are available at this time. Operators may only be available during office hours. The time is currently 12:26."
}

Copy

The notaccepted event is sent if the server is unable to accept the chat request.

ChatUid will contain the server generated unique ID for the current chat session.

Data will contain the message to display or a forwarding URL.

If the LeaveMessageEnabled property of the connected event is True, then you can offer the visitor the option of leaving a message. See: LeaveMessage

If the LeaveMessageEnabled property is False and the ForwardingUrl property of the connected event is not blank, then you can forward the visitor to the URL specified.

NewLine (Event)

All chat lines are sent in newline events. This includes both operator and visitor messages. Data contains Classname and Content properties. Classname is the type of message and you can use this to provide different styling according to the message type.

Class Names

Classname Type
pagingmessage The first line sent after a chat is accepted.
lineo linewaiting1 The first 'waiting' message sent before an operator picks up the chat.
lineo linewaiting2 The second 'waiting' message sent before an operator picks up the chat.
lineo final The final waiting message sent only if an operator has not picked up the chat before the waiting limit has been reached.
queuemessage Messages sent whilst the chat is waiting in a queue.
linesays A line preceding a chat line indicating the operator or visitor has said something.
linev A line from the visitor.
lineo A line from the operator.
linet A line from the operator that is a translation of the previous line (if translation is enabled for that chat session).

Content can contain HTML (for example links), however the WhosOn Server restricts HTML content to only a fixed number of allowed tags.

Markdown

Operators can include Markdown text in chat messages. The WhosOn Server will convert Markdown to HTML before sending newline events.

Paging Message

{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "pagingmessage",
    "Content": "Please wait. An operator will be with you shortly."
  }
}

Copy

The Paging Message is sent as a newline event.

The Paging message is the first line that is sent after a chat is accepted. It will have the class name pagingmessage.

Waiting Messages

{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "lineo linewaiting1",
    "Content": "One moment please..."
  }
}

Copy

{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "lineo linewaiting2",
    "Content": "We apologize for the delay. An operator will be with you shortly."
  }
}

Copy

Waiting messages are sent whilst waiting for an operator to pickup the chat session and the chat is not in a queue. The interval between the 1st and 2nd waiting message is defined in the Site Properties.

The ClassName will be 'lineo linewaiting1' and 'lineo linewaiting2'.

Final Waiting Message

If no operator picks up the chat after a period (defined in the Site Properties) then the final waiting message will be sent:

{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "lineo final",
    "Content": "No operators are available at this time. Operators may only be available during office hours. The time is currently 08:54."
  }
}

Copy

This will have the ClassName 'lineo final'

If the LeaveMessageEnabled property of the connected event is True, then you can offer the visitor the option of leaving a message.

If the LeaveMessageEnabled property is False and the ForwardingURL property of the connected event is not blank, then you can forward the visitor to the URL specified.

Queuing

Depending on the Site routing rules – chat requests can be added to a queue if no operators are available to take the chat. In these cases, the server will send newline events once per minute while the chat is in the queue.

{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "queuemessage",
    "Content": "Thank you for waiting. You are in position 3 of 10."
  }
}

Copy

Chats remain in a queue until the chat is picked up by an operator or until the queue timeout time is reached (defined by the Rule properties). A notaccepted event will be sent when a chat in a queue reaches the timeout value.

The Server will also send queue events approximately once per second whilst a chat is in a queue:

Queue (Event)

{
  "EventName": "queue",
  "ChatUid": "gq0i7smlen",
  "Data": "2"
}

Copy

Data field will contain the current queue position.

Ending A Chat

If you receive the final waiting message or a notaccepted event if the chat was in a queue – you should end the chat and optionally offer the visitor, the option of leaving a message.

To end the chat, send the Quit command:

Quit (Command)

{
  "Command": "Quit",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com"
  ]
}

Copy

Parameters: Chat Session ID, Domain

Sending the Quit command stops the chat from showing as waiting for operators.

Chat Picked Up By An Operator

When a chat is picked up by an operator your chat session will first receive a operatorjoined event and then start receiving newline events:

OperatorJoined (Event)

{
  "EventName": "operatorjoined",
  "ChatUid": "gq0i7smlen",
  "Data": {
     "Name": "Howard Williams",
     "Email": "howard@mycompany.com",
     "Phone": "+441782822577",
     "Dept": "",
     "Skills": [
       "Sales",
       "Marketing"
     ],
     "IsBot": "False",
     "Status": "Online",
     "Lang": "en"
   },
}

Copy

This event provides details of the operator that has picked up the chat. The IsBot property indicates if the operator that has picked up the chat is a bot.

From then on you will receive newline events as the operator (or bot) sends messages:

NewLine (Event)

{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "linesays",
    "Content": "Howard Williams says:"
  }
}
{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "lineo",
    "Content": "Good Morning Thomas. My name is Howard Williams how can I help you?"
  }
}

Copy

Operator Typing Status

The WhosOn Server will send events when the operator starts and stops typing. Use these events to display an 'operator is typing' indicator.

Typing (Event)

{
  "EventName": "typing",
  "ChatUid": "gq0i7smlen",
  "Data": ""
}

Copy

TypingStop (Event)

{
  "EventName": "typingstop",
  "ChatUid": "gq0i7smlen",
  "Data": ""
}

Copy

Sending A Message

To send a chat message send the Message command:

Message (Command)

{
  "Command": "Message",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com",
    "Could you please help me with product installation"
  ]
}

Copy

Parameters: Chat Session ID, Domain Name, Line Text (max 4000 characters).

The WhosOn Server will send the message to the operator. The newline event will also be sent back to the chat session:

{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "linesays",
    "Content": "Thomas says:"
  }
}

Copy

{
  "EventName": "newline",
  "ChatUid": "gq0i7smlen",
  "Data": {
    "Classname": "linev",
    "Content": "Could you please help me with product installation"
  }
}

Copy

newline events are sent for both operator and visitor lines. For visitor lines the class will be 'linev'.

Note: Your chat client should update the chat view in response to newline events, rather that directly after any Message commands. This is because the WhosOn Server may change the sent message content due to Translation or Chat Text Rules.

Handling Translation

If Translation is enabled for the chat session, then operator sent chat lines will also include a translated version of the operator's text. This will be sent as an additional newline event with the ClassName of 'linet'.

For visitor sent lines you can either make use of your own translation or allow the WhosOn Server to translate the text if translation is enabled for the Site and the current chat session.

To send a visitor line including your own translation you should append the original (untranslated) visitor text to the message text enclosed in <original></original> tags:

{
  "Command": "Message",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com",
    "Hello<original>Bonjour</original>"
  ]
}

Copy

If you do not add the <Original> tag and Translation is enabled for the Site then the WhosOn Server will handle the translation before the message is sent to the operator.

Sending Visitor Preview

You can send a preview of visitor typed text – before the visitor sends a message. Previewed text will be sent to the operator, allowing the operator to view what the visitor has typed so far. Chat preview can be disabled in the Site Properties. The OperatorPreview property of in the connected event will be True if preview is allowed.

To send preview text send the Preview command:

Preview (Command)
{
  "Command": "Preview",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com",
    "I would li"
  ]
}

Copy

Parameters: Chat Session ID, Domain, Typed text.

You can send the Preview command on every key press or enable a timer and send the current text every few seconds.

Note: Use of the Preview feature is optional. The Preview command will be ignored by the WhosOn Server if OperatorPreview is not enabled for the Site.

Sending Files

Visitors can send files during chat sessions, provided visitor file uploading is allowed in the Site Properties.

Before you can send a file through the Chat Session you need to upload the file to the WhosOn Document Store. This is done using the DocumentWriteForSite method on the WhosOn Web Services. The Web Services URL is returned with the connected event. This method will upload a file and return a unique URL which you include with the File command.

File (Command)

{
  "Command": "File",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com",
    "mydocument.pdf",
    "http://chat.mycompany.com/whosoncharts/document.aspx?f=dfc3ffd72bb9416194aaea7c6f14b449f4629aafd2830e0b4716.pdf"
  ]
}

Copy

Parameters:

  • Chat Session ID
  • Domain Name
  • File Name
  • URL Link to file in WhosOn Document Store

The File extension must be one of the allowed file extensions specified in the AllowedFileTypes property of the Site and Visitor file uploading must be enabled, otherwise an error event will be sent:

{
  "EventName": "error",
  "ChatUid": "gq0i7smlen",
  "Data": "You cannot upload files of this type."
}

Copy

Operator Requesting Files

Operators can request that the visitor uploads a file. Your chat session will receive the requestfile event.

RequestFile (Event)

{
  "EventName": "requestfile",
  "ChatUid": "gq0i7smlen",
  "Data": "pdf, doc"
}

Copy

Data will contain a comma separated list of allow file extensions.

If your chat session receives this event you should offer the visitor the option of uploading a file.

Operator Requested Dynamic Fields

Operators can request that the visitor complete a dynamic survey field during a chat session. You will receive the requestfield event:

RequestField (Event)

{
  "EventName": "requestfield",
  "ChatUid": "gq0i7smlen",
  "Data": {
      "FieldName": "OrderNumber",
      "FieldType": "text",
      "Enabled": true,
      "Prompt": "Please enter the order number:",
      "Length": 10,
      "MultiLine": false,
      "Lines": 0,
      "Password": false,
      "ChangeCase": 1,
      "Mask": "",
      "DefaultValue": "",
      "DefaultDateToday": false,
      "DefaultTimeToday": false,
      "SelectType": "",
      "ValidateLow": 0,
      "ValidateHigh": 0,
      "RequiredField": false,
      "SelectOptions": [],
      "HTML5Type": "text"
    }
}

Copy

You should then construct user input to match the field and validate. Then send the input data with a DynamicField command:

DynamicField (Command)

{
  "Command": "DynamicField",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com",
    "OrderNumber",
    "12345"
  ]
}

Copy

Sends the result of a dynamic field request.

Parameters: Chat Session ID, Domain, Field Name, Field Value

The field will be added to the chat session fields (and show with the Survey Fields for operators). A new chat line will also be added.

Sending Visitor Typing Status

You should send StartTyping and StopTyping commands when the visitor starts and stops typing – the WhosOn Server will then inform the operator that the visitor has started or stopped typing.

StartTyping (Command)

{
  "Command": "StartTyping",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a"
  ]
}

Copy

Parameters: Chat Session ID

This command informs the WhosOn Server that the visitor has started typing.

StopTyping (Command)

{
  "Command": "StopTyping",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a"
  ]
}

Copy

Parameters: Chat Session ID

This command informs the WhosOn Server that the visitor has stopped typing. You do not need to send this command before sending a Message command. The server assumes when it receives a visitor message that the visitor has stopped typing.

In your chat application you need to enable a timer when the visitor presses a key in the chat message text box. If the timer was not already enabled – send the StartTyping command and enable the timer. If the timer is already enabled – record the time of the last keypress. In the timer event compare the last key press time with the current time and if a period of (say) 2 seconds has elapsed – send the StopTyping command and disable the timer.

Ending A Chat

Chat sessions can be ended by the visitor, operator or by the server (based on inactivity timeout). To end a chat from the visitor side, send the Quit command:

Quit (Command)

{
  "Command": "Quit",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com"
  ]
}

Copy

Parameters: Chat Session ID, Domain

If the operator ends the chat the WhosOn Server will send the quit event:

Quit (Event)

The quit event will be received if the operator or server ends the chat.

{
  "EventName": "quit",
  "ChatUid": "gq0i7smlen",
  "Data": ""
}

Copy

Regardless of how the chat ends, if the chat was accepted you should then offer the visitor the option of completing the Post Chat Survey.

The Post Chat Survey fields will have been sent in the connected event.

Once the visitor has completed the Post Chat Survey you should send the PostChatSurvey command:

PostChatSurvey (Command)

{
  "Command": "PostChatSurvey",
  "Parameters": [
    "gq0i7smlen",
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com",
    "195.62.193.194",
    "<Fields><Field><Name>Rating</Name><Value>5</Value></Field></Fields>"
  ]
}

Copy

Parameters:

  1. Chat Uid
  2. Chat Session ID
  3. Domain Name
  4. Visitor IP Address
  5. Post Chat Survey XML

The Post-Chat Survey should be an XML block enclosed in <Fields> tags. Each field should be:

<Field>
    <Name>fieldname</Name>
    <Value>fieldvalue</Value>
</Field>

Copy

You can also include additional field values for data not included in the post-chat survey (provided the 'fieldnames' are unique).

When the Post Chat Survey is accepted by the WhosOn Server, the server will send an acknowledged event:

{
  "EventName": "acknowledged",
  "ChatUid": "",
  "Data": ""
}

Copy

Requesting A Transcript

You can request that the WhosOn Server sends an email of the chat transcript using the Transcript command.

Transcript (Command)

{
  "Command": "Transcript",
  "Parameters": [
    "gq0i7smlen",
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com",
    "195.62.193.194",
    "thomas@test.com"
  ]
}

Copy

Parameters: Chat Uid, Chat Session ID, Domain, Visitor IP Address, Visitor Email

The Transcript command can be sent at any time after a chat session starts – and after it has completed.

The chat transcript will be sent to the email address provided. The email address will also be added to the visitor record. The WhosOn Server can also be configured to automatically send transcripts to visitors that supply an email address (via the pre/post chat survey or during the chat).

Leaving Messages

If a chat is not accepted (IE: You receive the notaccepted event) and the LeaveMessage property of the connected event is True, then you can offer the visitor the option of leaving a message. You can also offer a 'Leave A Message' form at any point – you do not need to attempt to start a chat session first. Left messages will be added as 'missed chats', which operators can respond to later.

To leave a message send the LeaveMessage command:

LeaveMessage (Command)

{
  "Command": "LeaveMessage",
  "Parameters": [
      "sjbhpx4nxc",
        "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
        "www.mycompany.com",
        "195.62.193.194",
        "Thomas",
        "",
        "thomas@test.com",
        "07799123456",
        "Please call back as soon as possible"
    ]
}

Copy

Parameters:

  1. Chat Uid
  2. Chat Session ID
  3. Domain name
  4. Visitor IP Address
  5. Visitor Name
  6. Department
  7. Visitor Email Address
  8. Visitor Phone Number
  9. Message Text

The Chat Uid/Chat Session ID can be blank if you have not attempted to start a chat session beforehand.

The Department, Visitor Email Address & Visitor Phone Number are optional. If an Email Address is supplied then operators will be able to respond to the missed chat via email (using the WhosOn Client). If a Phone Number is supplied then operators can respond with a Callback (if phone callbacks are enabled on the WhosOn Server).

Other Commands

GetOperators (Command)

This command can be used to request a list of operators. Normally chat requests are routed to the correct operators based on server rules, so there is no need to know available operators in advance. However you can use this command if you wish to show a list of chat operators to the visitor and allow the visitor to select an operator. The GetOperators command can be sent after establishing a chat session, before sending the Hello command.

{
  "Command": "GetOperators",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com"
  ]
}

Copy

Parameters: Chat Session ID, Domain Name

A list of operators for the given domain will be returned in the operators event.

Operators (Event)

{
  "EventName": "operators",
  "ChatUid": null,
  "Data": [
    {
      "Name": "Howard Williams",
      "Email": "howard@mycompany.com",
      "Phone": "+441782822577",
      "Dept": "",
      "Skills": [
        "Sales",
        "Marketing"
      ],
      "IsBot": "False",
      "Status": "Online",
      "Lang": "en"
    },
    {
      "Name": "Daniel Tallentire",
      "Email": "daniel@mycompany.com",
      "Phone": "+441782822577",
      "Dept": "",
      "Skills": [
        "Technical Support",
        "Training"
      ],
      "IsBot": "False",
      "Status": "Busy",
      "Lang": "en"
    }
  ]
}

Copy

IsBot will be True if the operator is a bot.

Status will be one of: Online,Busy,Be Right Back, Away

GetImage (Command)

This command can be used to request an image assigned to the site. Images are set using the WhosOn Settings Portal - Chat Designer. You can request any of the image types. Images can be requested at any point after establishing a chat session.

{
  "Command": "GetImage",
  "Parameters": [
    "d6e76b3c-b1fc-4e13-9ee6-f4a788a5269a",
    "www.mycompany.com",
    "1"
  ]
}

Copy

Parameters:

  • Chat Session ID
  • Domain name
  • ImageType

Where ImageType is one of:

ImageType Description
1 Chat button 'available' image.
2 Chat button 'not available' image.
5 Site logo image.
8 Site mobile logo image.

The WhosOn Server will send an image event:

Image (Event)

{
  "EventName": "image",
  "ChatUid": "",
  "Data": {
      "Domain": "www.mycompany.com",
      "ImageType": 1,
      "Language": "en",
      "Ext": ".png",
      "Base64": "{base64}"
    }
}

Copy

{base64} will contain the Base 64 encoded image string.