Built motion from commit (unavailable).|2.4.20
[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 _0x3af5=['routeId','firstName','calleridname','<unknown>','uniqueid','destcalleridname','destcalleridnum','phone','resolve','then','omit','user:%s','name','format','action','toLowerCase','merge','createContact','xmd-contactid2','trigger:%s','catch','error','Error\x20creating\x20contact','bluebird','util','ioredis','../../../../config/environment','../../rpc/cmContact','redis','localhost','info','stringify','emit','exec','data2','data1','calleridnum'];(function(_0x221ade,_0x3d9927){var _0x5c513c=function(_0x1d1458){while(--_0x1d1458){_0x221ade['push'](_0x221ade['shift']());}};_0x5c513c(++_0x3d9927);}(_0x3af5,0x1d3));var _0x53af=function(_0x4f67a2,_0x273325){_0x4f67a2=_0x4f67a2-0x0;var _0x42beb3=_0x3af5[_0x4f67a2];return _0x42beb3;};'use strict';var BPromise=require(_0x53af('0x0'));var util=require(_0x53af('0x1'));var _=require('lodash');var Redis=require(_0x53af('0x2'));var config=require(_0x53af('0x3'));var logger=require('../../../../config/logger')('trigger');var cmContactRpc=require(_0x53af('0x4'));config['redis']=_['defaults'](config[_0x53af('0x5')],{'host':_0x53af('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x53af('0x5')]));function emit(_0x4eb461,_0x3aefaf,_0x27eed3){logger[_0x53af('0x7')](_0x4eb461,_0x3aefaf,JSON[_0x53af('0x8')](_0x27eed3));io['to'](_0x4eb461)[_0x53af('0x9')](_0x3aefaf,_0x27eed3);}exports[_0x53af('0xa')]=function(_0x56751b,_0x52b4d1,_0x10ee70){_0x10ee70['autoCreate']=0x0;if(_0x52b4d1[_0x53af('0xb')]&&parseInt(_0x52b4d1[_0x53af('0xb')],0xa)){var _0x56c2ed={'ListId':parseInt(_0x52b4d1[_0x53af('0xc')],0xa),'phone':_0x10ee70[_0x53af('0xd')]};if(_['isNil'](_0x10ee70[_0x53af('0xe')])){_0x56c2ed[_0x53af('0xf')]=_0x10ee70[_0x53af('0x10')]&&_0x10ee70['calleridname']!==_0x53af('0x11')?_0x10ee70['calleridname']:_0x10ee70[_0x53af('0xd')]||_0x10ee70[_0x53af('0x12')];}else{_0x56c2ed[_0x53af('0xf')]=_0x10ee70[_0x53af('0x13')]&&_0x10ee70[_0x53af('0x13')]!==_0x53af('0x11')?_0x10ee70[_0x53af('0x13')]:_0x10ee70[_0x53af('0x14')]||_0x10ee70[_0x53af('0x12')];_0x56c2ed[_0x53af('0x15')]=_0x10ee70['destcalleridname']&&_0x10ee70[_0x53af('0x13')]!==_0x53af('0x11')?_0x10ee70[_0x53af('0x13')]:_0x10ee70[_0x53af('0x14')]||_0x10ee70[_0x53af('0x12')];}BPromise[_0x53af('0x16')]()[_0x53af('0x17')](cmContactRpc['showContact']({'where':_[_0x53af('0x18')](_0x56c2ed,[_0x53af('0xf')])}))[_0x53af('0x17')](function(_0x8771d1){if(_0x8771d1){_0x10ee70['xmd-contactid2']=_0x8771d1['id'];emit(util['format'](_0x53af('0x19'),_0x56751b[_0x53af('0x1a')]),util[_0x53af('0x1b')]('trigger:%s',_0x52b4d1[_0x53af('0x1c')][_0x53af('0x1d')]()),_[_0x53af('0x1e')](_0x10ee70,{'ListId':parseInt(_0x52b4d1[_0x53af('0xc')],0xa)}));return;}else{return BPromise[_0x53af('0x16')]()[_0x53af('0x17')](cmContactRpc[_0x53af('0x1f')](_0x56c2ed));}})[_0x53af('0x17')](function(_0x5c2763){if(_0x5c2763){_0x10ee70[_0x53af('0x20')]=_0x5c2763['id'];emit(util[_0x53af('0x1b')](_0x53af('0x19'),_0x56751b[_0x53af('0x1a')]),util[_0x53af('0x1b')](_0x53af('0x21'),_0x52b4d1['action'][_0x53af('0x1d')]()),_[_0x53af('0x1e')](_0x10ee70,{'ListId':parseInt(_0x52b4d1[_0x53af('0xc')],0xa)}));}})[_0x53af('0x22')](function(_0x480665){logger[_0x53af('0x23')](_0x53af('0x24'),JSON[_0x53af('0x8')](_0x480665));});}else{if(_0x56751b){emit(util[_0x53af('0x1b')](_0x53af('0x19'),_0x56751b[_0x53af('0x1a')]),util[_0x53af('0x1b')](_0x53af('0x21'),_0x52b4d1['action'][_0x53af('0x1d')]()),_[_0x53af('0x1e')]({'ListId':parseInt(_0x52b4d1[_0x53af('0xc')],0xa)},_0x10ee70));}}};