Built motion from commit (unavailable).|2.5.4
[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 _0x9feb=['<unknown>','uniqueid','destcalleridname','phone','destcalleridnum','resolve','then','showContact','xmd-contactid2','format','user:%s','name','trigger:%s','action','toLowerCase','merge','[%s][%s]\x20Contact\x20not\x20found','createContact','[%s][%s]\x20Contact\x20created:%s','catch','error','[%s][%s]\x20Error\x20creating\x20contact','bluebird','util','ioredis','../../../../config/environment','../../../../config/logger','../../rpc/cmContact','redis','defaults','localhost','socket.io-emitter','info','[%s][%s]','emit','exec','autoCreate','data2','data1','calleridnum','isNil','routeId','firstName','calleridname'];(function(_0x5bef89,_0x7c41b4){var _0x1c34dd=function(_0x3df243){while(--_0x3df243){_0x5bef89['push'](_0x5bef89['shift']());}};_0x1c34dd(++_0x7c41b4);}(_0x9feb,0x6e));var _0xb9fe=function(_0x49626c,_0x25d3d0){_0x49626c=_0x49626c-0x0;var _0x1979b6=_0x9feb[_0x49626c];return _0x1979b6;};'use strict';var BPromise=require(_0xb9fe('0x0'));var util=require(_0xb9fe('0x1'));var _=require('lodash');var Redis=require(_0xb9fe('0x2'));var config=require(_0xb9fe('0x3'));var logger=require(_0xb9fe('0x4'))('trigger');var cmContactRpc=require(_0xb9fe('0x5'));config[_0xb9fe('0x6')]=_[_0xb9fe('0x7')](config['redis'],{'host':_0xb9fe('0x8'),'port':0x18eb});var io=require(_0xb9fe('0x9'))(new Redis(config[_0xb9fe('0x6')]));function emit(_0x1dc302,_0x12e664,_0xdcb7bb,_0x580934){logger[_0xb9fe('0xa')](_0xb9fe('0xb'),_0x1dc302,'',_0x12e664,_0xdcb7bb,JSON['stringify'](_0x580934));io['to'](_0x12e664)[_0xb9fe('0xc')](_0xdcb7bb,_0x580934);}exports[_0xb9fe('0xd')]=function(_0x184ab,_0x5e3d5f,_0x2f9b5d){_0x2f9b5d[_0xb9fe('0xe')]=0x0;if(_0x5e3d5f[_0xb9fe('0xf')]&&parseInt(_0x5e3d5f[_0xb9fe('0xf')],0xa)){var _0x2acba4={'ListId':parseInt(_0x5e3d5f[_0xb9fe('0x10')],0xa),'phone':_0x2f9b5d[_0xb9fe('0x11')]};if(_[_0xb9fe('0x12')](_0x2f9b5d[_0xb9fe('0x13')])){_0x2acba4[_0xb9fe('0x14')]=_0x2f9b5d[_0xb9fe('0x15')]&&_0x2f9b5d[_0xb9fe('0x15')]!==_0xb9fe('0x16')?_0x2f9b5d[_0xb9fe('0x15')]:_0x2f9b5d['calleridnum']||_0x2f9b5d[_0xb9fe('0x17')];}else{_0x2acba4[_0xb9fe('0x14')]=_0x2f9b5d[_0xb9fe('0x18')]&&_0x2f9b5d[_0xb9fe('0x18')]!==_0xb9fe('0x16')?_0x2f9b5d['destcalleridname']:_0x2f9b5d['destcalleridnum']||_0x2f9b5d[_0xb9fe('0x17')];_0x2acba4[_0xb9fe('0x19')]=_0x2f9b5d[_0xb9fe('0x18')]&&_0x2f9b5d[_0xb9fe('0x18')]!==_0xb9fe('0x16')?_0x2f9b5d[_0xb9fe('0x18')]:_0x2f9b5d[_0xb9fe('0x1a')]||_0x2f9b5d[_0xb9fe('0x17')];}BPromise[_0xb9fe('0x1b')]()[_0xb9fe('0x1c')](cmContactRpc[_0xb9fe('0x1d')]({'where':_['omit'](_0x2acba4,[_0xb9fe('0x14')])}))[_0xb9fe('0x1c')](function(_0x37e135){if(_0x37e135){logger[_0xb9fe('0xa')]('[%s][%s]\x20Contact\x20found:%s',_0x2f9b5d['uniqueid'],'',_0x37e135['id']);if(_0x184ab){_0x2f9b5d[_0xb9fe('0x1e')]=_0x37e135['id'];emit(_0x2f9b5d[_0xb9fe('0x17')],util[_0xb9fe('0x1f')](_0xb9fe('0x20'),_0x184ab[_0xb9fe('0x21')]),util['format'](_0xb9fe('0x22'),_0x5e3d5f[_0xb9fe('0x23')][_0xb9fe('0x24')]()),_[_0xb9fe('0x25')](_0x2f9b5d,{'ListId':parseInt(_0x5e3d5f['data1'],0xa)}));}return;}else{logger[_0xb9fe('0xa')](_0xb9fe('0x26'),_0x2f9b5d[_0xb9fe('0x17')],'');return BPromise[_0xb9fe('0x1b')]()[_0xb9fe('0x1c')](cmContactRpc[_0xb9fe('0x27')](_0x2acba4));}})[_0xb9fe('0x1c')](function(_0x58e796){if(_0x58e796){logger['info'](_0xb9fe('0x28'),_0x2f9b5d['uniqueid'],'',_0x58e796['id']);if(_0x184ab){_0x2f9b5d['xmd-contactid2']=_0x58e796['id'];emit(_0x2f9b5d[_0xb9fe('0x17')],util['format'](_0xb9fe('0x20'),_0x184ab[_0xb9fe('0x21')]),util[_0xb9fe('0x1f')]('trigger:%s',_0x5e3d5f[_0xb9fe('0x23')][_0xb9fe('0x24')]()),_[_0xb9fe('0x25')](_0x2f9b5d,{'ListId':parseInt(_0x5e3d5f[_0xb9fe('0x10')],0xa)}));}}})[_0xb9fe('0x29')](function(_0x185ec4){logger[_0xb9fe('0x2a')](_0xb9fe('0x2b'),_0x2f9b5d[_0xb9fe('0x17')],'',JSON['stringify'](_0x185ec4));});}else{if(_0x184ab){logger[_0xb9fe('0xa')]('[%s][%s]\x20Autocreate\x20disabled',_0x2f9b5d[_0xb9fe('0x17')],'');emit(_0x2f9b5d[_0xb9fe('0x17')],util[_0xb9fe('0x1f')](_0xb9fe('0x20'),_0x184ab['name']),util[_0xb9fe('0x1f')]('trigger:%s',_0x5e3d5f['action']['toLowerCase']()),_[_0xb9fe('0x25')]({'ListId':parseInt(_0x5e3d5f['data1'],0xa)},_0x2f9b5d));}}};