Built motion from commit (unavailable).|2.0.76
[motion2.git] / server / services / ami / trigger / cmContact / index.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x6808=['util','lodash','../../../../config/logger','../../rpc/cmContact','localhost','info','stringify','emit','exec','autoCreate','data2','data1','calleridnum','calleridname','<unknown>','uniqueid','firstName','destcalleridname','destcalleridnum','resolve','showContact','user:%s','format','trigger:%s','action','toLowerCase','merge','createContact','then','xmd-contactid2','name','catch','Error\x20creating\x20contact','bluebird'];(function(_0x4c1ffb,_0x6839a8){var _0x360df6=function(_0x30d4eb){while(--_0x30d4eb){_0x4c1ffb['push'](_0x4c1ffb['shift']());}};_0x360df6(++_0x6839a8);}(_0x6808,0x197));var _0x8680=function(_0x50c12f,_0x28e72b){_0x50c12f=_0x50c12f-0x0;var _0x544cb6=_0x6808[_0x50c12f];return _0x544cb6;};'use strict';var BPromise=require(_0x8680('0x0'));var util=require(_0x8680('0x1'));var _=require(_0x8680('0x2'));var logger=require(_0x8680('0x3'))('trigger');var cmContactRpc=require(_0x8680('0x4'));var io=require('socket.io-emitter')({'host':_0x8680('0x5'),'port':0x18eb});function emit(_0x493c4d,_0x2d3e66,_0x13b22c){logger[_0x8680('0x6')](_0x493c4d,_0x2d3e66,JSON[_0x8680('0x7')](_0x13b22c));io['to'](_0x493c4d)[_0x8680('0x8')](_0x2d3e66,_0x13b22c);}exports[_0x8680('0x9')]=function(_0x2ee4d2,_0x3d4822,_0x97b33c){_0x97b33c[_0x8680('0xa')]=0x0;if(_0x3d4822[_0x8680('0xb')]&&parseInt(_0x3d4822[_0x8680('0xb')],0xa)){var _0x4d8420={'ListId':parseInt(_0x3d4822[_0x8680('0xc')],0xa),'phone':_0x97b33c[_0x8680('0xd')]};if(_['isNil'](_0x97b33c['routeId'])){_0x4d8420['firstName']=_0x97b33c['calleridname']&&_0x97b33c[_0x8680('0xe')]!==_0x8680('0xf')?_0x97b33c[_0x8680('0xe')]:_0x97b33c[_0x8680('0xd')]||_0x97b33c[_0x8680('0x10')];}else{_0x4d8420[_0x8680('0x11')]=_0x97b33c[_0x8680('0x12')]&&_0x97b33c[_0x8680('0x12')]!==_0x8680('0xf')?_0x97b33c[_0x8680('0x12')]:_0x97b33c[_0x8680('0x13')]||_0x97b33c['uniqueid'];_0x4d8420['phone']=_0x97b33c['destcalleridname']&&_0x97b33c[_0x8680('0x12')]!==_0x8680('0xf')?_0x97b33c[_0x8680('0x12')]:_0x97b33c['destcalleridnum']||_0x97b33c[_0x8680('0x10')];}BPromise[_0x8680('0x14')]()['then'](cmContactRpc[_0x8680('0x15')]({'where':_['omit'](_0x4d8420,['firstName'])}))['then'](function(_0x286a4f){if(_0x286a4f){_0x97b33c['xmd-contactid2']=_0x286a4f['id'];emit(util['format'](_0x8680('0x16'),_0x2ee4d2['name']),util[_0x8680('0x17')](_0x8680('0x18'),_0x3d4822[_0x8680('0x19')][_0x8680('0x1a')]()),_[_0x8680('0x1b')](_0x97b33c,{'ListId':parseInt(_0x3d4822[_0x8680('0xc')],0xa)}));return;}else{return BPromise[_0x8680('0x14')]()['then'](cmContactRpc[_0x8680('0x1c')](_0x4d8420));}})[_0x8680('0x1d')](function(_0x35efcc){if(_0x35efcc){_0x97b33c[_0x8680('0x1e')]=_0x35efcc['id'];emit(util[_0x8680('0x17')](_0x8680('0x16'),_0x2ee4d2[_0x8680('0x1f')]),util[_0x8680('0x17')](_0x8680('0x18'),_0x3d4822[_0x8680('0x19')][_0x8680('0x1a')]()),_['merge'](_0x97b33c,{'ListId':parseInt(_0x3d4822[_0x8680('0xc')],0xa)}));}})[_0x8680('0x20')](function(_0x194fb2){logger['error'](_0x8680('0x21'),JSON['stringify'](_0x194fb2));});}else{if(_0x2ee4d2){emit(util[_0x8680('0x17')]('user:%s',_0x2ee4d2[_0x8680('0x1f')]),util[_0x8680('0x17')]('trigger:%s',_0x3d4822[_0x8680('0x19')][_0x8680('0x1a')]()),_['merge']({'ListId':parseInt(_0x3d4822[_0x8680('0xc')],0xa)},_0x97b33c));}}};