Built motion from commit (unavailable).|2.4.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 _0x722a=['toLowerCase','merge','createContact','user:%s','catch','error','Error\x20creating\x20contact','util','lodash','../../../../config/logger','trigger','../../rpc/cmContact','redis','defaults','localhost','socket.io-emitter','info','stringify','emit','exec','autoCreate','data1','calleridnum','isNil','routeId','firstName','calleridname','<unknown>','uniqueid','destcalleridname','destcalleridnum','phone','resolve','then','showContact','omit','xmd-contactid2','format','name','trigger:%s','action'];(function(_0x50367a,_0x4d4853){var _0x7eee81=function(_0x1f4bc4){while(--_0x1f4bc4){_0x50367a['push'](_0x50367a['shift']());}};_0x7eee81(++_0x4d4853);}(_0x722a,0xd4));var _0xa722=function(_0x104861,_0x368f40){_0x104861=_0x104861-0x0;var _0x2b86b7=_0x722a[_0x104861];return _0x2b86b7;};'use strict';var BPromise=require('bluebird');var util=require(_0xa722('0x0'));var _=require(_0xa722('0x1'));var Redis=require('ioredis');var config=require('../../../../config/environment');var logger=require(_0xa722('0x2'))(_0xa722('0x3'));var cmContactRpc=require(_0xa722('0x4'));config[_0xa722('0x5')]=_[_0xa722('0x6')](config[_0xa722('0x5')],{'host':_0xa722('0x7'),'port':0x18eb});var io=require(_0xa722('0x8'))(new Redis(config[_0xa722('0x5')]));function emit(_0x2a4e6b,_0x7a92e4,_0x100120){logger[_0xa722('0x9')](_0x2a4e6b,_0x7a92e4,JSON[_0xa722('0xa')](_0x100120));io['to'](_0x2a4e6b)[_0xa722('0xb')](_0x7a92e4,_0x100120);}exports[_0xa722('0xc')]=function(_0x400ecc,_0x1db430,_0x2617cc){_0x2617cc[_0xa722('0xd')]=0x0;if(_0x1db430['data2']&&parseInt(_0x1db430['data2'],0xa)){var _0xe1bcd4={'ListId':parseInt(_0x1db430[_0xa722('0xe')],0xa),'phone':_0x2617cc[_0xa722('0xf')]};if(_[_0xa722('0x10')](_0x2617cc[_0xa722('0x11')])){_0xe1bcd4[_0xa722('0x12')]=_0x2617cc[_0xa722('0x13')]&&_0x2617cc[_0xa722('0x13')]!==_0xa722('0x14')?_0x2617cc[_0xa722('0x13')]:_0x2617cc[_0xa722('0xf')]||_0x2617cc[_0xa722('0x15')];}else{_0xe1bcd4['firstName']=_0x2617cc[_0xa722('0x16')]&&_0x2617cc['destcalleridname']!==_0xa722('0x14')?_0x2617cc[_0xa722('0x16')]:_0x2617cc[_0xa722('0x17')]||_0x2617cc['uniqueid'];_0xe1bcd4[_0xa722('0x18')]=_0x2617cc[_0xa722('0x16')]&&_0x2617cc[_0xa722('0x16')]!==_0xa722('0x14')?_0x2617cc[_0xa722('0x16')]:_0x2617cc[_0xa722('0x17')]||_0x2617cc[_0xa722('0x15')];}BPromise[_0xa722('0x19')]()[_0xa722('0x1a')](cmContactRpc[_0xa722('0x1b')]({'where':_[_0xa722('0x1c')](_0xe1bcd4,[_0xa722('0x12')])}))[_0xa722('0x1a')](function(_0x4eece1){if(_0x4eece1){_0x2617cc[_0xa722('0x1d')]=_0x4eece1['id'];emit(util[_0xa722('0x1e')]('user:%s',_0x400ecc[_0xa722('0x1f')]),util[_0xa722('0x1e')](_0xa722('0x20'),_0x1db430[_0xa722('0x21')][_0xa722('0x22')]()),_[_0xa722('0x23')](_0x2617cc,{'ListId':parseInt(_0x1db430[_0xa722('0xe')],0xa)}));return;}else{return BPromise[_0xa722('0x19')]()[_0xa722('0x1a')](cmContactRpc[_0xa722('0x24')](_0xe1bcd4));}})['then'](function(_0x3be491){if(_0x3be491){_0x2617cc[_0xa722('0x1d')]=_0x3be491['id'];emit(util['format'](_0xa722('0x25'),_0x400ecc[_0xa722('0x1f')]),util[_0xa722('0x1e')](_0xa722('0x20'),_0x1db430['action'][_0xa722('0x22')]()),_['merge'](_0x2617cc,{'ListId':parseInt(_0x1db430[_0xa722('0xe')],0xa)}));}})[_0xa722('0x26')](function(_0x117098){logger[_0xa722('0x27')](_0xa722('0x28'),JSON[_0xa722('0xa')](_0x117098));});}else{if(_0x400ecc){emit(util['format'](_0xa722('0x25'),_0x400ecc[_0xa722('0x1f')]),util['format'](_0xa722('0x20'),_0x1db430['action'][_0xa722('0x22')]()),_['merge']({'ListId':parseInt(_0x1db430['data1'],0xa)},_0x2617cc));}}};