initial commit
This commit is contained in:
commit
284a3ef1ba
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
||||
21
Five9VirtualCallCenterFreedomLightingDemoInt.xml
Normal file
21
Five9VirtualCallCenterFreedomLightingDemoInt.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<callCenter>
|
||||
<section sortOrder="0" name="reqGeneralInfo" label="General Info">
|
||||
<item sortOrder="0" name="reqInternalName" label="Five9 Domain Name">Five9DomainCRMSDKDemo</item>
|
||||
<item sortOrder="1" name="reqDisplayName" label="Display Name">Five9 Domain CRM SDK demo</item>
|
||||
<item sortOrder="2" name="reqDescription" label="Description"> Five9 is the leading global provider of on-demand call center software for telemarketing, customer service, and business continuity. The award-winning Five9 Virtual Call Center and Predictive Dialer serve customers of all sizes on five continents. Customers profit from Five9's reliable, robust functionality that is fast, easy, and affordable to deploy. For more information, visit www.five9.com.</item>
|
||||
<item sortOrder="3" name="reqAdapterUrl" label="CTI Adapter URL">https://crm-sdk.five9lab.com/iframe_api_v2_cti.html</item>
|
||||
<item sortOrder="4" name="reqUseApi" label="Use CTI API">true</item>
|
||||
<item sortOrder="5" name="reqSoftphoneHeight" label="Softphone Height">600</item>
|
||||
<item sortOrder="6" name="reqSoftphoneWidth" label="Softphone Width">550</item>
|
||||
<item label="Salesforce Compatibility Mode" name="reqSalesforceCompatibilityMode" sortOrder="7">Lightning</item>
|
||||
</section>
|
||||
<section sortOrder="1" name="reqDialingOptions" label="Dialing Options">
|
||||
<item sortOrder="0" name="reqOutsidePrefix" label="Outside Prefix">9</item>
|
||||
<item sortOrder="1" name="reqLongDistPrefix" label="Long Distance Prefix">1</item>
|
||||
<item sortOrder="2" name="reqInternationalPrefix" label="International Prefix">01</item>
|
||||
</section>
|
||||
<section sortOrder="2" name="Five9Info" label="Five9 Info">
|
||||
<item sortOrder="0" name=" createdByFive9User" label="Created By Five9 User">five9</item>
|
||||
<item sortOrder="1" name=" createdOn" label="Created On">Tue Dec 11 22:55:59 UTC 2018</item>
|
||||
</section>
|
||||
</callCenter>
|
||||
30
README.md
Normal file
30
README.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Five9CRMSDKSamples
|
||||
|
||||
Examples of using [Five9 CRM SDK Javascript Library](https://app.five9.com/dev/sdk/crm/latest/doc/index.html)
|
||||
|
||||
### Dependencies
|
||||
- [Node.js](https://nodejs.org)
|
||||
- [Gulp](https://gulpjs.com)
|
||||
### How to run project
|
||||
```
|
||||
npm install
|
||||
gulp server
|
||||
```
|
||||
### Configuration
|
||||
Project is running local https web server on your machine. Add following line to etc/hosts file:
|
||||
```
|
||||
127.0.0.1 crm-sdk.five9lab.com
|
||||
```
|
||||
|
||||
### Example
|
||||
- Page demonstrating CRM SDK functions of Agent Desktop Toolkit embedded inside iframe https://crm-sdk.five9lab.com/iframe_api_v2.html
|
||||
> For details see tutorial [Integrating ADT inside web page](https://app.five9.com/dev/sdk/crm/latest/doc/tutorial-basicintegration.html)
|
||||
- Page demonstrating CRM SDK functions in combination with SalesForce CRM https://crm-sdk.five9lab.com/iframe_api_v2_cti.html
|
||||
This page should be embedded inside SalesForce CRM using Five9VirtualCallCenterFreedomLightingDemoInt.xml call center
|
||||
definition file located in the root of the project. This page can work in combination with demo Lightning Components
|
||||
[Salesforce package with examples](https://login.salesforce.com/packaging/installPackage.apexp?p0=04tf4000004Mbr5&isdtp=p1)
|
||||
> For details see tutorials [Customizing existing integrations](https://app.five9.com/dev/sdk/crm/latest/doc/tutorial-custexisting.html) and
|
||||
[Building proxy page](https://app.five9.com/dev/sdk/crm/latest/doc/tutorial-proxypage.html)
|
||||
|
||||
|
||||
|
||||
4406
five9.crm.sdk.js
Normal file
4406
five9.crm.sdk.js
Normal file
File diff suppressed because it is too large
Load Diff
25
gulpfile.js
Normal file
25
gulpfile.js
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var gulp = require('gulp');
|
||||
var browserSync = require('browser-sync').create();
|
||||
var minimist = require('minimist');
|
||||
|
||||
gulp.task('server', function() {
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||
var args = minimist(process.argv.slice(2));
|
||||
browserSync.init({
|
||||
server: {
|
||||
baseDir: '',
|
||||
https: true,
|
||||
online: true,
|
||||
routes: {
|
||||
'/': ''
|
||||
}
|
||||
},
|
||||
ghostMode: false,
|
||||
host: args.host || 'crm-sdk.five9lab.com',
|
||||
port: args.port || '443',
|
||||
open: false,
|
||||
startPath: 'iframe_api_v2.html'
|
||||
});
|
||||
});
|
||||
425
iframe_api_v2.html
Normal file
425
iframe_api_v2.html
Normal file
@ -0,0 +1,425 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title>IFrame API</title>
|
||||
<script type="text/javascript" src="libs/five9.crm.sdk.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var interactionApi = window.Five9.CrmSdk.interactionApi();
|
||||
var customComponentsApi = window.Five9.CrmSdk.customComponentsApi();
|
||||
var crmApi = window.Five9.CrmSdk.crmApi();
|
||||
|
||||
// =======CRM API=======
|
||||
crmApi.registerApi({
|
||||
getAdtConfig: function (params) {
|
||||
var config = {
|
||||
providerName: 'Demo CRM ADT adapter',
|
||||
myCallsTodayEnabled: true,
|
||||
myChatsTodayEnabled: true,
|
||||
myEmailsTodayEnabled: true,
|
||||
showContactInfo: false
|
||||
};
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
return Promise.resolve(config);
|
||||
},
|
||||
search: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
var crmObjects = [{id: "123", label: "Contact", name: "Joe", isWho: true, isWhat: false, fields:[{displayName: "Company", value: "ABC"}]}];
|
||||
return Promise.resolve({crmObjects: crmObjects, screenPopObject: crmObjects[0]});
|
||||
|
||||
},
|
||||
saveLog: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
screenPop: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
getTodayCallsCount: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
return Promise.resolve(77);
|
||||
},
|
||||
getTodayChatsCount: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
return Promise.resolve(77);;
|
||||
},
|
||||
getTodayEmailsCount: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
return Promise.resolve(11);;
|
||||
},
|
||||
openMyCallsToday: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
openMyChatsToday: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
contactSelected: function (contactModel) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
enableClickToDial: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
disableClickToDial: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// ======Interaction API EVENTS========
|
||||
interactionApi.subscribe({
|
||||
callStarted: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
setCallId(params.callData.interactionId);
|
||||
},
|
||||
|
||||
callFinished: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
setCallId('');
|
||||
},
|
||||
|
||||
callAccepted: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
callRejected: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
callEnded: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
emailOffered: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
emailAccepted: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
emailRejected: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
emailFinished: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
chatOffered: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
chatAccepted: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
chatRejected: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
chatEnded: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
},
|
||||
|
||||
chatFinished: function (params) {
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//======== F9 API REGISTRATION======
|
||||
window.Five9.CrmSdk.customComponentsApi().registerCustomComponents({template: `<adt-components>
|
||||
<adt-component location="3rdPartyComp-li-call-tab" label="3rdPartyComp-li-call-tab" style="flex-direction: column">
|
||||
<adt-input value="Initial value" id="aaa1" name="input1" label="Credit card1" placeholder="this is placeholder1"
|
||||
onchange="callTabInputCallback"></adt-input>
|
||||
<adt-btn-group label="Group of buttons">
|
||||
<!-- comments are ignored and styles are filtered by whitelisting -->
|
||||
<adt-button name="button1" label="Yes" class="btnPrimary" style="flex-grow: 1; justify-content: center;"
|
||||
onclick="callTabYesCallback">Yes</adt-button>
|
||||
<adt-button name="button2" label="No" class="btnSecondary" style="flex-grow: 1"
|
||||
onclick="callTabNoCallback"></adt-button>
|
||||
</adt-btn-group>
|
||||
</adt-component>
|
||||
<adt-component location="3rdPartyComp-li-call-details-bottom" label="3rdPartyComp-li-call-details-bottom" style="flex-direction: row; justify-content: space-between; align-items: flex-end;">
|
||||
<adt-input value="Initial value" name="input2" label="Credit card2" placeholder="this is placeholder1"
|
||||
onchange="callDetailsInputCallback"></adt-input>
|
||||
<adt-button name="button3" label="Verify" class="btnPrimary" style="justify-content: center;"
|
||||
onclick="callDetailsButtonCallback"></adt-button>
|
||||
</adt-component>
|
||||
</adt-components>
|
||||
`,
|
||||
callbacks: {
|
||||
callTabInputCallback: function(params){
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
callTabYesCallback: function(params){
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
|
||||
},
|
||||
callTabNoCallback: function(params){
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
|
||||
},
|
||||
callDetailsInputCallback: function(params){
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
|
||||
},
|
||||
callDetailsButtonCallback: function(params){
|
||||
debugStream.debug({
|
||||
callee: arguments.callee.name,
|
||||
data: params
|
||||
});
|
||||
|
||||
}
|
||||
}});
|
||||
|
||||
|
||||
function clearList(list) {
|
||||
var listNode = document.getElementById(list);
|
||||
while (listNode.lastChild) {
|
||||
listNode.removeChild(listNode.lastChild);
|
||||
}
|
||||
}
|
||||
|
||||
function setCallId(callId) {
|
||||
document.getElementById('callId').innerHTML = callId;
|
||||
}
|
||||
|
||||
function getCallId() {
|
||||
return document.getElementById('callId').innerHTML;
|
||||
}
|
||||
|
||||
var debugStream = {
|
||||
debug: function (arg) {
|
||||
console.debug("IframeV2: " + JSON.stringify(arg));
|
||||
updateListComponent('events_list', [arg]);
|
||||
}
|
||||
};
|
||||
|
||||
var updateListComponent = function (name, params) {
|
||||
if (params && params.length > 0) {
|
||||
var list = document.getElementById(name);
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
list.insertAdjacentHTML('beforeend', '<li>' + JSON.stringify(params[i]) + '</li>');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var reset_btn = document.getElementById('reset_btn');
|
||||
reset_btn.addEventListener('click', function () {
|
||||
clearList('cav_list');
|
||||
clearList('disp_list');
|
||||
clearList('events_list');
|
||||
});
|
||||
|
||||
var get_btn = document.getElementById('get_btn');
|
||||
get_btn.addEventListener('click', function () {
|
||||
clearList('cav_list');
|
||||
|
||||
interactionApi.getCav({interactionId: getCallId()}).then(function (cavList) {
|
||||
console.debug('IframeV2 got cavList: ' + JSON.stringify(cavList));
|
||||
updateListComponent('cav_list', cavList);
|
||||
});
|
||||
});
|
||||
|
||||
var set_cav_btn = document.getElementById('set_cav_btn');
|
||||
set_cav_btn.addEventListener('click', function () {
|
||||
var cavId = document.getElementById('cavId').value;
|
||||
var cavValue = document.getElementById('cavValue').value;
|
||||
|
||||
interactionApi.getCav({interactionId: getCallId()}).then(function (cavList) {
|
||||
console.debug('IframeV2 got cavList: ' + JSON.stringify(cavList));
|
||||
updateListComponent('cav_list', cavList);
|
||||
|
||||
|
||||
console.debug('IframeV2 set cavList: ' + JSON.stringify(cavList));
|
||||
interactionApi.setCav({interactionId: getCallId(), cavList: [{id: cavId, value: cavValue}]});
|
||||
});
|
||||
});
|
||||
|
||||
var get_disp_btn = document.getElementById('get_disp_btn');
|
||||
get_disp_btn.addEventListener('click', function () {
|
||||
clearList('disp_list');
|
||||
|
||||
interactionApi.getDispositions({interactionType: 'Call', interactionId: getCallId()}).then(function (dispList) {
|
||||
console.debug('IframeV2 got dispList: ' + JSON.stringify(dispList));
|
||||
updateListComponent('disp_list', dispList);
|
||||
});
|
||||
});
|
||||
|
||||
var set_disp_btn = document.getElementById('set_disp_btn');
|
||||
set_disp_btn.addEventListener('click', function () {
|
||||
var dispId = document.getElementById('dispId').value;
|
||||
interactionApi.setDisposition({interactionType: 'Call', interactionId: getCallId(), dispositionId: dispId});
|
||||
});
|
||||
|
||||
var c2d_btn = document.getElementById('c2d_btn');
|
||||
c2d_btn.addEventListener('click', function () {
|
||||
var num = document.getElementById('c2dNum').value;
|
||||
crmApi.click2dial({click2DialData: {clickToDialNumber: num}});
|
||||
//crmApi.click2dial({click2DialData: {clickToDialNumber: num, crmObject: {id: "789", label: "Account", name: "XYZ", isWho: false, isWhat: true}}});
|
||||
|
||||
});
|
||||
|
||||
var objectVisited_btn = document.getElementById('objectVisited_btn');
|
||||
objectVisited_btn.addEventListener('click', function () {
|
||||
crmApi.objectVisited({crmObject: {id: "456", label: "Case", name: "Broken microwave", isWho: false, isWhat: true}});
|
||||
});
|
||||
|
||||
var suggestedNumbers_btn = document.getElementById('suggestedNumbers_btn');
|
||||
|
||||
suggestedNumbers_btn.addEventListener('click', function () {
|
||||
crmApi.suggestedNumbers(
|
||||
{suggestedNumbers: [
|
||||
{clickToDialNumber:"9250000111", crmObject: {id: "441", label: "Case", name: "Engine broken", isWho: false, isWhat: true}},
|
||||
{clickToDialNumber:"9250000112", crmObject: {id: "789", label: "Account", name: "XYZ", isWho: false, isWhat: true}},
|
||||
{clickToDialNumber:"9250000113", crmObject: {id: "731", label: "Contact", name: "Tim", isWho: true, isWhat: false}}]});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="panel-body">
|
||||
<iframe id="iframe-api-v2-panel" src="https://app.five9.com/clients/integrations/adt.li.main.html?f9crmapi=true&f9verticalthreshold=300px" style="position: relative; float: right; height: 600px; width: 299px"></iframe>
|
||||
</div>
|
||||
|
||||
|
||||
<p>Call Variables for callId: </p> <p id='callId'></p>
|
||||
<button id="get_btn">Get Cav</button>
|
||||
</br>
|
||||
<div class="setCav">
|
||||
<button id="set_cav_btn">Set Call Variable</button>
|
||||
<input type="text" id="cavId" name="cavId" placeholder="enter Cav Id" />
|
||||
<input type="text" id="cavValue" name="cavValue" placeholder="enter Cav Value" />
|
||||
</div>
|
||||
</br>
|
||||
<div class="getDispositions">
|
||||
<button id="get_disp_btn">Get Dispositions</button>
|
||||
</div>
|
||||
<div class="setDisposition">
|
||||
<button id="set_disp_btn">Set Disposition</button>
|
||||
<input type="text" id="dispId" name="dispId" placeholder="enter Disposition Id" />
|
||||
</div>
|
||||
</br>
|
||||
<div class="c2d">
|
||||
<button id="c2d_btn">Click to Dial</button>
|
||||
<input type="text" id="c2dNum" name="c2dNum" placeholder="enter number" />
|
||||
</div>
|
||||
</br>
|
||||
<div class="objectVisited">
|
||||
<button id="objectVisited_btn">objectVisited</button>
|
||||
</div>
|
||||
</br>
|
||||
<div class="suggestedNumbers">
|
||||
<button id="suggestedNumbers_btn">suggestedNumbers</button>
|
||||
</div>
|
||||
|
||||
</br>
|
||||
|
||||
<button id="reset_btn">Reset</button>
|
||||
|
||||
|
||||
<p>Dispositions:</p>
|
||||
<ul id="disp_list"></ul>
|
||||
|
||||
<p>Call Variables:</p>
|
||||
<ul id="cav_list"></ul>
|
||||
|
||||
<p>Events:</p>
|
||||
<ul id="events_list"></ul>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
219
iframe_api_v2_cti.html
Normal file
219
iframe_api_v2_cti.html
Normal file
@ -0,0 +1,219 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title>IFrame API</title>
|
||||
<script type="text/javascript" src="libs/five9.crm.sdk.js"></script>
|
||||
<script type="text/javascript" src="libs/lightningInteraction.js"></script>
|
||||
<style>
|
||||
#five9-adapter {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: calc(100% - 45px);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var crmApi = window.Five9.CrmSdk.crmApi();
|
||||
|
||||
var callsCount = 0;
|
||||
|
||||
// register CRM API event callbacks
|
||||
crmApi.registerApi({
|
||||
getAdtConfig: function (params) {
|
||||
var config = {
|
||||
providerName: 'Demo CRM ADT adapter',
|
||||
myCallsTodayEnabled: true,
|
||||
myChatsTodayEnabled: true,
|
||||
myEmailsTodayEnabled: false,
|
||||
showContactInfo: false,
|
||||
};
|
||||
return Promise.resolve(config);
|
||||
},
|
||||
search: function (params) {
|
||||
var pr = new Promise(function (resolve, reject) {
|
||||
sforce.opencti.searchAndScreenPop({
|
||||
searchParams: params.interactionData.number,
|
||||
queryParams: `PhoneNumber=${params.Number}`,
|
||||
callType: sforce.opencti.CALL_TYPE.OUTBOUND,
|
||||
deferred: true,
|
||||
callback: function (result) {
|
||||
if (result.success) {
|
||||
console.log(result.returnValue);
|
||||
|
||||
var foundObjects = [];
|
||||
for (var property in result.returnValue) {
|
||||
if (result.returnValue.hasOwnProperty(property)) {
|
||||
if (property !== 'SCREEN_POP_DATA'){
|
||||
var newItem={};
|
||||
var id = result.returnValue[property].Id;
|
||||
newItem.id = id && id.slice(0, 15);
|
||||
newItem.name = result.returnValue[property].Name;
|
||||
newItem.label = result.returnValue[property].RecordType;
|
||||
newItem.isWho = true;
|
||||
newItem.isWhat = false;
|
||||
|
||||
foundObjects.push(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var screenPop = null;
|
||||
if (foundObjects.length === 1){
|
||||
screenPop = foundObjects[0];
|
||||
}
|
||||
resolve({crmObjects:foundObjects, screenPopObject: screenPop});
|
||||
console.log(result.returnValue);
|
||||
} else {
|
||||
console.log(result.errors);
|
||||
reject();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
return pr;
|
||||
},
|
||||
saveLog: function (params) {
|
||||
sforce.opencti.saveLog({
|
||||
value: {
|
||||
entityApiName: "Task",
|
||||
WhoId: params.interactionLogData.who ? params.interactionLogData.who.id : null,
|
||||
WhatId: params.interactionLogData.what ? params.interactionLogData.what.id : null,
|
||||
CallType: getSFCallType(params.interactionData.callType),
|
||||
ActivityDate: getActivityDate(),
|
||||
Status: "Completed",
|
||||
CallDisposition: params.interactionLogData.dispositionName,
|
||||
Description: params.interactionLogData.comments,
|
||||
Subject: params.interactionLogData.subject,
|
||||
CallDurationInSeconds: params.interactionLogData.duration
|
||||
},
|
||||
callback: function (result) {
|
||||
if (result.success) {
|
||||
callsCount++;
|
||||
console.log(result.returnValue);
|
||||
} else {
|
||||
console.log(result.errors);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
screenPop: function (params) {
|
||||
var object = params.crmObject;
|
||||
if (object.id) {
|
||||
object = {type: sforce.opencti.SCREENPOP_TYPE.SOBJECT, params: {recordId: object.id}};
|
||||
} else {
|
||||
object = {type: sforce.opencti.SCREENPOP_TYPE.SOBJECT ,params : { recordId: object}};
|
||||
}
|
||||
sforce.opencti.screenPop(object);
|
||||
},
|
||||
getTodayCallsCount: function (params) {
|
||||
return callsCount;
|
||||
},
|
||||
getTodayChatsCount: function (params) {
|
||||
return 88;
|
||||
},
|
||||
openMyCallsToday: function (params) {
|
||||
},
|
||||
openMyChatsToday: function (params) {
|
||||
},
|
||||
enableClickToDial: function (params) {
|
||||
sforce.opencti.enableClickToDial();
|
||||
},
|
||||
disableClickToDial: function (params) {
|
||||
sforce.opencti.disableClickToDial();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
//subscribe to Salesforce Open CTI events and execute CRM API methods based on Salesforce events
|
||||
sforce.opencti.onClickToDial({
|
||||
listener: function (payload) {
|
||||
var click2DialData = {
|
||||
clickToDialNumber: payload.number,
|
||||
screenpopC2DSearch: true,
|
||||
crmObject: {
|
||||
id: payload.recordId,
|
||||
label: payload.objectType,
|
||||
name: payload.recordName,
|
||||
isWho: payload.objectType === "Contact",
|
||||
isWhat: payload.objectType === "Case"
|
||||
}
|
||||
};
|
||||
crmApi.click2dial({click2DialData: click2DialData});
|
||||
}
|
||||
});
|
||||
|
||||
sforce.opencti.onNavigationChange({
|
||||
listener: function (response){
|
||||
if (isNavigationEventValid({result: JSON.stringify(response)})){
|
||||
var item = convertSearchResults(response);
|
||||
if (item.id) {
|
||||
crmApi.objectVisited({crmObject: item});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//utility functions
|
||||
|
||||
function isNavigationEventValid(response) {
|
||||
if (response.result) {
|
||||
let result = JSON.parse(response.result);
|
||||
return !result.recordId || (result.recordId && result.url && result.url.indexOf(result.recordId) > -1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
var getActivityDate = function()
|
||||
{
|
||||
var today = new Date();
|
||||
var dd = today.getDate();
|
||||
var mm = today.getMonth() + 1; //January is 0!
|
||||
|
||||
var yyyy = today.getFullYear();
|
||||
if (dd < 10) {
|
||||
dd = '0' + dd;
|
||||
}
|
||||
if (mm < 10) {
|
||||
mm = '0' + mm;
|
||||
}
|
||||
return today = yyyy + '-'+mm+'-'+dd;
|
||||
}
|
||||
var getSFCallType = function (calltype) {
|
||||
calltype = calltype.toUpperCase();
|
||||
switch (calltype) {
|
||||
case 'INBOUND':
|
||||
return 'Inbound';
|
||||
case 'INTERNAL':
|
||||
return 'Internal';
|
||||
default:
|
||||
return "Outbound";
|
||||
}
|
||||
};
|
||||
|
||||
var convertSearchResults = function(rawResults){
|
||||
var id = rawResults.recordId;
|
||||
var newItem = {};
|
||||
newItem.id = id && id.slice(0, 15);
|
||||
newItem.name = rawResults.recordName;
|
||||
newItem.label = rawResults.objectType;
|
||||
newItem.isWho = rawResults.objectType === "Contact";
|
||||
newItem.isWhat = rawResults.objectType === "Case";;
|
||||
|
||||
return newItem;
|
||||
};
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<iframe id='five9-adapter' src="https://app.five9.com/clients/integrations/adt.li.main.html?f9crmapi=true" frameborder='0'></iframe>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
4406
libs/five9.crm.sdk.js
Normal file
4406
libs/five9.crm.sdk.js
Normal file
File diff suppressed because it is too large
Load Diff
641
libs/lightningInteraction.js
Normal file
641
libs/lightningInteraction.js
Normal file
@ -0,0 +1,641 @@
|
||||
/******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId])
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ exports: {},
|
||||
/******/ id: moduleId,
|
||||
/******/ loaded: false
|
||||
/******/ };
|
||||
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.loaded = true;
|
||||
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
|
||||
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "/assets/";
|
||||
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
'use strict';
|
||||
|
||||
window.sforce = window.sforce || {};
|
||||
/* global sforce */
|
||||
sforce.opencti = __webpack_require__(1);
|
||||
sforce.opencti.initialize();
|
||||
|
||||
/***/ }),
|
||||
/* 1 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var config = __webpack_require__(2);
|
||||
var utils = __webpack_require__(3);
|
||||
var topFrameOriginPattern = /^http[s]?:\/\/[\w-.]+(\.force\.com|\.salesforce\.com)(:\d+)?$/;
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Initializes API to listen for responses from Salesforce.
|
||||
*/
|
||||
initialize: function initialize() {
|
||||
// Set the Salesforce frame origin and the nonce needed to call API methods.
|
||||
var params = utils.parseUrlQueryString(location.search);
|
||||
var sfdcIframeOrigin = params.sfdcIframeOrigin;
|
||||
if (sfdcIframeOrigin && params.mode && topFrameOriginPattern.test(sfdcIframeOrigin) && sfdcIframeOrigin.indexOf(window.location.protocol) === 0) {
|
||||
config.sfdcIframeOrigin = params.sfdcIframeOrigin;
|
||||
config.mode = params.mode;
|
||||
} else {
|
||||
//Fatal error: Can't proceed in initialization because the page didn't initialize properly.
|
||||
//TODO : think about providing validation utils to perform validation tasks in multiple methods
|
||||
throw "Failed to initialize Open CTI. Ensure that it is loaded from the right frame with correct URL parameters";
|
||||
}
|
||||
window.addEventListener('message', utils.processPostMessage, false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns in callback true if the softphone panel was successfully shown or hidden, false otherwise.
|
||||
* If false is returned, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {boolean} args.visible - true to show and false to hide the softphone container.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelVisibility: function setSoftphonePanelVisibility(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelVisibility', { visible: args.visible }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true if the softphone panel is currently shown, false otherwise.
|
||||
* If false is returned, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
isSoftphonePanelVisible: function isSoftphonePanelVisible(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateCallback(args);
|
||||
utils.invokeApiCall('isSoftphonePanelVisible', {}, args.callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Enum of the different screenpop types
|
||||
*/
|
||||
SCREENPOP_TYPE: {
|
||||
URL: "url",
|
||||
SOBJECT: "sobject",
|
||||
OBJECTHOME: "objecthome",
|
||||
LIST: "list",
|
||||
SEARCH: "search",
|
||||
NEW_RECORD_MODAL: "newRecord",
|
||||
FLOW: "flow"
|
||||
},
|
||||
|
||||
/**
|
||||
* Pops to the specified navigation type.
|
||||
* If false is returned, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Object} args.type - The enumerated type to screen-pop to.
|
||||
* @param {Object} args.params - An object holding arguments depending on the type.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
screenPop: function screenPop(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('screenPop', { type: args.type, params: args.params }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Enum of the different call types for searchandscreenpop.
|
||||
*/
|
||||
CALL_TYPE: {
|
||||
INBOUND: "inbound",
|
||||
OUTBOUND: "outbound",
|
||||
INTERNAL: "internal"
|
||||
},
|
||||
|
||||
/**
|
||||
* Searches objects specified in the softphone layout for a given string. Returns search results and screen pops any matching records. This method respects screen pop settings defined in the softphone layout.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.searchParams - The string to search for specified objects. The minimum character length is 3.
|
||||
* @param {Object} args.callType - One of the following types: sforce.openct.INBOUND | sforce.openct.OUTBOUND | sforce.openct.INTERNAL
|
||||
* @param {Object|String} args.queryParams - Specifies the query parameters to pass to the VisualForce URLs (when we pop to VisualForce page). Specify a string OR object. Objects are converted to strings of key/value pair and escaped before being passed.
|
||||
* @param {Object} args.defaultFieldValues - Specifies the default field values to pass to the new entity page(when we pop to new entity page).
|
||||
* @param {boolean} args.deferred - The default is false. If true, this function doesn't perform screen pop but instead passes back an object which can later be passed to sforce.opencti.screenPop API as an input to perform the same operation.
|
||||
*/
|
||||
searchAndScreenPop: function searchAndScreenPop(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('searchAndScreenPop', { searchParams: args.searchParams, callType: args.callType, queryParams: args.queryParams, defaultFieldValues: args.defaultFieldValues, deferred: args.deferred, params: args.params }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns information about the current page as a JSON string.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
getAppViewInfo: function getAppViewInfo(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateCallback(args);
|
||||
utils.invokeApiCall('getAppViewInfo', {}, args.callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true and provides the new object Id in callback if the object was successfully created or updated, null otherwise.
|
||||
* If false is returned, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Object} args.value - New object to create.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
saveLog: function saveLog(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateValueObject(args);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('saveLog', { object: args.value }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Refreshes the current view and returns JSON string true as part of the result if API call is successful.
|
||||
* If API call fails, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.callback - An optional function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
refreshView: function refreshView(args) {
|
||||
utils.validateArguments(arguments, true);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('refreshView', {}, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Notifies that the adapter url has been successfully loaded.
|
||||
*/
|
||||
notifyInitializationComplete: function notifyInitializationComplete(args) {
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('notifyInitializationComplete', {}, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the label in the softphone utility item.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.label - The label to set.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphoneItemLabel: function setSoftphoneItemLabel(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphoneItemLabel', { label: args.label }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the label in the softphone panel's header.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.label - The label to set.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelLabel: function setSoftphonePanelLabel(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelLabel', { label: args.label }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the icon in the softphone utility item.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.key - The image key of the icon to display.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphoneItemIcon: function setSoftphoneItemIcon(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphoneItemIcon', { key: args.key }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the icon in the softphone panel's header.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.key - The image key of the icon to display.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelIcon: function setSoftphonePanelIcon(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelIcon', { key: args.key }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the height of the softphone panel.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {number} args.heightPX - To set the height of the softphone panel, specify the height value in pixels.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelHeight: function setSoftphonePanelHeight(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelHeight', { heightPX: args.heightPX }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the width of the softphone panel.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {number} args.widthPX - To set the width of the softphone panel, specify the width in pixels.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelWidth: function setSoftphonePanelWidth(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelWidth', { widthPX: args.widthPX }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns callCenterSettings in a JSON string as part of the results if the API call was successful.
|
||||
* If the API call fails, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
getCallCenterSettings: function getCallCenterSettings(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateCallback(args);
|
||||
utils.invokeApiCall('getCallCenterSettings', {}, args.callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Registers a function to call when a user clicks an enabled phone number.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.listener - Function which will be called when a user clicks an enabled phone number.
|
||||
*/
|
||||
onClickToDial: function onClickToDial(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateListener(args);
|
||||
utils.invokeApiCall('onClickToDial', {}, undefined, args.listener);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns callCenterSettings in a JSON string as part of the results if the API call was successful.
|
||||
* If the API call fails, an error message is also returned.
|
||||
* @param {Object} callback - An input object with the following parameter:
|
||||
* {Function} callback - Executes function on success and returns an error on failure.
|
||||
*/
|
||||
enableClickToDial: function enableClickToDial(args) {
|
||||
utils.validateArguments(arguments, true);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('enableClickToDial', {}, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns callCenterSettings in a JSON string as part of the results if the API call was successful.
|
||||
* If the API call fails, an error message is also returned.
|
||||
* @param {Object} args - An input object with the following parameter:
|
||||
* @param {Function} args.callback - Executes function on success and returns an error on failure.
|
||||
*/
|
||||
disableClickToDial: function disableClickToDial(args) {
|
||||
utils.validateArguments(arguments, true);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('disableClickToDial', {}, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the softphone layout in a JSON string as part of the results if the API call was successful.
|
||||
* If the API call fails, an error message is also returned.
|
||||
* @param {Object} args - An input object with the following parameter:
|
||||
* @param {Function} args.callback - Executes function on success and returns an error on failure.
|
||||
*/
|
||||
getSoftphoneLayout: function getSoftphoneLayout(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateCallback(args);
|
||||
utils.invokeApiCall('getSoftphoneLayout', {}, args.callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Registers a function to be invoked on navigation changes.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.listener - Function which will be called when navigation has changed.
|
||||
*/
|
||||
onNavigationChange: function onNavigationChange(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateListener(args);
|
||||
utils.invokeApiCall('onNavigationChange', {}, undefined, args.listener);
|
||||
},
|
||||
|
||||
/**
|
||||
* Runs a method from an Apex class with supplied parameters.
|
||||
* @param {Object} args - An object holding arguments for calls to this method. For this method to work, you must provide an args object containing the following: apexClass (i.e. AccountRetrieval), methodName (i.e. getAccount) and methodParams (i.e. firstName=Charles&lastName=Green).
|
||||
* @param {Function} args.callback - An optional function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
runApex: function runApex(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('runApex', {
|
||||
apexClass: args.apexClass,
|
||||
methodName: args.methodName,
|
||||
methodParams: args.methodParams
|
||||
}, callback);
|
||||
}
|
||||
};
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
API_VERSION: 43,
|
||||
API_TYPE: 'opencti',
|
||||
sfdcIframeOrigin: null, // will be populated in during initialization
|
||||
mode: null // will be populated in during initialization
|
||||
};
|
||||
|
||||
/***/ }),
|
||||
/* 3 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var config = __webpack_require__(2);
|
||||
var callbackManager = __webpack_require__(4);
|
||||
var listenerManager = __webpack_require__(5);
|
||||
|
||||
/**
|
||||
* Get a unique Call ID.
|
||||
*/
|
||||
var getCallId = function () {
|
||||
//All API Calls increment this value and thus will have a unique ID
|
||||
var callId = 0;
|
||||
return function () {
|
||||
return callId++;
|
||||
};
|
||||
}();
|
||||
|
||||
/**
|
||||
* Process messages received from Salesforce by executing callbacks, if any.
|
||||
* The event.data object contains the following fields:
|
||||
* {
|
||||
* apiVersion {Integer} - The version of API.
|
||||
* apiType {String} - The type of API.
|
||||
* methodName {String} - The name of the API method to be invoked.
|
||||
* callId {Integer} - A unique ID for this window and API call.
|
||||
* response - {Object}
|
||||
* success - Boolean value indicating if the API executed correctly.
|
||||
* returnValue - Any return value.
|
||||
* errors - Any error if present.
|
||||
* }
|
||||
*/
|
||||
var processPostMessage = function processPostMessage(event) {
|
||||
var eventData = event.data;
|
||||
if (eventData && eventData.apiVersion === config.API_VERSION && eventData.apiType === config.API_TYPE && event.origin === config.sfdcIframeOrigin) {
|
||||
// execute callbacks and listeners registered for the method called
|
||||
callbackManager.executeCallback(eventData.methodName, eventData.callId, eventData.response);
|
||||
listenerManager.executeListeners(eventData.methodName, eventData.response);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: Replace this with a more robust implementation.
|
||||
* Utility method to create a query string object.
|
||||
* @param {String} queryString - Represents the location.search value or any GET (key/value) pair string in the URL.
|
||||
* @return {Object} - JSON of the key/value pairs in the given string of GET values in the URL.
|
||||
*/
|
||||
var parseUrlQueryString = function parseUrlQueryString(queryString) {
|
||||
var params = {};
|
||||
if (typeof queryString !== 'string') {
|
||||
return params;
|
||||
}
|
||||
|
||||
if (queryString.charAt(0) === '?') {
|
||||
queryString = queryString.slice(1);
|
||||
}
|
||||
|
||||
if (queryString.length === 0) {
|
||||
return params;
|
||||
}
|
||||
|
||||
var pairs = queryString.split('&');
|
||||
for (var i = 0; i < pairs.length; i++) {
|
||||
var pair = pairs[i].split('=');
|
||||
if (pair[0]) {
|
||||
// Pre-emptive gaurd agains bad URLS which have no key "&=1234"
|
||||
if (params[pair[0]]) {
|
||||
//encountered a multi value input GET
|
||||
if (_typeof(params[pair[0]]) === 'object') {
|
||||
//already created an array.. push to it
|
||||
params[pair[0]].push(pair[1] ? decodeURIComponent(pair[1]) : null);
|
||||
} else {
|
||||
// create new array and push to it.
|
||||
var tmp = params[pair[0]];
|
||||
params[pair[0]] = [];
|
||||
params[pair[0]].push(tmp);
|
||||
params[pair[0]].push(pair[1] ? decodeURIComponent(pair[1]) : null);
|
||||
}
|
||||
} else {
|
||||
params[pair[0]] = pair[1] ? decodeURIComponent(pair[1]) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes an API call to the Salesforce domain in the top window.
|
||||
* @param {String} methodName - Represents the name of the API method being invoked.
|
||||
* @param {Object} args - Represents the data to be sent for the API to function.
|
||||
* @param {Function} callback [optional] - The callback to be called after the API returns a value (success or failure).
|
||||
*/
|
||||
var invokeApiCall = function invokeApiCall(methodName, args, callback, listener) {
|
||||
|
||||
/**
|
||||
* Post message object.
|
||||
*
|
||||
* API methods should have a unique ID in case they are called multiple times in an asynchronous manner.
|
||||
* This helps differentiate between calls and also calculating performance for each of the calls.
|
||||
* {
|
||||
* apiVersion {Integer} - The version of API.
|
||||
* apiType {String} - The type of API.
|
||||
* methodName {String} - The name of the API method to be invoked.
|
||||
* callId {Integer} - A unique ID for this window and API call.
|
||||
* isListenerRegistered {Boolean} - Indicates if a listener was registered.
|
||||
* isCallbackRegistered {Boolean} - Indicates if the user supplied a callback
|
||||
* args {Object} - Depends on the API type. Holds all the information passed for that API to function.
|
||||
* }
|
||||
*/
|
||||
var params = {
|
||||
methodName: methodName,
|
||||
callId: getCallId(),
|
||||
apiVersion: config.API_VERSION,
|
||||
apiType: config.API_TYPE,
|
||||
isCallbackRegistered: false,
|
||||
isListenerRegistered: false,
|
||||
args: args
|
||||
};
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callbackManager.registerCallback(params.methodName, params.callId, callback);
|
||||
params.isCallbackRegistered = true;
|
||||
}
|
||||
|
||||
if (typeof listener === 'function') {
|
||||
listenerManager.registerListener(params.methodName, listener);
|
||||
params.isListenerRegistered = true;
|
||||
}
|
||||
|
||||
parent.postMessage(params, config.sfdcIframeOrigin);
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates the callback argument in args.
|
||||
*/
|
||||
var validateCallback = function validateCallback(args) {
|
||||
if (!(args && typeof args.callback === 'function')) {
|
||||
throw new Error("Missing the required argument `callback`!");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates the listener argument in args.
|
||||
*/
|
||||
var validateListener = function validateListener(args) {
|
||||
if (!(args && typeof args.listener === 'function')) {
|
||||
throw new Error("Missing the required argument `listener`!");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: Shouldn't this be handled by opencti:openCtiApiHandler?
|
||||
* Validates the value argument in args for saveLog API.
|
||||
*/
|
||||
var validateValueObject = function validateValueObject(args) {
|
||||
if (!(args && _typeof(args.value) === 'object')) {
|
||||
throw new Error("Missing the required argument `value object`!");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates the input arguments to ensure there is only one argument passed in which is of type object if isOptional is false or isOptional is true but args.length > 0.
|
||||
*/
|
||||
var validateArguments = function validateArguments(args, isOptional) {
|
||||
if (isOptional && args.length || !isOptional) {
|
||||
if (!(args.length === 1 && _typeof(args[0]) === 'object' && Object.keys(args[0]).length)) {
|
||||
throw new Error("Must pass in only one object which holds arguments to this API method call.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
processPostMessage: processPostMessage,
|
||||
parseUrlQueryString: parseUrlQueryString,
|
||||
invokeApiCall: invokeApiCall,
|
||||
validateCallback: validateCallback,
|
||||
validateListener: validateListener,
|
||||
validateValueObject: validateValueObject,
|
||||
validateArguments: validateArguments
|
||||
};
|
||||
|
||||
/***/ }),
|
||||
/* 4 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Key => Value | [methodName_callId] => callbackFunctionReference
|
||||
|
||||
var callbacksMap = {};
|
||||
var getKey = function getKey(methodName, callId) {
|
||||
return methodName + "_" + callId;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Registers the callback so that it can be called after a response is received from the top window.
|
||||
* @param {String} methodName - Represents the name of the API method being invoked. Use one of the CONSTANTS.
|
||||
* @param {Integer} callId - Represents a unique integer ID to be associated with the method call. Use getCallId() to generate this.
|
||||
* @param {Function} callback - The function to be called.
|
||||
*/
|
||||
registerCallback: function registerCallback(methodName, callId, callback) {
|
||||
callbacksMap[getKey(methodName, callId)] = callback;
|
||||
},
|
||||
|
||||
/**
|
||||
* Executes the callback for the given method call ID and deletes it from the map after its executed.
|
||||
* @param {String} methodName - Represents the name of the API method being invoked. Use one of the CONSTANTS.
|
||||
* @param {Integer} callId - Represents a unique integer ID to be associated with the method call. Use getCallId() to generate this.
|
||||
* @param {Object} data - The data to be passed to the callback function.
|
||||
*/
|
||||
executeCallback: function executeCallback(methodName, callId, data) {
|
||||
var key = getKey(methodName, callId);
|
||||
if (callbacksMap[key]) {
|
||||
callbacksMap[key].call(null, data);
|
||||
delete callbacksMap[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/***/ }),
|
||||
/* 5 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Contains a list listeners (key-> method name_uniqueId, value -> listener methods)
|
||||
|
||||
var listenersMap = {};
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Registers the listener for the API method to be called when a value is returned from the top window.
|
||||
* @param {String} methodName - Represents the name of the API method being invoked.
|
||||
* @param {Function} listener - The function to be called whenever the API "methodName" returns a value.
|
||||
*/
|
||||
registerListener: function registerListener(methodName, listener) {
|
||||
if (listenersMap[methodName]) {
|
||||
listenersMap[methodName].push(listener);
|
||||
} else {
|
||||
listenersMap[methodName] = [listener];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Executes the registered.
|
||||
* @param {[type]} methodName the api method name to be executed
|
||||
* @param {[type]} data the arguments to be passed to callback
|
||||
*/
|
||||
executeListeners: function executeListeners(methodName, data) {
|
||||
var listeners = listenersMap[methodName];
|
||||
if (listeners) {
|
||||
listeners.forEach(function (listener) {
|
||||
listener.call(null, data);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
641
lightningInteraction.js
Normal file
641
lightningInteraction.js
Normal file
@ -0,0 +1,641 @@
|
||||
/******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId])
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ exports: {},
|
||||
/******/ id: moduleId,
|
||||
/******/ loaded: false
|
||||
/******/ };
|
||||
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.loaded = true;
|
||||
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
|
||||
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "/assets/";
|
||||
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
'use strict';
|
||||
|
||||
window.sforce = window.sforce || {};
|
||||
/* global sforce */
|
||||
sforce.opencti = __webpack_require__(1);
|
||||
sforce.opencti.initialize();
|
||||
|
||||
/***/ }),
|
||||
/* 1 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var config = __webpack_require__(2);
|
||||
var utils = __webpack_require__(3);
|
||||
var topFrameOriginPattern = /^http[s]?:\/\/[\w-.]+(\.force\.com|\.salesforce\.com)(:\d+)?$/;
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Initializes API to listen for responses from Salesforce.
|
||||
*/
|
||||
initialize: function initialize() {
|
||||
// Set the Salesforce frame origin and the nonce needed to call API methods.
|
||||
var params = utils.parseUrlQueryString(location.search);
|
||||
var sfdcIframeOrigin = params.sfdcIframeOrigin;
|
||||
if (sfdcIframeOrigin && params.mode && topFrameOriginPattern.test(sfdcIframeOrigin) && sfdcIframeOrigin.indexOf(window.location.protocol) === 0) {
|
||||
config.sfdcIframeOrigin = params.sfdcIframeOrigin;
|
||||
config.mode = params.mode;
|
||||
} else {
|
||||
//Fatal error: Can't proceed in initialization because the page didn't initialize properly.
|
||||
//TODO : think about providing validation utils to perform validation tasks in multiple methods
|
||||
throw "Failed to initialize Open CTI. Ensure that it is loaded from the right frame with correct URL parameters";
|
||||
}
|
||||
window.addEventListener('message', utils.processPostMessage, false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns in callback true if the softphone panel was successfully shown or hidden, false otherwise.
|
||||
* If false is returned, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {boolean} args.visible - true to show and false to hide the softphone container.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelVisibility: function setSoftphonePanelVisibility(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelVisibility', { visible: args.visible }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true if the softphone panel is currently shown, false otherwise.
|
||||
* If false is returned, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
isSoftphonePanelVisible: function isSoftphonePanelVisible(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateCallback(args);
|
||||
utils.invokeApiCall('isSoftphonePanelVisible', {}, args.callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Enum of the different screenpop types
|
||||
*/
|
||||
SCREENPOP_TYPE: {
|
||||
URL: "url",
|
||||
SOBJECT: "sobject",
|
||||
OBJECTHOME: "objecthome",
|
||||
LIST: "list",
|
||||
SEARCH: "search",
|
||||
NEW_RECORD_MODAL: "newRecord",
|
||||
FLOW: "flow"
|
||||
},
|
||||
|
||||
/**
|
||||
* Pops to the specified navigation type.
|
||||
* If false is returned, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Object} args.type - The enumerated type to screen-pop to.
|
||||
* @param {Object} args.params - An object holding arguments depending on the type.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
screenPop: function screenPop(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('screenPop', { type: args.type, params: args.params }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Enum of the different call types for searchandscreenpop.
|
||||
*/
|
||||
CALL_TYPE: {
|
||||
INBOUND: "inbound",
|
||||
OUTBOUND: "outbound",
|
||||
INTERNAL: "internal"
|
||||
},
|
||||
|
||||
/**
|
||||
* Searches objects specified in the softphone layout for a given string. Returns search results and screen pops any matching records. This method respects screen pop settings defined in the softphone layout.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.searchParams - The string to search for specified objects. The minimum character length is 3.
|
||||
* @param {Object} args.callType - One of the following types: sforce.openct.INBOUND | sforce.openct.OUTBOUND | sforce.openct.INTERNAL
|
||||
* @param {Object|String} args.queryParams - Specifies the query parameters to pass to the VisualForce URLs (when we pop to VisualForce page). Specify a string OR object. Objects are converted to strings of key/value pair and escaped before being passed.
|
||||
* @param {Object} args.defaultFieldValues - Specifies the default field values to pass to the new entity page(when we pop to new entity page).
|
||||
* @param {boolean} args.deferred - The default is false. If true, this function doesn't perform screen pop but instead passes back an object which can later be passed to sforce.opencti.screenPop API as an input to perform the same operation.
|
||||
*/
|
||||
searchAndScreenPop: function searchAndScreenPop(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('searchAndScreenPop', { searchParams: args.searchParams, callType: args.callType, queryParams: args.queryParams, defaultFieldValues: args.defaultFieldValues, deferred: args.deferred, params: args.params }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns information about the current page as a JSON string.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
getAppViewInfo: function getAppViewInfo(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateCallback(args);
|
||||
utils.invokeApiCall('getAppViewInfo', {}, args.callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true and provides the new object Id in callback if the object was successfully created or updated, null otherwise.
|
||||
* If false is returned, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Object} args.value - New object to create.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
saveLog: function saveLog(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateValueObject(args);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('saveLog', { object: args.value }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Refreshes the current view and returns JSON string true as part of the result if API call is successful.
|
||||
* If API call fails, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.callback - An optional function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
refreshView: function refreshView(args) {
|
||||
utils.validateArguments(arguments, true);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('refreshView', {}, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Notifies that the adapter url has been successfully loaded.
|
||||
*/
|
||||
notifyInitializationComplete: function notifyInitializationComplete(args) {
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('notifyInitializationComplete', {}, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the label in the softphone utility item.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.label - The label to set.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphoneItemLabel: function setSoftphoneItemLabel(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphoneItemLabel', { label: args.label }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the label in the softphone panel's header.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.label - The label to set.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelLabel: function setSoftphonePanelLabel(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelLabel', { label: args.label }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the icon in the softphone utility item.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.key - The image key of the icon to display.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphoneItemIcon: function setSoftphoneItemIcon(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphoneItemIcon', { key: args.key }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the icon in the softphone panel's header.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {string} args.key - The image key of the icon to display.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelIcon: function setSoftphonePanelIcon(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelIcon', { key: args.key }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the height of the softphone panel.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {number} args.heightPX - To set the height of the softphone panel, specify the height value in pixels.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelHeight: function setSoftphonePanelHeight(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelHeight', { heightPX: args.heightPX }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the width of the softphone panel.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {number} args.widthPX - To set the width of the softphone panel, specify the width in pixels.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
setSoftphonePanelWidth: function setSoftphonePanelWidth(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('setSoftphonePanelWidth', { widthPX: args.widthPX }, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns callCenterSettings in a JSON string as part of the results if the API call was successful.
|
||||
* If the API call fails, an error message is also returned.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.callback - Function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
getCallCenterSettings: function getCallCenterSettings(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateCallback(args);
|
||||
utils.invokeApiCall('getCallCenterSettings', {}, args.callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Registers a function to call when a user clicks an enabled phone number.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.listener - Function which will be called when a user clicks an enabled phone number.
|
||||
*/
|
||||
onClickToDial: function onClickToDial(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateListener(args);
|
||||
utils.invokeApiCall('onClickToDial', {}, undefined, args.listener);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns callCenterSettings in a JSON string as part of the results if the API call was successful.
|
||||
* If the API call fails, an error message is also returned.
|
||||
* @param {Object} callback - An input object with the following parameter:
|
||||
* {Function} callback - Executes function on success and returns an error on failure.
|
||||
*/
|
||||
enableClickToDial: function enableClickToDial(args) {
|
||||
utils.validateArguments(arguments, true);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('enableClickToDial', {}, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns callCenterSettings in a JSON string as part of the results if the API call was successful.
|
||||
* If the API call fails, an error message is also returned.
|
||||
* @param {Object} args - An input object with the following parameter:
|
||||
* @param {Function} args.callback - Executes function on success and returns an error on failure.
|
||||
*/
|
||||
disableClickToDial: function disableClickToDial(args) {
|
||||
utils.validateArguments(arguments, true);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('disableClickToDial', {}, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the softphone layout in a JSON string as part of the results if the API call was successful.
|
||||
* If the API call fails, an error message is also returned.
|
||||
* @param {Object} args - An input object with the following parameter:
|
||||
* @param {Function} args.callback - Executes function on success and returns an error on failure.
|
||||
*/
|
||||
getSoftphoneLayout: function getSoftphoneLayout(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateCallback(args);
|
||||
utils.invokeApiCall('getSoftphoneLayout', {}, args.callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Registers a function to be invoked on navigation changes.
|
||||
* @param {Object} args - An object holding arguments for calls to this method.
|
||||
* @param {Function} args.listener - Function which will be called when navigation has changed.
|
||||
*/
|
||||
onNavigationChange: function onNavigationChange(args) {
|
||||
utils.validateArguments(arguments);
|
||||
utils.validateListener(args);
|
||||
utils.invokeApiCall('onNavigationChange', {}, undefined, args.listener);
|
||||
},
|
||||
|
||||
/**
|
||||
* Runs a method from an Apex class with supplied parameters.
|
||||
* @param {Object} args - An object holding arguments for calls to this method. For this method to work, you must provide an args object containing the following: apexClass (i.e. AccountRetrieval), methodName (i.e. getAccount) and methodParams (i.e. firstName=Charles&lastName=Green).
|
||||
* @param {Function} args.callback - An optional function which will be called upon completion of this method's invocation.
|
||||
*/
|
||||
runApex: function runApex(args) {
|
||||
utils.validateArguments(arguments);
|
||||
var callback = args ? args.callback : undefined;
|
||||
utils.invokeApiCall('runApex', {
|
||||
apexClass: args.apexClass,
|
||||
methodName: args.methodName,
|
||||
methodParams: args.methodParams
|
||||
}, callback);
|
||||
}
|
||||
};
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
API_VERSION: 43,
|
||||
API_TYPE: 'opencti',
|
||||
sfdcIframeOrigin: null, // will be populated in during initialization
|
||||
mode: null // will be populated in during initialization
|
||||
};
|
||||
|
||||
/***/ }),
|
||||
/* 3 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
||||
|
||||
var config = __webpack_require__(2);
|
||||
var callbackManager = __webpack_require__(4);
|
||||
var listenerManager = __webpack_require__(5);
|
||||
|
||||
/**
|
||||
* Get a unique Call ID.
|
||||
*/
|
||||
var getCallId = function () {
|
||||
//All API Calls increment this value and thus will have a unique ID
|
||||
var callId = 0;
|
||||
return function () {
|
||||
return callId++;
|
||||
};
|
||||
}();
|
||||
|
||||
/**
|
||||
* Process messages received from Salesforce by executing callbacks, if any.
|
||||
* The event.data object contains the following fields:
|
||||
* {
|
||||
* apiVersion {Integer} - The version of API.
|
||||
* apiType {String} - The type of API.
|
||||
* methodName {String} - The name of the API method to be invoked.
|
||||
* callId {Integer} - A unique ID for this window and API call.
|
||||
* response - {Object}
|
||||
* success - Boolean value indicating if the API executed correctly.
|
||||
* returnValue - Any return value.
|
||||
* errors - Any error if present.
|
||||
* }
|
||||
*/
|
||||
var processPostMessage = function processPostMessage(event) {
|
||||
var eventData = event.data;
|
||||
if (eventData && eventData.apiVersion === config.API_VERSION && eventData.apiType === config.API_TYPE && event.origin === config.sfdcIframeOrigin) {
|
||||
// execute callbacks and listeners registered for the method called
|
||||
callbackManager.executeCallback(eventData.methodName, eventData.callId, eventData.response);
|
||||
listenerManager.executeListeners(eventData.methodName, eventData.response);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: Replace this with a more robust implementation.
|
||||
* Utility method to create a query string object.
|
||||
* @param {String} queryString - Represents the location.search value or any GET (key/value) pair string in the URL.
|
||||
* @return {Object} - JSON of the key/value pairs in the given string of GET values in the URL.
|
||||
*/
|
||||
var parseUrlQueryString = function parseUrlQueryString(queryString) {
|
||||
var params = {};
|
||||
if (typeof queryString !== 'string') {
|
||||
return params;
|
||||
}
|
||||
|
||||
if (queryString.charAt(0) === '?') {
|
||||
queryString = queryString.slice(1);
|
||||
}
|
||||
|
||||
if (queryString.length === 0) {
|
||||
return params;
|
||||
}
|
||||
|
||||
var pairs = queryString.split('&');
|
||||
for (var i = 0; i < pairs.length; i++) {
|
||||
var pair = pairs[i].split('=');
|
||||
if (pair[0]) {
|
||||
// Pre-emptive gaurd agains bad URLS which have no key "&=1234"
|
||||
if (params[pair[0]]) {
|
||||
//encountered a multi value input GET
|
||||
if (_typeof(params[pair[0]]) === 'object') {
|
||||
//already created an array.. push to it
|
||||
params[pair[0]].push(pair[1] ? decodeURIComponent(pair[1]) : null);
|
||||
} else {
|
||||
// create new array and push to it.
|
||||
var tmp = params[pair[0]];
|
||||
params[pair[0]] = [];
|
||||
params[pair[0]].push(tmp);
|
||||
params[pair[0]].push(pair[1] ? decodeURIComponent(pair[1]) : null);
|
||||
}
|
||||
} else {
|
||||
params[pair[0]] = pair[1] ? decodeURIComponent(pair[1]) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes an API call to the Salesforce domain in the top window.
|
||||
* @param {String} methodName - Represents the name of the API method being invoked.
|
||||
* @param {Object} args - Represents the data to be sent for the API to function.
|
||||
* @param {Function} callback [optional] - The callback to be called after the API returns a value (success or failure).
|
||||
*/
|
||||
var invokeApiCall = function invokeApiCall(methodName, args, callback, listener) {
|
||||
|
||||
/**
|
||||
* Post message object.
|
||||
*
|
||||
* API methods should have a unique ID in case they are called multiple times in an asynchronous manner.
|
||||
* This helps differentiate between calls and also calculating performance for each of the calls.
|
||||
* {
|
||||
* apiVersion {Integer} - The version of API.
|
||||
* apiType {String} - The type of API.
|
||||
* methodName {String} - The name of the API method to be invoked.
|
||||
* callId {Integer} - A unique ID for this window and API call.
|
||||
* isListenerRegistered {Boolean} - Indicates if a listener was registered.
|
||||
* isCallbackRegistered {Boolean} - Indicates if the user supplied a callback
|
||||
* args {Object} - Depends on the API type. Holds all the information passed for that API to function.
|
||||
* }
|
||||
*/
|
||||
var params = {
|
||||
methodName: methodName,
|
||||
callId: getCallId(),
|
||||
apiVersion: config.API_VERSION,
|
||||
apiType: config.API_TYPE,
|
||||
isCallbackRegistered: false,
|
||||
isListenerRegistered: false,
|
||||
args: args
|
||||
};
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callbackManager.registerCallback(params.methodName, params.callId, callback);
|
||||
params.isCallbackRegistered = true;
|
||||
}
|
||||
|
||||
if (typeof listener === 'function') {
|
||||
listenerManager.registerListener(params.methodName, listener);
|
||||
params.isListenerRegistered = true;
|
||||
}
|
||||
|
||||
parent.postMessage(params, config.sfdcIframeOrigin);
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates the callback argument in args.
|
||||
*/
|
||||
var validateCallback = function validateCallback(args) {
|
||||
if (!(args && typeof args.callback === 'function')) {
|
||||
throw new Error("Missing the required argument `callback`!");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates the listener argument in args.
|
||||
*/
|
||||
var validateListener = function validateListener(args) {
|
||||
if (!(args && typeof args.listener === 'function')) {
|
||||
throw new Error("Missing the required argument `listener`!");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: Shouldn't this be handled by opencti:openCtiApiHandler?
|
||||
* Validates the value argument in args for saveLog API.
|
||||
*/
|
||||
var validateValueObject = function validateValueObject(args) {
|
||||
if (!(args && _typeof(args.value) === 'object')) {
|
||||
throw new Error("Missing the required argument `value object`!");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates the input arguments to ensure there is only one argument passed in which is of type object if isOptional is false or isOptional is true but args.length > 0.
|
||||
*/
|
||||
var validateArguments = function validateArguments(args, isOptional) {
|
||||
if (isOptional && args.length || !isOptional) {
|
||||
if (!(args.length === 1 && _typeof(args[0]) === 'object' && Object.keys(args[0]).length)) {
|
||||
throw new Error("Must pass in only one object which holds arguments to this API method call.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
processPostMessage: processPostMessage,
|
||||
parseUrlQueryString: parseUrlQueryString,
|
||||
invokeApiCall: invokeApiCall,
|
||||
validateCallback: validateCallback,
|
||||
validateListener: validateListener,
|
||||
validateValueObject: validateValueObject,
|
||||
validateArguments: validateArguments
|
||||
};
|
||||
|
||||
/***/ }),
|
||||
/* 4 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Key => Value | [methodName_callId] => callbackFunctionReference
|
||||
|
||||
var callbacksMap = {};
|
||||
var getKey = function getKey(methodName, callId) {
|
||||
return methodName + "_" + callId;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Registers the callback so that it can be called after a response is received from the top window.
|
||||
* @param {String} methodName - Represents the name of the API method being invoked. Use one of the CONSTANTS.
|
||||
* @param {Integer} callId - Represents a unique integer ID to be associated with the method call. Use getCallId() to generate this.
|
||||
* @param {Function} callback - The function to be called.
|
||||
*/
|
||||
registerCallback: function registerCallback(methodName, callId, callback) {
|
||||
callbacksMap[getKey(methodName, callId)] = callback;
|
||||
},
|
||||
|
||||
/**
|
||||
* Executes the callback for the given method call ID and deletes it from the map after its executed.
|
||||
* @param {String} methodName - Represents the name of the API method being invoked. Use one of the CONSTANTS.
|
||||
* @param {Integer} callId - Represents a unique integer ID to be associated with the method call. Use getCallId() to generate this.
|
||||
* @param {Object} data - The data to be passed to the callback function.
|
||||
*/
|
||||
executeCallback: function executeCallback(methodName, callId, data) {
|
||||
var key = getKey(methodName, callId);
|
||||
if (callbacksMap[key]) {
|
||||
callbacksMap[key].call(null, data);
|
||||
delete callbacksMap[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/***/ }),
|
||||
/* 5 */
|
||||
/***/ (function(module, exports) {
|
||||
|
||||
'use strict';
|
||||
|
||||
// Contains a list listeners (key-> method name_uniqueId, value -> listener methods)
|
||||
|
||||
var listenersMap = {};
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Registers the listener for the API method to be called when a value is returned from the top window.
|
||||
* @param {String} methodName - Represents the name of the API method being invoked.
|
||||
* @param {Function} listener - The function to be called whenever the API "methodName" returns a value.
|
||||
*/
|
||||
registerListener: function registerListener(methodName, listener) {
|
||||
if (listenersMap[methodName]) {
|
||||
listenersMap[methodName].push(listener);
|
||||
} else {
|
||||
listenersMap[methodName] = [listener];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Executes the registered.
|
||||
* @param {[type]} methodName the api method name to be executed
|
||||
* @param {[type]} data the arguments to be passed to callback
|
||||
*/
|
||||
executeListeners: function executeListeners(methodName, data) {
|
||||
var listeners = listenersMap[methodName];
|
||||
if (listeners) {
|
||||
listeners.forEach(function (listener) {
|
||||
listener.call(null, data);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
5727
package-lock.json
generated
Normal file
5727
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
package.json
Normal file
14
package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "Demo-crm",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "gulp server"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"gulp": "^4.0.2",
|
||||
"browser-sync": "^2.29.3",
|
||||
"minimist": "^1.2.8"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user