Built motion from commit (unavailable).|2.5.0
[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 _0x4991=['catch','Error\x20creating\x20contact','bluebird','lodash','../../../../config/environment','../../../../config/logger','trigger','../../rpc/cmContact','redis','defaults','localhost','info','stringify','emit','exec','data2','data1','calleridnum','calleridname','<unknown>','destcalleridname','destcalleridnum','uniqueid','resolve','then','showContact','xmd-contactid2','user:%s','name','format','trigger:%s','action','toLowerCase','merge','createContact'];(function(_0x31ca4c,_0x38802c){var _0x423753=function(_0x55988e){while(--_0x55988e){_0x31ca4c['push'](_0x31ca4c['shift']());}};_0x423753(++_0x38802c);}(_0x4991,0xf7));var _0x1499=function(_0x402a24,_0x4f9866){_0x402a24=_0x402a24-0x0;var _0x285fcd=_0x4991[_0x402a24];return _0x285fcd;};'use strict';var BPromise=require(_0x1499('0x0'));var util=require('util');var _=require(_0x1499('0x1'));var Redis=require('ioredis');var config=require(_0x1499('0x2'));var logger=require(_0x1499('0x3'))(_0x1499('0x4'));var cmContactRpc=require(_0x1499('0x5'));config[_0x1499('0x6')]=_[_0x1499('0x7')](config[_0x1499('0x6')],{'host':_0x1499('0x8'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x1499('0x6')]));function emit(_0x1c3bd7,_0x1c65c3,_0x33b261){logger[_0x1499('0x9')](_0x1c3bd7,_0x1c65c3,JSON[_0x1499('0xa')](_0x33b261));io['to'](_0x1c3bd7)[_0x1499('0xb')](_0x1c65c3,_0x33b261);}exports[_0x1499('0xc')]=function(_0x48d2ca,_0x16e8ad,_0x36a053){_0x36a053['autoCreate']=0x0;if(_0x16e8ad[_0x1499('0xd')]&&parseInt(_0x16e8ad[_0x1499('0xd')],0xa)){var _0x4c2bd2={'ListId':parseInt(_0x16e8ad[_0x1499('0xe')],0xa),'phone':_0x36a053[_0x1499('0xf')]};if(_['isNil'](_0x36a053['routeId'])){_0x4c2bd2['firstName']=_0x36a053[_0x1499('0x10')]&&_0x36a053[_0x1499('0x10')]!==_0x1499('0x11')?_0x36a053[_0x1499('0x10')]:_0x36a053[_0x1499('0xf')]||_0x36a053['uniqueid'];}else{_0x4c2bd2['firstName']=_0x36a053[_0x1499('0x12')]&&_0x36a053['destcalleridname']!==_0x1499('0x11')?_0x36a053[_0x1499('0x12')]:_0x36a053[_0x1499('0x13')]||_0x36a053[_0x1499('0x14')];_0x4c2bd2['phone']=_0x36a053[_0x1499('0x12')]&&_0x36a053[_0x1499('0x12')]!=='<unknown>'?_0x36a053[_0x1499('0x12')]:_0x36a053[_0x1499('0x13')]||_0x36a053[_0x1499('0x14')];}BPromise[_0x1499('0x15')]()[_0x1499('0x16')](cmContactRpc[_0x1499('0x17')]({'where':_['omit'](_0x4c2bd2,['firstName'])}))['then'](function(_0x2172b3){if(_0x2172b3){_0x36a053[_0x1499('0x18')]=_0x2172b3['id'];emit(util['format'](_0x1499('0x19'),_0x48d2ca[_0x1499('0x1a')]),util[_0x1499('0x1b')](_0x1499('0x1c'),_0x16e8ad[_0x1499('0x1d')][_0x1499('0x1e')]()),_[_0x1499('0x1f')](_0x36a053,{'ListId':parseInt(_0x16e8ad[_0x1499('0xe')],0xa)}));return;}else{return BPromise[_0x1499('0x15')]()[_0x1499('0x16')](cmContactRpc[_0x1499('0x20')](_0x4c2bd2));}})[_0x1499('0x16')](function(_0x223f4c){if(_0x223f4c){_0x36a053[_0x1499('0x18')]=_0x223f4c['id'];emit(util[_0x1499('0x1b')](_0x1499('0x19'),_0x48d2ca[_0x1499('0x1a')]),util['format'](_0x1499('0x1c'),_0x16e8ad[_0x1499('0x1d')][_0x1499('0x1e')]()),_[_0x1499('0x1f')](_0x36a053,{'ListId':parseInt(_0x16e8ad[_0x1499('0xe')],0xa)}));}})[_0x1499('0x21')](function(_0x54f3c2){logger['error'](_0x1499('0x22'),JSON[_0x1499('0xa')](_0x54f3c2));});}else{if(_0x48d2ca){emit(util[_0x1499('0x1b')](_0x1499('0x19'),_0x48d2ca[_0x1499('0x1a')]),util['format'](_0x1499('0x1c'),_0x16e8ad['action']['toLowerCase']()),_['merge']({'ListId':parseInt(_0x16e8ad[_0x1499('0xe')],0xa)},_0x36a053));}}};