Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.60 KB | None | 0 0
  1. (function(scope, document, $) {
  2. 'use strict';
  3.  
  4. // Constantes
  5. var MAX_RETRIES = 5;
  6.  
  7. var $cometd = scope.$cometd || $.cometd,
  8. _handlers = {},
  9. _state = {
  10. endpoint: '',
  11. restService: '',
  12. cometdService: '',
  13. connected: false,
  14. wasConnected: true,
  15. allowManualHandshake: true,
  16. retries: 0,
  17. auth: {
  18. extension: '',
  19. siteid: '',
  20. linkType: '',
  21. password: '',
  22. username: '',
  23. teamid: null
  24. /*campaignid: null*/
  25. /*reason: null*/
  26. }
  27. },
  28. ACCESS_TOKEN = '',
  29. EXPIRES_IN = ''
  30.  
  31. /**
  32. * Funciones públicas del módulo
  33. */
  34. /**
  35. * Inicializa la conexión a CometD
  36. **
  37. * @author jmartinezpisson
  38. * @date 24/09/2017
  39. */
  40. function init(settings) {
  41. console.log('Initializing CometD client');
  42. // 1 - Inicializamos y registramos los handlers
  43. settings = settings || {};
  44. settings.events = settings.events || {};
  45.  
  46. _state.endpoint = settings.endpoint.base || '';
  47. _state.restService = settings.endpoint.restService || '';
  48. _state.cometdService = settings.endpoint.cometdService || '';
  49. _state.auth.extension = settings.extension || '';
  50. _state.auth.siteid = settings.siteId || '';
  51. _state.auth.linkType = settings.linkType || '';
  52.  
  53. _state.auth.username = settings.username || '';
  54. _state.auth.password = settings.password || '';
  55.  
  56. // Función de obtención de credenciales OAuth
  57. if(typeof(settings.getOAuthCredentials) === 'function') {
  58. getOAuthCredentials = settings.getOAuthCredentials;
  59. }
  60.  
  61. for (var event in settings.events) {
  62. if (settings.events.hasOwnProperty(event)) {
  63. addHook(event, settings.events[event]);
  64. }
  65. }
  66.  
  67. // 2 - Se revisa que los eventos del sistema tienen handler asociado y se lanza un error en caso contrario
  68. if (!_handlers.onConnectionEstablished || !_handlers.onConnectionRetry ||
  69. !_handlers.onConnectionBroken || !_handlers.onConnectionClosed ||
  70. !_handlers.onHandshakeSuccess || !_handlers.onHandshakeError ||
  71. !_handlers.onDisconnection || !_handlers.onRetryError) {
  72. throw new Error('Fatal Error. No callback registered for softphone system events. Please check the initialization config.');
  73. }
  74.  
  75. // 3 - Se añaden los listeners a los canales de CometD:
  76. $cometd.addListener("/meta/handshake", _metaHandshake);
  77. $cometd.addListener("/meta/connect", _metaConnect);
  78. $cometd.addListener('/meta/disconnect', _metaDisconnect);
  79.  
  80. // 4 - Se añade gestión de excepciones
  81. $cometd.onListenerException = function(exception, subscriptionHandle, isListener, message) {
  82. console.log(exception);
  83. console.log(message);
  84. };
  85.  
  86. console.log('CometD client reporting for duty!');
  87.  
  88. // 5 - Get Access Token
  89. // getToken();
  90. }
  91.  
  92. /**
  93. * Registra un hook para ejecutar un callback ante un evento de BIG/CometD
  94. **
  95. * @author jmartinezpisson
  96. * @date 24/09/2017
  97. */
  98. function addHook(event, handler) {
  99. _handlers[event] = handler;
  100. _handlers[event.charAt(0).toUpperCase() + event.slice(1)] = handler;
  101. }
  102.  
  103. /**
  104. * Elimina un hook para un evento determinado
  105. **
  106. * @author jmartinezpisson
  107. * @date 24/09/2017
  108. */
  109. function removeHook(event, handler) {
  110. var capitalizedEvent = event.charAt(0).toUpperCase() + event.slice(1);
  111.  
  112. if (_handlers[event]) {
  113. delete _handlers[event];
  114. }
  115.  
  116. if (_handlers[capitalizedEvent]) {
  117. delete _handlers[capitalizedEvent];
  118. }
  119. }
  120.  
  121. /**
  122. * Inicializa la comunicación CometD
  123. **
  124. * @author jmartinezpisson
  125. * @date 28/09/2017
  126. */
  127. function start(settings) {
  128.  
  129. if (settings) {
  130. _state.auth.extension = (settings.extension || settings.extension === '')? settings.extension:_state.auth.extension;
  131. _state.auth.username = (settings.username || settings.username === '')? settings.username:_state.auth.username;
  132. _state.auth.password = (settings.password || settings.password === '')? settings.password:_state.auth.password;
  133. _state.auth.siteid = settings.siteId || _state.auth.siteid;
  134. _state.auth.linkType = settings.linkType || _state.auth.linkType;
  135. _state.auth.teamid = settings.teamId || _state.auth.teamid;
  136. //_state.auth.campaignid = settings.campaignid || _state.auth.campaignid; // Comentado con miedo por axel
  137.  
  138. _state.allowManualHandshake = settings.isRestart? !settings.isRestart:true;
  139. }
  140.  
  141. $cometd.configure({
  142. url: _state.cometdService
  143. });
  144.  
  145. var additional = {
  146. extension: _state.auth.extension,
  147. apptype: 'desktop',
  148. siteid: _state.auth.siteid,
  149. linktype: _state.auth.linkType,
  150. agentname: _state.auth.username
  151. };
  152.  
  153. getToken().then(function() {
  154. console.log('Resolve on getToken');
  155. $cometd.handshake(additional);
  156.  
  157. }).catch(function(error) {
  158. console.log('Reject on getToken: ' + error);
  159. _handlers.onHandshakeError(_state.allowManualHandshake, settings.isRestart);
  160. });
  161.  
  162. }
  163.  
  164. /**
  165. * Actualiza los parametros internos de las peticiones
  166. */
  167. function updateAuth(settings) {
  168. if (settings) {
  169. _state.auth = Object.assign(_state.auth, settings);
  170. }
  171. }
  172.  
  173. /**
  174. * Detiene la comunicación CometD
  175. **
  176. * @author jmartinezpisson
  177. * @date 28/09/2017
  178. */
  179. function stop() {
  180. $cometd.disconnect(function() {
  181. _state.allowManualHandshake = true;
  182. _handlers.onDisconnection();
  183. });
  184. }
  185.  
  186. /**
  187. * Funciones privadas del módulo
  188. */
  189.  
  190. /**
  191. * Util Functions
  192. */
  193. function _logCometd(channel, message) {
  194. console.log(' >> ' + channel + 'Subscribe </br>');
  195. console.log(' >> Evento: ' + message.data.name + '</br>');
  196.  
  197. if (message.data.name === "OnAgentStateChanged") {
  198. console.log('&#183; Estado Agente[' + message.data.username + ']: ' + message.data.status + ' - ReasonCode: ' + message.data.reason + '</br>');
  199. } else {
  200. _createLog(message.data);
  201. }
  202. }
  203.  
  204. function _createLog(data) {
  205. var props = [];
  206. var knownProps = {
  207. name: '<span style="background-color: #FFEB3B; color: #00BCD4;"> >>> New Event[' + new Date().toJSON() + ']: ' + data.name + '</span>',
  208. extension: ' - Extension: ' + data.extension,
  209. provider: '- Provider: ' + data.provider,
  210. username: '- Username: ' + data.username
  211. };
  212.  
  213. for (var prop in data) {
  214. if (data.hasOwnProperty(prop) && !knownProps.hasOwnProperty(prop)) {
  215. props.push(' - ' + prop.charAt(0).toUpperCase() + prop.slice(1) + ': ' + data[prop]);
  216. }
  217. }
  218.  
  219. console.log('<div>' +
  220. knownProps.name +
  221. '<br>' + knownProps.extension +
  222. '<br>' + knownProps.provider +
  223. '<br>' + knownProps.username +
  224. '<br>' + props.join('<br>') +
  225. '</div>'
  226. );
  227. }
  228.  
  229. function _keysToCamelCase(target) {
  230. var stringToCamelCase = function(s) {
  231. return s.replace(/-([a-z])/g, function(g) {
  232. return g[1].toUpperCase();
  233. });
  234. }
  235. var i = 0;
  236. for (var key in target) {
  237. if (typeof target[key] !== 'undefined') {
  238. if (typeof target[key] === 'object' && !(target[key] instanceof Array)) {
  239. _keysToCamelCase(target[key]);
  240. }
  241. if (target[key] instanceof Array) {
  242. for (var i = 0; i < target[key].length; i++) {
  243. _keysToCamelCase(target[key][i]);
  244. }
  245. }
  246. if (~key.indexOf('_') || ~key.indexOf('-')) {
  247. var oldKey = key;
  248. key = key.replace(/_/g, '-');
  249. key = stringToCamelCase(key);
  250. target[key] = target[oldKey];
  251. delete target[oldKey];
  252. }
  253. }
  254. i = ++i;
  255. }
  256. return target;
  257. }
  258.  
  259. /**
  260. * CometD - Hard Reset. Fuerza la desconexión y un nuevo handshake.
  261. **
  262. * @author jmartinezpisson
  263. * @date 24/09/2017
  264. */
  265. function _hardReset(handshake) {
  266. $cometd.disconnect(function() {
  267. start();
  268. });
  269. }
  270. /**
  271. * CometD - Handshake handler. Gestiona el handshake de CometD
  272. **
  273. * @author jmartinezpisson
  274. * @date 24/09/2017
  275. */
  276. function _metaHandshake(handshake) {
  277. var isManualHandshake = _state.allowManualHandshake;
  278.  
  279. console.log('Handshake: ' + handshake.successful);
  280. console.log(handshake);
  281.  
  282. // 1 - Gestión del success
  283. if (handshake.successful) {
  284. if ($cometd.getAdvice() && $cometd.getAdvice().reconnect === 'handshake') {
  285. console.log('CometD: Received advice: handshake during a succesful handshake. Resetting...');
  286. return start();
  287. }
  288.  
  289. console.log('CometD: successful handshake');
  290.  
  291. // 1.1 - Se ejecuta un callback para la gestión de un handshake exitoso, identificando si el handshake ha sido manual y bloqueando la ejecución de futuros
  292. _state.allowManualHandshake = false;
  293. _handlers.onHandshakeSuccess(isManualHandshake);
  294.  
  295.  
  296. // 1.2 - En algunas centralitas se realiza una gestión posterior del token para realizar la monitorización
  297. if (_handlers.onHandshakeTokenReceived) {
  298. // Datos que necesitamos de BIG (Token de acceso que necesitamos para la monitorizacion)
  299. if (handshake.ext && handshake.ext.token) {
  300. _handlers.onHandshakeTokenReceived(handshake.ext.token, isManualHandshake);
  301. } else {
  302. // No se ha recibido correctamente el Token; si no, es un error en el handshake
  303. if (handshake.ext) {
  304. _handlers.onHandshakeError(isManualHandshake);
  305. } else {
  306. alert('Error, el handshake no ha sido correcto');
  307. }
  308. }
  309. }
  310.  
  311. // 1.3 - Se (re)suscribe a los eventos de BIG
  312. _suscribeChannels(handshake);
  313. } else { // 2 - Gestión de errores en callbacks
  314.  
  315. // 2.1 - Se lanza el callback de gestión de errores en handshake
  316. _handlers.onHandshakeError(isManualHandshake);
  317.  
  318. // 2.2 - Si el handshake es manual y falla no se reintenta la conexión.
  319. console.log($cometd.isDisconnected());
  320. if (_state.allowManualHandshake) {
  321. return $cometd.disconnect();
  322. }
  323.  
  324. // 2.3 - Se evita un reintento en fallos graves de conexión
  325. if ((handshake.error && handshake.error.indexOf("403") === 0) || (handshake.failure && handshake.failure.reason.indexOf("Extra Connection") === 0)) {
  326. _state.tryReconnecting = false;
  327. }
  328. }
  329. }
  330.  
  331. /**
  332. * CometD - Handshake handling. Función auxiliar para escuchar los canales y eventos de BIG
  333. **
  334. * @author jmartinezpisson
  335. * @date 24/09/2017
  336. */
  337. function _suscribeChannels(handshake) {
  338. var bigChannelSubscribe = '/cti/' + _state.extension + '/*';
  339.  
  340. if (handshake.ext && handshake.ext.bigchannel) {
  341. bigChannelSubscribe = handshake.ext.bigchannel;
  342. }
  343.  
  344. $cometd.batch(function() {
  345. $cometd.subscribe(bigChannelSubscribe, function(message) {
  346. _logCometd('BigChannelSubscribe', message);
  347.  
  348. if (_handlers[message.data.name]) {
  349. _handlers[message.data.name](message.data);
  350. } else {
  351. console.log('No CometD Handler Registered for ' + message.data.name);
  352. }
  353. });
  354. });
  355. }
  356.  
  357. /**
  358. * Gestiona el estado de la conexión al servidor Bayeux
  359. **
  360. * @author jmartinezpisson
  361. * @date 24/09/2017
  362. * @change 04/10/2017 jmartienzpisson Cambiada la gestión de reintentos para hacerla más robusta
  363. */
  364. function _metaConnect(message) {
  365.  
  366. console.log('>> MetaConnect - ID: ' + message.id + ' – Date: ' + new Date().toJSON());
  367.  
  368. // 1 - Si CometD, se encuentra desconectado, se obvia el LongPolling. Para gestionar una desconexión completa, se usa el canal metadisconnect
  369. if ($cometd.isDisconnected()) {
  370. console.log('CometD: Metaconnect - Desconexión CometD');
  371. return;
  372. }
  373.  
  374. // 2 - Se almacena el estado anterior de conexión y se verifica si la conexión es correcta
  375. _state.wasConnected = _state.connected;
  376. _state.connected = (message.successful === true);
  377.  
  378. // 3 -Se actua en caso de (re)conexión, desconexión parcial (gestionada automáticamente por CometD)
  379. // y reintentos fallidos
  380. // 3.1 - Si se ha producido una conexión
  381. if (!_state.wasConnected && _state.connected) {
  382. console.log('CometD: Metaconnect - Conexión establecida');
  383. console.log(message);
  384. _handlers.onConnectionEstablished(_state.retries);
  385. _state.retries = 0;
  386.  
  387. // 3.2 - Si se ha producido una desconexión
  388. } else if (_state.wasConnected && !_state.connected) {
  389. console.log('CometD: Metaconnect - Conexión rota');
  390. console.log(message);
  391. _handlers.onConnectionBroken();
  392. // 3.3 - Si se ha producido un reintento
  393. } else if (!_state.wasConnected && !_state.connected) {
  394. console.log('CometD: Metaconnect - Intento de reconexión erróneo');
  395. console.log(message);
  396. _state.retries++;
  397.  
  398. if (_state.retries > MAX_RETRIES) {
  399. _handlers.onConnectionRetry(_state.retries);
  400. } else {
  401. _handlers.onRetryError();
  402.  
  403. scope.setTimeout(function() {
  404. stop();
  405. }, 2000);
  406. }
  407. }
  408. }
  409.  
  410. function _metaDisconnect(message) {
  411. console.log('Disconnection');
  412. console.log(message);
  413.  
  414. // Independientemente de si la desconexión se produce en servidor, la libería CometD borra su estado interno, por lo que se considera una desconexión
  415. _state.connected = false;
  416. _state.wasConnected = false;
  417. _state.retries = 0;
  418. _handlers.onConnectionClosed();
  419. }
  420.  
  421.  
  422. /**
  423. * BIG REST
  424. **/
  425.  
  426. <!--[if gte IE 9]><!-->
  427. $.ajaxSetup({
  428. cache: false
  429. });
  430. <!--<![endif]-->
  431.  
  432. //Funciones de OAuth2
  433. function getToken() {
  434. return new Promise(function(resolve, reject) {
  435. console.log(' #### getToken Request #### ');
  436.  
  437. getOAuthCredentials().then(function(oAuthCredentials) {
  438. var credentials = Object.assign({
  439. grant_type: 'password'
  440. }, oAuthCredentials);
  441.  
  442. $.ajax({
  443. url: _state.endpoint + "/api/token",
  444. type: "POST",
  445. dataType: "json",
  446. data: credentials,
  447. success: function(json) {
  448. ACCESS_TOKEN = json.access_token;
  449. EXPIRES_IN = json.expires_in;
  450. console.log('Token received: ' + ACCESS_TOKEN + ' - Expires in ' + EXPIRES_IN + ' seconds');
  451. window.setTimeout(function() {
  452. refreshToken();
  453. }, EXPIRES_IN * 1000);
  454.  
  455. resolve();
  456. },
  457. error: function(error) {
  458. console.log(error);
  459. reject(error)
  460. //tokenError('Error retreiving the token');
  461. },
  462. });
  463. })
  464. });
  465. }
  466.  
  467. function refreshToken() {
  468. console.log(' #### refreshToken Request #### ');
  469. console.log('Parameters: ' + _state.endpoint + _state.restService);
  470. if (ACCESS_TOKEN) {
  471. $.ajax({
  472. url: _state.endpoint + _state.restService + "/api/token",
  473. type: "POST",
  474. dataType: "json",
  475. headers: {
  476. 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate',
  477. 'Pragma': 'no-cache'
  478. },
  479. data: {
  480. grant_type: "refresh_token",
  481. refresh_token: ACCESS_TOKEN,
  482. client_secret: "oauth2clientsecret",
  483. client_id: "oauth2test"
  484. },
  485. success: function(json) {
  486. ACCESS_TOKEN = json.access_token;
  487. EXPIRES_IN = json.expires_in;
  488.  
  489. window.setTimeout(function() {
  490. refreshToken();
  491. }, EXPIRES_IN * 1000);
  492. },
  493. error: function() {
  494. console.log('Error with token request');
  495. },
  496. })
  497. }
  498. }
  499.  
  500. //Funcion que devuelve una promesa con las credenciales del oAuth
  501. function getOAuthCredentials() {
  502. return new Promise(function(resolve, reject) {
  503. //Se simula que se obtienen las credenciales.
  504. //Esto HAY QUE MODIFICARLO PARA OBTENERLAS DE FUERA?
  505. var obj = {
  506. username: '',
  507. password: '',
  508. client_secret: '',
  509. client_id: ''
  510. }
  511. resolve(obj);
  512. });
  513. }
  514.  
  515. function debug(name, args) {
  516. var debug = '';
  517.  
  518. for (var key in args) {
  519. debug += key + ': ' + args[key] + '<br />';
  520. }
  521.  
  522. console.log('#### ' + name + ' Request #### ' + new Date().toJSON());
  523. console.log('Parameters:<br/>' + debug);
  524. }
  525.  
  526. // Name. def.name
  527. // ReturnValue: def.returnValueAttribute
  528. // Error: def.errorAttribute
  529. // useCredentials: true/false
  530. // useAccessToken: true/false
  531. function promisify(def) {
  532. return function(args, keepHyphens) {
  533. // 0 - Tratamiento parámetros
  534. args = args || {};
  535.  
  536. if (def.useCredentials !== false) {
  537. args = Object.assign(args, _state.auth);
  538. }
  539.  
  540. if (def.useAccessToken !== false) {
  541. args.access_token = ACCESS_TOKEN;
  542. }
  543.  
  544. // 1 - Debug
  545. debug(def.name, args);
  546.  
  547. // 2 - Llamada
  548. return new Promise(function(resolve, reject) {
  549. $.ajax({
  550. url: _state.restService + '/' + def.name,
  551. type: 'GET',
  552. async: false,
  553. contentType: "application/json",
  554. dataType: 'jsonp',
  555. headers: {
  556. 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate',
  557. 'Pragma': 'no-cache'
  558. },
  559. data: formatParams(args),
  560. error: function(xhr, status, error) {
  561. console.log(def.name);
  562. console.log('URL Disconnect - Reconnection. - Error: ' + error);
  563. reject(error);
  564. },
  565. success: function(json) {
  566. console.log(def.name);
  567. if (json.response === 'OK') {
  568. console.log('Response: Success');
  569.  
  570. if (!keepHyphens) {
  571. json = _keysToCamelCase(json);
  572. }
  573.  
  574. if (typeof(def.returnValue) === 'function') {
  575. resolve(def.returnValue(json));
  576. } else {
  577. resolve(def.returnValue ?
  578. json[def.returnValue] :
  579. true
  580. );
  581. }
  582.  
  583. } else {
  584. console.log('Response: Failure - ' + (def.errorAttribute ? json[def.errorAttribute] : json.failureDescription));
  585.  
  586. reject(def.errorAttribute ?
  587. json[def.errorAttribute] :
  588. (json.failureDescription? json.failureDescription: json.failuredescription)
  589. );
  590. }
  591. },
  592. });
  593. });
  594. }
  595. }
  596.  
  597. function formatParams(args) {
  598. var params = [];
  599.  
  600. for (var key in args) {
  601. if (args[key] || args[key] === '') {
  602. params.push(key + '=' + args[key]);
  603. }
  604. }
  605.  
  606. return params.join('&');
  607. }
  608.  
  609. var restDefinitions = {
  610. login: promisify({
  611. name: 'login',
  612. useCredentials: true,
  613. useAccessToken: true,
  614. returnValue: function (response) {
  615. return response;
  616. }
  617. }),
  618. logout: promisify({
  619. name: 'logout',
  620. useCredentials: true,
  621. useAccessToken: true
  622. }),
  623. extension: promisify({
  624. name: 'extension',
  625. useCredentials: true,
  626. useAccessToken: true
  627. }),
  628. getStatusCalls: promisify({
  629. name: 'getstatuscalls',
  630. useCredentials: true,
  631. useAccessToken: true,
  632. returnValue: function(response) {
  633. return {
  634. extension: _state.auth.extension,
  635. calls: response.calls
  636. }
  637. }
  638. }),
  639. getState: promisify({
  640. name: 'getstate',
  641. useCredentials: true,
  642. useAccessToken: true,
  643. returnValue: function(response) {
  644. return {
  645. state: response.state,
  646. workMode: response.workmode,
  647. reason: response.reason,
  648. pendingState: response.pendingstate,
  649. pendingReason: response.pendingreason
  650. };
  651. }
  652. }),
  653. getSessionInfo: promisify({
  654. name: 'getsessioninfo',
  655. useCredentials: true,
  656. useAccessToken: true,
  657. returnValue: function(response) {
  658. return {
  659. services: {
  660. campaigns: response.sessionInfoList.serviceInfoList
  661. },
  662. session: {
  663. agentName: response.sessionInfoList.agentName
  664. }
  665. }
  666. }
  667. }),
  668. setReady: promisify({
  669. name: 'setready',
  670. useCredentials: true,
  671. useAccessToken: true
  672. }),
  673. setNotReady: promisify({
  674. name: 'setnotready',
  675. useCredentials: true,
  676. useAccessToken: true
  677. }),
  678. makeCall: promisify({
  679. name: 'makecall',
  680. useCredentials: true,
  681. useAccessToken: true,
  682. returnValue: function (response) {
  683. if(response.hasOwnProperty('sessionid')){
  684. return response.sessionid;
  685. }
  686. else{
  687. return response.cid;
  688. }
  689. }
  690. }),
  691. consultationCall: promisify({
  692. name: 'consultation',
  693. useCredentials: true,
  694. useAccessToken: true,
  695. returnValue: 'cid'
  696. }),
  697. blindTransferCall: promisify({
  698. name: 'blindtransfer',
  699. useCredentials: true,
  700. useAccessToken: true,
  701. returnValue: 'cid'
  702. }),
  703. transferCall: promisify({
  704. name: 'transfer',
  705. useCredentials: true,
  706. useAccessToken: true,
  707. returnValue: 'cid'
  708. }),
  709. answerCall: promisify({
  710. name: 'answer',
  711. useCredentials: true,
  712. useAccessToken: true
  713. }),
  714. clearCall: promisify({
  715. name: 'clearcall',
  716. useCredentials: true,
  717. useAccessToken: true
  718. }),
  719. clearAllCalls: promisify({
  720. name: 'clearallcalls',
  721. useCredentials: true,
  722. useAccessToken: true
  723. }),
  724. retrieveCall: promisify({
  725. name: 'retrieve',
  726. useCredentials: true,
  727. useAccessToken: true
  728. }),
  729. holdCall: promisify({
  730. name: 'hold',
  731. useCredentials: true,
  732. useAccessToken: true
  733. }),
  734. sendDtmf: promisify({
  735. name: 'senddtmf',
  736. useCredentials: true,
  737. useAccessToken: true
  738. }),
  739. // Presence/Altitude
  740. site: promisify({
  741. name: 'site',
  742. useCredentials: true,
  743. useAccessToken: true
  744. }),
  745. getStatus: promisify({
  746. name: 'getstatus',
  747. useCredentials: true,
  748. useAccessToken: true,
  749. returnValue: function (response) {
  750. return {
  751. campaigns: response.campaigns,
  752. status: response.status,
  753. sessions: response.sessions
  754. };
  755. }
  756. }),
  757. getQCode: promisify({
  758. name: 'getqcode',
  759. useCredentials: true,
  760. useAccessToken: true,
  761. returnValue: 'listqcode'
  762. }),
  763. setQCode: promisify({
  764. name: 'setqcode',
  765. useCredentials: true,
  766. useAccessToken: true
  767. }),
  768. startSession: promisify({
  769. name: 'startsession',
  770. useCredentials: true,
  771. useAccessToken: true
  772. }),
  773. stopSession: promisify({
  774. name: 'stopsession',
  775. useCredentials: true,
  776. useAccessToken: true
  777. }),
  778. getLogoutReasons: promisify({
  779. name: 'getLogoutCode',
  780. useCredentials: true,
  781. useAccessToken: true,
  782. returnValue: 'reasons'
  783. }),
  784. closeContact: promisify({
  785. name: 'closecontact',
  786. useCredentials: true,
  787. useAccessToken: true
  788. }),
  789. reschedule: promisify({
  790. name: 'reschedule',
  791. useCredentials: true,
  792. useAccessToken: true
  793. }),
  794. rescheduleContact: promisify({
  795. name: 'reschedulecall',
  796. useCredentials: true,
  797. useAccessToken: true
  798. }),
  799. getNotReadyCode: promisify({
  800. name: 'getNotReadyCode',
  801. useCredentials: true,
  802. useAccessToken: true
  803. }),
  804. makeContactCall: promisify({
  805. name: 'makecontactcall',
  806. useCredentials: true,
  807. useAccessToken: true
  808. }),
  809. requestOutboundACDCall: promisify({
  810. name: 'requestoutboundacdcall',
  811. useCredentials: true,
  812. useAccessToken: true
  813. }),
  814. campaignOpen: promisify({
  815. name: 'campaignopen',
  816. useCredentials: true,
  817. useAccessToken: true
  818. }),
  819. campaignClose: promisify({
  820. name: 'campaignclose',
  821. useCredentials: true,
  822. useAccessToken: true
  823. }),
  824. campaignSignOn: promisify({
  825. name: 'campaignsignon',
  826. useCredentials: true,
  827. useAccessToken: true
  828. }),
  829. campaignSignOff: promisify({
  830. name: 'campaignsignoff',
  831. useCredentials: true,
  832. useAccessToken: true
  833. }),
  834. campaignReady: promisify({
  835. name: 'campaignready',
  836. useCredentials: true,
  837. useAccessToken: true
  838. }),
  839. campaignNotReady: promisify({
  840. name: 'campaignnotready',
  841. useCredentials: true,
  842. useAccessToken: true
  843. }),
  844. // Finesse
  845. getReasonsCodes: promisify({
  846. name: 'getreasonscodes',
  847. useCredentials: true,
  848. useAccessToken: true,
  849. returnValue: 'codes'
  850. }),
  851. getWrapupReasons: promisify({
  852. name: 'getwrapupreasons',
  853. useCredentials: true,
  854. useAccessToken: true,
  855. returnValue: 'reasons'
  856. }),
  857. setWrapup: promisify({
  858. name: 'setwrapup',
  859. useCredentials: true,
  860. useAccessToken: true,
  861. returnValue: 'cid'
  862. }),
  863. getNotReadyReasons: promisify({
  864. name: 'getNotReadyCode',
  865. useCredentials: true,
  866. useAccessToken: true,
  867. returnValue: 'reasons'
  868. }),
  869. getRecordingSessionId: promisify({
  870. name: 'getrecordingsessionid',
  871. useCredentials: true,
  872. useAccessToken: true,
  873. returnValue: 'sessionid'
  874. })
  875. };
  876.  
  877. // Se expone las funciones públicas del módulo
  878. scope.thc = scope.thc || {};
  879. scope.thc.big = {
  880. init: init,
  881. start: start,
  882. update: updateAuth,
  883. stop: stop,
  884. addHook: addHook,
  885. removeHook: removeHook,
  886. rest: restDefinitions
  887. };
  888. })(window, document, window.jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement