CPC

Remember: CPC is a client-side API. Actions are carried out in context of current logged on user. Returned values depend on user account's rights.

Terminology: CPC API and this document use the term "interaction" when referring to inbound or outbound conversations with customers. The term "conversation" is used in other Sinch Contact Pro applications.

Tip: Remember to await when using async methods.

Have a great time integrating Communication Panel into your application! 😀

Namespaces

RI

Members

activeInteractionId :string|undefined|null

ID of current active interaction being viewed in Communication Panel.
Type:
  • string | undefined | null

currentUser :object

Holds details of current user. Value is set once CPC has initialized.
Note: In case user's details change during session and most recent data is needed, call getDetails like this instead:
await CPC.getDetails('user').

Type:
  • object

hostAppEventHandler :function

Event handler that is called per each event sent by Communication Panel. Initially provided as parameter for CPC.load. Can be changed at any time.
Type:
  • function

isInitialized :boolean

True when user is logged in and CPC is ready to interact with Communication Panel.
Type:
  • boolean

Methods

(async) authenticate_basic(sUsername, sPassword) → {boolean}

Authenticate Contact Pro user with basic authentication.

Note: When using this authentication option, be sure to handle user credentials with care. In your application you must prevent credentials getting logged or otherwise getting stored persistently. When possible, use authenticate_token instead.

Recommended: Authentication can also be handled as part of load call.
Parameters:
NameTypeDescription
sUsernamestringUsername
sPasswordstringPassword
Returns:
Authentication result
Type: 
boolean

(async) authenticate_token(authToken) → {boolean}

Authenticate Contact Pro user with OAuth.
Good article about the process https://www.oauth.com/oauth2-servers/signing-in-with-google/verifying-the-user-info/

Contact Pro ECF Web Server assumes that the Issuer (token iss claim) implements OAuth {iss}/.well-known/openid-configuration endpoint which returns user_info URL.
ECF server calls user_info URL to request verification for token.

Upon successful token verification, the user_info endpoint must return 200 OK and payload {sub: '', email: ''} where values correspond with Contact Pro user's Certificate Subject and Email values.

ECF server finally identifies Contact Pro user based on sub and email, and grants session cookie, allowing browser to access resources behind ECF Web Server.

Recommended: Authentication can also be handled as part of load call.
Parameters:
NameTypeDescription
authTokenstringOAuth token
Returns:
Authentication result
Type: 
boolean

(async) callOut(destinationNumber, sourceQueueNumberopt) → {object|false}

Sends a call out request to Communication Panel.
Parameters:
NameTypeAttributesDescription
destinationNumberstringDestination phone number.
sourceQueueNumberstring<optional>
Queue number to be used as Visible A Number for the call.
Note:User must have appropriate serve rights to the Queue.
Tip:Check list of user's queues first with getCurrentUserQueues
Returns:
Phone call object, or false if creating a call failed.
Type: 
object | false

(async) callState(action, interactionIdopt) → {false|Object}

Change state of ongoing phone call.
Parameters:
NameTypeAttributesDescription
action'startRecording' | 'stopRecording' | 'hold' | 'unhold' | 'mute' | 'unmute'State change to be performed on currently ongoing phone call.
interactionIdstring<optional>
Id of interaction that should be acted on. Defaults to user's current active interaction being viewed in Communication Panel.
Returns:
Changed interaction object, or false if action failed.
Type: 
false | Object

(async) consult(to, interactionIdopt) → {object|false}

In context of ongoing interaction currently selected in Communication Panel (or in context of explicitly defined interaction), create a consultation interaction.
The original phone call is put on hold, and a new phone call is created. Later the calls can be joined by calling joinCalls. Possible for phone and chat type interactions.
Parameters:
NameTypeAttributesDescription
tostringAddress or number of destination Queue or User.
interactionIdstring<optional>
Id of the ongoing interaction.
Returns:
Created interaction object, or false if action failed.
Type: 
object | false

(async) dtmf(tone, interactionIdopt) → {false|Object}

