Constructor
new VivochaAgentContact()
Extends
Members
(readonly) idle
Idle state of the contact.
(readonly) isMine
The contact is currently routed only to the agent: can be declined and if it times out, the agent will be put in a forced pause state.
(readonly) mediaState
- Overrides:
Current media transition state. The possible values are:
(readonly) secure :boolean
- Overrides:
Flag set to true
is the contact is using end-to-end encryption.
Type:
- boolean
Methods
setIdle(idle)
Set/Unset the idle state of the contact
Parameters:
Name | Type | Description |
---|---|---|
idle |
boolean | New idle state |
Fires:
moveTo(list)
Move the contact to the specified contact list
Parameters:
Name | Type | Description |
---|---|---|
list |
string |
Fires:
assign(callback)
Assign the contact to the agent, if the operation succeeds, the contact is also moved to the assigned contact list.
Parameters:
Name | Type | Description |
---|---|---|
callback |
GenericCallback |
decline(callback)
Decline a pending contact. Only contacts that were routed to a single agent can be declined.
Parameters:
Name | Type | Description |
---|---|---|
callback |
GenericCallback | Called when the operation is completed. |
clear(callback)
Clear a pending contact. Only contacts that were routed to the current agent can be cleared.
Parameters:
Name | Type | Description |
---|---|---|
callback |
GenericCallback | Called when the operation is completed. |
loadVisit(full, callback)
Downloads from the Vivocha server the details of the current customer visit.
Parameters:
Name | Type | Description |
---|---|---|
full |
boolean | If |
callback |
VivochaAgentContact~VisitCallback | The callback to receive the visit data. |
updateData(data, callback)
Update the data attached to the contact. NOTE: the remote party is not notified when the update occurs, use a custom request to notify the remote party.
Parameters:
Name | Type | Description |
---|---|---|
data |
DataCollection | The data to save in the contact |
callback |
GenericCallback | Called when the operation is completed. |
transfer(opts, callback)
Transfer the contact to another agent or another groups of agents.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
object |
Properties
|
||||||||||||||||||||||||
callback |
GenericCallback | Called when the operation is completed. |
setSyncToken(callback)
- To Do:
-
- add link to docs.vivocha.com
Generate a new synchronization id for the contact.
Parameters:
Name | Type | Description |
---|---|---|
callback |
VivochaAgentContact~SyncCallback | Called when the operation is complete. |
isRecording() → {Promise}
Check and returns the recording status of the WebRTC media engine.
Returns:
Resolved with the result of the checks:
true
if there is an active recording.false
if there isn't any active recording.
- Type
- Promise
startRecording(audioInopt, audioOutopt, videoInopt, videoOutopt) → {Promise}
Start the media recording on the WebRTC media engine for the specified channels.
Examples
contact.startRecording(true, true).then(function() {
console.log('Recording successfully started');
});
contact.startRecording(true, true, true, true).then(function() {
console.log('Recording successfully started');
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
audioIn |
boolean |
<optional> |
Enable recording for incoming audio. |
audioOut |
boolean |
<optional> |
Enable recording for outgoing audio. |
videoIn |
boolean |
<optional> |
Enable recording for incoming video. |
videoOut |
boolean |
<optional> |
Enable recording for outgoing video. |
Returns:
Resolved when the recording is started.
- Type
- Promise
stopRecording() → {Promise}
Stop the media recording on the WebRTC media engine.
Example
contact.stopRecording().then(function() {
console.log('Recording successfully stopped');
});
Returns:
Resolved when the recording is stopped.
- Type
- Promise
mergeMedia(newMedia) → {Promise}
- Overrides:
Merges the passed newMedia
with the current media state. This method does not change the media state, it merely
returns a description how the current state would be after being merged with the differences listed in newMedia
.
Example
// Imagine the current media state (i.e. what contact.getMedia() would return) is:
{
"Sharing": {
"tx": true,
"rx": true,
"via": "net",
"engine": "Native"
},
"Chat": {
"tx": true,
"rx": true,
"via": "net",
"engine": "Native"
}
}
// Calling mergeMedia
contact.mergeMedia({
"Voice": {
"tx": true,
"rx": true,
"via": "net",
"engine": "WebRTC"
}
})
// The result of mergeMedia
{
"Sharing": {
"tx": true,
"rx": true,
"via": "net",
"engine": "Native"
},
"Chat": {
"tx": true,
"rx": true,
"via": "net",
"engine": "Native"
},
"Voice": {
"tx": true,
"rx": true,
"via": "net",
"engine": "WebRTC"
}
}
Parameters:
Name | Type | Description |
---|---|---|
newMedia |
MediaState | The media to merge to the current one. |
Returns:
Resolved to the current state merged with newMedia
.
- Type
- Promise
setLocalCapability(path, value) → {Promise}
- Overrides:
Set a single local capability. The a capability exchange has already happened, the remote is notified of update.
Parameters:
Name | Type | Description |
---|---|---|
path |
string | Dotted path of the capability to set, "a.b.c" |
value |
* | value, value to set, must be a value that can be converted to string using |
Returns:
Resolves to a MediaCapabilities object, containing the full set of local capabilities, including the value just set.
- Type
- Promise
setLocalCapabilities(caps) → {Promise}
- Overrides:
Set the local capabilities. The a capability exchange has already happened, the remote is notified of the update.
Parameters:
Name | Type | Description |
---|---|---|
caps |
MediaCapabilities | The new local capabilities |
Returns:
Resolves to a MediaCapabilities object, containing the capabilies just set.
- Type
- Promise
getLocalCapabilities() → {Promise}
- Overrides:
Return the local capabilities.
Returns:
Resolves to a MediaCapabilities object.
- Type
- Promise
getRemoteCapabilities() → {Promise}
- Overrides:
Return the local capabilities. If these are not locally available, a capability exchange is started.
Returns:
Resolves to a MediaCapabilities object.
- Type
- Promise
(async) updateRemoteCapabilities() → {Promise}
- Overrides:
Initiate a capability exchange with the remote party: the local capabilities are sent to the remote and its
capabilities are requested and returned. After the first time a capability exchange is performed, any change to
the local caps is immediately notified to the remote party. Similarly, any change to the remote caps is notified
locally via a capabilities
event.
Returns:
Resolves to a MediaCapabilities object.
- Type
- Promise
data() → {ContactData}
- Overrides:
Return the raw contact data (i.e. the contact record as stored in Vivocha servers).
Returns:
- Type
- ContactData
encrypt(text) → {string}
- Overrides:
Encrypt the input text using AES256. The contact must be in secure mode.
Parameters:
Name | Type | Description |
---|---|---|
text |
string | The text to encrypt. |
Throws:
-
no_crypto: the CryptoJS library couldn't be loaded.
-
invalid_key: the contact is not secure.
Returns:
- The encrypted and base64 encoded text.
- Type
- string
encryptMessage(msg, fields) → {object}
- Overrides:
Encrypt a message. Only the specified fields are encrypted.
Parameters:
Name | Type | Description |
---|---|---|
msg |
object | The message to encrypt. |
fields |
Array.<string> | List of properties of |
Throws:
-
no_crypto: the CryptoJS library couldn't be loaded.
-
invalid_key: the contact is not secure.
Returns:
The encrypted message. The list of fields that is added to the massage in the encrypted property.
- Type
- object
decrypt(data) → {string}
- Overrides:
Decrypt the input data using AES256. The contact must be in secure mode.
Parameters:
Name | Type | Description |
---|---|---|
data |
string | Base64 encoded data to decode. |
Throws:
-
no_crypto: the CryptoJS library couldn't be loaded.
-
invalid_key: the contact is not secure.
Returns:
- The plaintext.
- Type
- string
decryptMessage(msg) → {object}
- Overrides:
Decrypt all the encrypted properties of a message.
Parameters:
Name | Type | Description |
---|---|---|
msg |
object | The message to decrypt. |
Throws:
-
no_crypto: the CryptoJS library couldn't be loaded.
-
invalid_key: the contact is not secure.
Returns:
- The decrypted message.
- Type
- object
sendText(text, langopt, callbackopt)
- Overrides:
Send a text message to the remote party
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
text |
string | Message body |
|
lang |
string |
<optional> |
ISO 639-1 text language |
callback |
VivochaContact~SendMessageCallback |
<optional> |
Called when the message is sent. |
sendLink(url, descopt, callbackopt)
- Overrides:
Send a link message to the remote party.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url |
string | URL to send. |
|
desc |
string |
<optional> |
Description of the link. |
callback |
VivochaContact~SendMessageCallback |
<optional> |
Called when the message is sent. |
sendAction(code, argsopt, callbackopt)
- Overrides:
Send a custom message to the remote party.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
code |
string | User-defined type of message. |
|
args |
string |
<optional> |
User-defined arguments of the message. |
callback |
VivochaContact~SendMessageCallback |
<optional> |
Called when the message is sent. |
sendIsWriting()
- Overrides:
Notify the remote party that the local one is composing a new message.
join(callback, force)
- Overrides:
Become a partecipant in a contact. For the join to succeed, the contact must have already been assigned to the agent.
Parameters:
Name | Type | Description |
---|---|---|
callback |
GenericCallback | Called when the contact is joined (or if when the join fails) |
force |
boolean | Join the contact even if there's no information on whether it was assigned to the agent. This flag is typically used with third party integrations (e.g. CTI integrations), when an external router assigns the contacts: in this case, the client does not get notified when the assign request succeeds. |
leave(reasonopt, callbackopt)
- Overrides:
Close all channels and disconnect from a contact.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
reason |
string |
<optional> |
Disconnect reason |
callback |
GenericCallback |
<optional> |
Called when the disconnect procedure is over (this includes stopping media acquisition and streaming) |
request(type, dataopt, timeoutopt, retriesopt, callbackopt) → {Promise}
- Overrides:
Request the remote party to perform an action. This method is used to request a Remote Procedure Call (RPC) over the native communication channel of a Vivocha contact. An action is supported if the contact has a registered event handler for it.
Examples
contact.request('PrintDocument', { name: 'contract.pdf', pages: 'all'}).then(function() {
console.log('document successfully printed');
});
contact.on('PrintDocument', function(data, cb) {
// print the file
// call the callback: the first parameter is set in case of error
// the second is used to resolve the remote promise
cb(null, true);
});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
string | Name of the action to request. Conventionally, |
|
data |
<optional> |
Arguments to the action. The data must be serializable using |
|
timeout |
number |
<optional> |
Maximum time to wait for an answer, expressed in milliseconds. If omitted, the request never times out. |
retries |
number |
<optional> |
Retry to to the specified number of times. If omitted, only to attempt is performed. Otherwise, timeout out must be specified too. |
callback |
GenericCallback |
<optional> |
Called when the remote answers the request. If omitted, a Promise is returned. |
Returns:
Resolved when the remote answers the request. Rejected with
timeout
if not answer is received in the expected time and all retries have been attempted.not_supported
if the remote does not support the specified requesttype
- Any other failure defined by the Remote Procedure
- Type
- Promise
sendData(channel, data, topicopt, typeopt) → {Promise}
- Overrides:
Send a custom data packet to the remote party over a DataChannel. If the channel does not already exist,
it's created. There's no guaranteed that the remote party is listening for incoming data on the channel: to ensure
that, additional messaging between the parties might be required (i.e. sending a request
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
channel |
string | The channel name. |
|
data |
* | The data to send, must be a value that can be converted to string using |
|
topic |
string |
<optional> |
User-defined topic of the message. |
type |
type |
<optional> |
Type of channel to create, leave empty to choose automatically, or specify |
Returns:
Resolved if the data is sent.
- Type
- Promise
getDataChannel(id, typeopt) → {Promise}
- Overrides:
Return the DataChannel with the given id. If the channel does not already exist, it's created. Type types of channel are supported:
- WebRTC DataChannel, a peer-to-peer binary data channel between the parties
- WebSocket channel, a text based channel proxied through the Vivocha servers.
Whenever possible, the library will try to use WebRTC channel, to improve the speed and the confidentility of the
data transmission. When that is not possible, the library falls back to WebSockets. It's possible to force the use
of WebSockets setting the argument type to
sio
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
id |
string | Channel id/name. |
|
type |
string |
<optional> |
Pass |
Returns:
Resolves to the requested DataChannel
- Type
- Promise
getMediaEngine(id) → {MediaEngine}
- Overrides:
Return the media engine with the given id
Parameters:
Name | Type | Description |
---|---|---|
id |
string | Media engine id |
Returns:
- Type
- MediaEngine
registerMediaEngine(engine) → {Promise}
- Overrides:
Register a media engine with the contact. Registered engines appear in the capabilities and can be used to negotiate media transitions between parties.
Parameters:
Name | Type | Description |
---|---|---|
engine |
MediaEngine |
Returns:
Resolves to the updated media capabilities
- Type
- Promise
(async) getMedia(clone) → {Promise}
- Overrides:
Get the current state of all media.
Parameters:
Name | Type | Description |
---|---|---|
clone |
boolean | clones media to avoid MediaStream objects |
Returns:
Resolves to the current MediaState
- Type
- Promise
getMediaOffer() → {Promise}
- Overrides:
Create a media offer from the current media state.
Returns:
Resolved to a MediaOffer
- Type
- Promise
getMediaState() → {VivochaContact#mediaState}
- Overrides:
Get the current media transition state.
Returns:
offerMedia(offer, callbackopt) → {Promise}
- Overrides:
Send a media offer to the remote, wait for its answer and, if positive, transition to the new media state.
This method can be called only if the current media transition state is idle.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
offer |
MediaOffer | Offer to send |
|
callback |
VivochaContact~MediaOfferCallback |
<optional> |
The callback to receive the answer. If omitted, the method returns a Promise |
Returns:
Resolved to a MediaState, the received answer.
- Type
- Promise
transitMedia(currentMedia, newMedia, optionsopt) → {Promise}
- Overrides:
Initiates a media transition to a new state. Whenever possible, in place of this method, the use of mergeAndTransitMedia is recommended.
This method can be called only if the current media transition state is idle.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
currentMedia |
MediaState | The starting/current state of the media |
|||||||||||||
newMedia |
MediaState | The state to transit to. This state must be complete: any state not included, will be disabled. |
|||||||||||||
options |
object |
<optional> |
Properties
|
Returns:
Resolved to the final media state at the end of the transition.
- Type
- Promise
(async) mergeAndTransitMedia(media, optionsopt) → {Promise}
- Overrides:
Initiates a media transition to a new state. This method recommended over transitMedia as it lets the caller specify only the media that needs to be changed, as opposed to complete media state.
This method can be called only if the current media transition state is idle.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
media |
MediaState | The changes to apply to the current media. All media and property not explicitly specified will retain the current value. |
|||||||||||||
options |
object |
<optional> |
Properties
|
Returns:
Resolved to the final media state at the end of the transition.
- Type
- Promise
cloneMedia(media, includeData) → {MediaState}
- Overrides:
Create a deep clone of a MediaState object.
Parameters:
Name | Type | Description |
---|---|---|
media |
MediaState | The object to clone. |
includeData |
boolean | If |
Returns:
The cloned object.
- Type
- MediaState
diffMedia(oldMedia, newMedia) → {MediaStateDiff}
- Overrides:
Returns the difference between two MediaState objects as a MediaStateDiff.
Parameters:
Name | Type | Description |
---|---|---|
oldMedia |
MediaState | The first state to compare. |
newMedia |
MediaState | The second state to compare. |
Returns:
The result of the comparison.
- Type
- MediaStateDiff
attach(file, descriptionopt, referenceIdopt, callbackopt) → {Promise}
- Overrides:
Attach a file to the contacts and send it to the remote party.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
file |
File | The file to attach. The argument must be a HTML5 File instance. |
|
description |
string |
<optional> |
Description of the attachment. |
referenceId |
string |
<optional> |
An opaque reference id of the attachment: the same value will be added to the corresponding attachment event. |
callback |
GenericCallback |
<optional> |
If not specified, a Promise is returned. |
Returns:
Resolved when the file is sucessfully uploaded to the Vivocha servers for delivery to the remote.
- Type
- Promise
Type Definitions
VisitCallback(err, visit)
Parameters:
Name | Type | Description |
---|---|---|
err |
* | Set if an error occurred. |
visit |
VisitData | The current customer visit data. |
SyncCallback(err, synchId)
Parameters:
Name | Type | Description |
---|---|---|
err |
* | Set if an error occurred. |
synchId |
string | The new synchronization id. |
Events
isidle
The contact has entered the idle state (no activity detected for a the configured "idle chat timeout")
isactive
The contact has entered the active state (activity detected after isidle event)
queuechange
Properties:
Name | Type | Description |
---|---|---|
assigned |
boolean | The contact was moved from or to the assigned contact list. |
pending |
boolean | The contact was moved from or to the pending contact list. |
hidden |
boolean | The contact was moved from or to the hidden contact list. |
The contact was moved from one contact list to another.
Type:
- object
recready
The recorder is not recording and it's ready to start recording.
recstart
The recorder is starting a new recording.
recstarted
The recorder is recording.
recstopping
The recorder is stopping the current recording session.
text
- Overrides:
New chat message received.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
text |
string | Content of the message. |
|
from_id |
string | Identifier of the sender. |
|
from_nick |
string |
<optional> |
Nickname of the message sender. |
agent |
boolean |
|
localtext
- Overrides:
New chat message sent.
Parameters:
Name | Type | Description |
---|---|---|
text |
string | Content of the message. |
link
- Overrides:
New link received.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url |
string | URL of the link. |
|
from_id |
string | Identifier of the sender. |
|
from_nick |
string |
<optional> |
Nickname of the message sender. |
desc |
string |
<optional> |
Description of the link. |
agent |
boolean |
|
locallink
- Overrides:
New link sent.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url |
string | URL of the link. |
|
desc |
string |
<optional> |
Description of the link. |
attachment
- Overrides:
New attachment received.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url |
string | URL to download the attachment. |
|
meta |
object | Attachment metadata. |
|
from_id |
string | Identifier of the sender. |
|
from_nick |
string |
<optional> |
Nickname of the message sender. |
agent |
boolean |
|
iswriting
- Overrides:
The remote party is typing a new message.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
from_id |
string | Identifier of the sender. |
|
from_nick |
string |
<optional> |
Nickname of the message sender. |
agent |
boolean |
|
localiswriting
- Overrides:
The local user is typing a message.
ack
- Overrides:
The remote party acknowledge the receipt of a message.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ref |
string | Identifier of the message that was ack'd. |
|
from_id |
string | Identifier of the sender. |
|
from_nick |
string |
<optional> |
Nickname of the message sender. |
agent |
boolean |
|
action
- Overrides:
Custom message received.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
action_code |
string | User-defined type of message. |
|
args |
Array | User-defined arguments of the message. |
|
from_id |
string | Identifier of the sender. |
|
from_nick |
string |
<optional> |
Nickname of the message sender. |
agent |
boolean |
|
left
- Overrides:
Properties:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string | The contact id. |
|||||||||||||||||
vvcu |
string |
<optional> |
The unique id of the visitor. If present, it is the customer who left a channel. |
||||||||||||||||
user |
string |
<optional> |
The agent id. If present, it is the agent who left a channel. |
||||||||||||||||
reason |
string |
<optional> |
The reason why the channel was left. Possible reasons are:
|
||||||||||||||||
channels |
object | Information about the remaining active channels connected to the contact. Properties
|
One of the media sessions (channels) of the contact has ended. This event can signal that one of the parties has in fact left the contact altogether, or that he simply disabled one of the media. When moving between pages of a website, a customer will leave the connection established on the first page and rejoin the contact on the new page.
Type:
- object
localleft
- Overrides:
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
reason |
string |
<optional> |
The reason why the channel was left. Possible reasons are:
|
The local media session (channel) of the contact has ended. This event signal that the local party has left the contact.
cleared
- Overrides:
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
id |
string | The contact id. |
|
reason |
string |
<optional> |
The reason why the channel was left. Possible reasons are:
|
The contact ended.
Type:
- object
joined
- Overrides:
Properties:
Name | Type | Attributes | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string | The contact id. |
|||||||||||||||||||
user |
string | The agent id. |
|||||||||||||||||||
nick |
string | The agent's nickname. |
|||||||||||||||||||
avatar |
object |
<optional> |
The agent's avatar Properties
|
The agent joined the contact.
data
- Overrides:
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
channel |
string | The name of the data channel the reiceived the data. |
|
topic |
string |
<optional> |
Data topic. |
data |
The received data. |
New data was received from a DataChannel.
Type:
- object
transferred
- Overrides:
Properties:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string | The contact id. |
||||||||||||||||
to |
object | Destination of the transfer. Properties
|
The contact was transferred to a another agent, to another set of tags or simply requeued
declined
- Overrides:
Properties:
Name | Type | Description |
---|---|---|
id |
string | The contact id. |
user |
string | The agent id. |
nick |
string | The agent's nickname. |
An agent did not accept a contact that was either transferred or distributed to him.
localcapabilities
- Overrides:
The local capabilities changed
Type:
capabilities
- Overrides:
The remote capabilities changed (or were received for the first time)
Type:
datachannel
- Overrides:
A new DataChannel was created and it's ready to be used.
Type:
- DataChannel
mediaoffer
- Overrides:
A new MediaOffer was received from the remote party.
Parameters:
Name | Type | Description |
---|---|---|
offer |
MediaOffer | The received offer. |
callback |
VivochaContact~MediaOfferCallback | To be called by the handler passing the answer for the remote. |
mediachange
- Overrides:
The local media state has changed.
Parameters:
Name | Type | Description |
---|---|---|
newMedia |
MediaState | The complete new media state. |
diff |
MediaStateDiff | The difference from the previous state. |