Developers

Chat Object

Methods

init(options, config, historyWatch)
Initializes the chat data (loads it from the server or creates a new chat)

options Object

  • room String: Target room for the chat.
  • lang String: Language of the chat.
  • source String: Source of the chat.
  • id String: Id of the chat. If id is passed, the chat will be loaded from the server.

config Object optional

  • assignMaxAttempts Number: Maximum number of attempts to assign the chat.
  • assignTimeout Number: Time in seconds a chat will be assign to an agent before performing another attempt.

historyWatch optional Boolean: Whether to include actions performed by chat watchers in history or not.

return Promise{Chat}

You can check the Chat object definition here in the Chat section.

searchAgent(algorithm)
Look for an agent to attend the chat using the provided algorithm.

  • algorithm optional String: Algorithm name

return Promise{Object}

Response object:

{
    agent: {
        id,
        name,
        nickname,
        providerId
    }
}

sendUserActivity(type)
Send user activity

  • type String: Type of activity ('writing', 'stop-writing' or 'not-writing')

return Promise{Object}

Response object:

{
    success: Boolean
}

sendMessage(message, onCreate)
Send a message

  • message String: Message text
  • onCreate Function: Callback executed when message is created on the server

return Promise{Object}

The response object is an object like the postChatMessageResponse definition documented here in the postChatMessageResponse section.

readMessage(messageId)
Send a message read event

  • messageId String: Id of the read message

return Promise{Object}

The response object is an object like the postChatMessageResponse definition documented here in the postChatMessageResponse section.

sendMedia(media, onProgress)
Send media

  • media Object
    An instance of File

  • onProgress Function: Callback executed when there's progress on the upload

return Promise{Object}

Response object:

{
    media: {
        id,
        name,
        size,
        senderId
    }
}

close(extraData)
Close the chat

  • extraData optional Object: Other data you want to attach to the close action.

return Promise{Object}

Response object:

{
    success: Boolean
}

hasOtherUsers()
Whether the chat has other users or not

return Boolean: Whether the chat has other users or not

getId()
Retrieves the chat ID

return String: The chat ID

importHistory(history)
Import external history into the chat

  • history Array: History entries to be imported. You can check the definition of a History Entry here in the HistoryEntry section

return Array: The full chat history

Events

'user:joined'
Triggered when a user joins the chat

Event data:

{
  chat, // Object with chat properties
  mode, // String 'watch' or empty otherwise
  sender, // String with the sender id
  transfer, // Boolean stating whether the join is from a transfer or not
  user // Object with the user properties
}

'user:left'
Triggered when a user leaves the chat

Event data:

{ chatId, userId }

'user:activity'
Triggered when user activity is received

Event data:

{ 
    userId, 
    type // 'writing', 'stop-writing' or 'not-writing'
}

'message:received'
Triggered when a message is received

The event data is an object like the postChatMessageResponse definition documented here in the postChatMessageResponse section.

'message:read'
Triggered when a message read is received

The event data is an object like the postChatMessageResponse definition documented here in the postChatMessageResponse section.

'chat:closed'
Triggered when the chat is closed

Event data:

{ chatId, userId }

'chat:intervened'
Triggered when a chat is intervened

Event data:

{ 
    chat, // intervened chat object
    interventor // interventor user object
}

'forever:alone'
Triggered when there aren't any agents available for a chat

Event data:

{ chatId }

'queue:update'
Only works if queue mode is active. Triggered when the chat is in queue and its position in the queue changed.

Event data:

{ queuePosition, waitingTime }

'chat:timer:expiryAlert'
Triggered when the chat is close to expiration.

Event data:

{ 
    chatId, 
    timeLeft // in seconds 
}

Properties

The Chat object properties match the Chat object definition, which can be checked here in the Chat section.