Send DTMF tone to current active interaction being viewed in Communication Panel. This works only with phone channel.
Parameters:
NameTypeAttributesDescription
tone'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A' | 'B' | 'C' | 'D' | '*' | '#'The tone to be sent.
interactionIdstring<optional>
Specify ongoing phone interaction for which tone is sent.
Returns:
Corresponding interaction object, or false if action failed.
Type: 
false | Object

(async) getCurrentUserQueues(sChannelType) → {Array}

Get the currently logged on user's queue list.
Parameters:
NameTypeDescription
sChannelType'phone' | 'chat' | 'email'Optionally filter by channel.
Returns:
Array of queue(s).
Type: 
Array

(async) getDetails(subject) → {object}

Returns details of defined subject.
Parameters:
NameTypeDescription
subject'user' | 'interaction' | 'interactions' | 'queue' | 'queues' | 'transcript' | 'activeExtension ' | 'activeInteraction' | stringSubject of details request.
Returns:
Object including details of the given subject. In CPExtInterface schema, see "detail".
Type: 
object

getTenantBaseUrl() → {string}

Get Contact Pro tenant/installation base URL. This is provided initially as parameter for load.
Returns:
URL.
Type: 
string

hasOngoingInteraction(channelType) → {boolean}

Check if user has any ongoing interaction(s) in Communication Panel.
Parameters:
NameTypeDescription
channelType'phone' | 'chat' | 'email'Optionally check specified channel type only.
Returns:
True when there is at least one ongoing interaction.
Type: 
boolean

hasOngoingInteractionOfType(channelType) → {boolean}

Check if user has ongoing interaction(s) of specific type.
Parameters:
NameTypeDescription
channelType'phone' | 'chat' | 'email'Channel
Returns:
True when there is at least one ongoing interaction.
Type: 
boolean

init() → {void}

Sends initialization request to Communication Panel. As result, Communication Panel will start sending events and accepting commands from CPC.

Note: This is needed only if load is not used to automatically inject Communication Panel.
Recommended: Use load instead. It internally handles calling init so you don't need to.
Returns:
No return value.
Type: 
void

(async) interaction(action, interactionIdopt) → {Object|false}

Perform a state changing action on the current active interaction being viewed in Communication Panel.
Parameters:
NameTypeAttributesDescription
action'accept' | 'reject' | 'pick' | 'handle' | 'hangup'Type of action to perform.
interactionIdstring<optional>
Specify ID of ongoing interaction which should be acted upon.
Returns:
Changed interaction object, or false if action failed.
Type: 
Object | false

(async) joinCalls() → {object|false}

Joins currently active original inbound or outbound phone call interaction and corresponding consultation call.
This drops the agent/user from the ongoing calls, connects other parties in a joined phone call.
Note: After joinCalls completes, phone call signaling and voice still remain connected via Sinch Contact Pro backend but can no longer be controlled by CPC.
Returns:
The interaction object of phone call from which the agent/user left, or false if action failed.
Type: 
object | false

(async) load(config) → {boolean}

Load Communication Panel into host application. Optionally provide authentication for automated user login.
Tip: It's easy to try this on the CPC Playground page. See link in top banner.
Parameters:
NameTypeDescription
configObjectObject containing initial configuration for CPC.
Properties
NameTypeAttributesDescription
eventHandlerfunctionDefined by Client Application.
tenantBaseUrlstringContact Pro tenant/installation specific base-URL.
parentElementstring | ObjectProvide container element ID or reference to container element. An iframe element containing Communication Panel is injected into this element.
enableDebugLogboolean<optional>
Set true to enable debug logging.
denyPopoutboolean<optional>
Set true to deny user from opening CP in pop-out window. This also disables My Conversations view, and overrides any User Settings Template -level settings configured in System Configurator.
minWidthnumber<optional>
Set width limit (interpreted in pixels) to activate My Conversations view. This overrides User Settings Template -level settings configured in System Configurator.
minHeightnumber<optional>
Set height limit (interpreted in pixels) to activate My Conversations view. This overrides User Settings Template -level settings configured in System Configurator.
enableChannelStatusUpdatesboolean<optional>
When enabled, CPC forwards channel_status updates to client event handler.
authenticationObject<optional>
Authenticate and log user in automatically.
Properties
NameTypeAttributesDescription
oAuthObject<optional>
OAuth
Properties
NameTypeDescription
tokenstringToken
basicObject<optional>
basic authentication
Properties
NameTypeDescription
userNamestringUsername
passwordstringPassword
Returns:
Load result.
Type: 
boolean

(async) message(message, interactionIdopt) → {false|Object}

Send a textual message to active chat interaction. Works also with sms chats.
Parameters:
NameTypeAttributesDescription
messagestringMessage content
interactionIdstring<optional>
Specific interaction for which the message should be sent.
Returns:
Corresponding interaction object, or false if action failed.
Type: 
false | Object

ongoingInteractions() → {Map.<string, object>}

Returns a Map containing all currently ongoing interaction(s) cached by CPC. These interactions include the extra timestamps appended by CPC.
Returns:
Key = InteractionId, Value = interaction
Type: 
Map.<string, object>

(async) sendEmail(email) → {object|false}

Create a new email.
Parameters:
NameTypeDescription
emailObjectObject containing following properties
Properties
NameTypeAttributesDescription
toArrayArray of destination email addresses.
directbooleanIf true, email is sent without user interaction. When true, value for all optional parameters must be provided.
fromstring<optional>
Specific sender address can be defined.
subjectstring<optional>
Subject for email
contentstring<optional>
Content of email message.
Returns:
Created email interaction object, or false on failure.
Type: 
object | false

(async) sendSMS(msg) → {object|false}

Start a one-to-one SMS message based chat.
Parameters:
NameTypeDescription
msgObjectObject containing following properties
Properties
NameTypeAttributesDescription
tostringDestination number
directbooleanIf true, SMS chat is started and first message sent without user interaction. When true, all other optional parameters require values as well.
fromstring<optional>
Queue number/address of message. User must have serve right for the Queue.
contentstring<optional>
Content of SMS message.
Returns:
Created SMS interaction object, or false if creation failed.
Type: 
object | false

(async) startWhatsAppChat(chat) → {object|false}

Start a new WhatsApp chat.
Parameters:
NameTypeDescription
chatObjectObject containing following properties
Properties
NameTypeAttributesDescription
tostringDestination number
directbooleanIf true, value for all optional parameters must be provided. When true, chat is started and first message is sent without user interaction.
fromstring<optional>
Queue number/address of message. User must have serve right for the Queue.
contentstring<optional>
Content of first WhatsApp message sent. Note: Delivery of this message depends on current consent status of destination number. Delivery is not guaranteed.
defaultReplyTemplateIdstring<optional>
Specific WhatsApp template to use, which is sent when invoking first WhatsApp chat towards number for which Contact Pro doesn't have stored consent yet.
Returns:
Created WhatsApp chat interaction object, or false if creation failed.
Type: 
object | false

(async) transfer(to, interactionIdopt) → {object|false}

Transfer ongoing interaction. Possible in phone and chat channels.
Parameters:
NameTypeAttributesDescription
tostringAddress or number of destination queue or user.
interactionIdstring<optional>
Id of the ongoing interaction.
Returns:
Created WhatsApp interaction object, or false if creation failed.
Type: 
object | false

(async) unload() → {boolean}

Unload performs two steps:
1. Sends request to server to invalidate current authentication cookie -> Server logs out currently logged in user.
2. CPC deletes the iframe element that contains Communication Panel.
Note: This is a 'hard logout' which does not take into account possibly ongoing interaction(s) such as phone calls or chats. If needed, call hasOngoingInteraction() first. If user needs to log back in, call load to re-inject Communication Panel.
Returns:
Unload result.
Type: 
boolean

(async) xdmSendAction(payload) → {object}

Helper for sending action messages to Communication Panel.

Note: Usually there is no need to call this directly.
In CPC there is a convenience method per each capability/feature of the underlying CPExtInterface. Convenience methods handle calling xdmSendAction internally, so you don't have to.
Parameters:
NameTypeDescription
payloadobjectObject containing documented attributes and values.
Returns:
Response payload value from Communication Panel.
Type: 
object