f034435b464aa99b37b3844885cb4c99a521ba0a
[motion2.git] / server / api / openchannelMessage / openchannelMessage.model.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 _0x3d34=['FULLTEXT','models','get','direction','toLowerCase','out','isNil','UserId','OpenchannelInteraction','findOne','OpenchannelInteractionId','then','update','createdAt','catch','secret','CmContact','OpenchannelAccount','find','OpenchannelAccountId','Contact','replyUri','info','afterCreate','format','Interactions','length','Interaction','POST','method','GET','OpenchannelMessage,\x20%s,\x20%s','Message\x20%d\x20forwarded\x20to\x20%s','threadId','error','inspect','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','bluebird','request-promise','rimraf','../../config/environment','./openchannelMessage.attributes','exports','define','OpenchannelMessage','openchannel_messages','fti_openchannel_messages','body'];(function(_0x11da19,_0x5bebb9){var _0x25c772=function(_0x5a90d9){while(--_0x5a90d9){_0x11da19['push'](_0x11da19['shift']());}};_0x25c772(++_0x5bebb9);}(_0x3d34,0x93));var _0x43d3=function(_0x3a8d18,_0x34096f){_0x3a8d18=_0x3a8d18-0x0;var _0x13cb5d=_0x3d34[_0x3a8d18];return _0x13cb5d;};'use strict';var _=require(_0x43d3('0x0'));var util=require(_0x43d3('0x1'));var logger=require(_0x43d3('0x2'))(_0x43d3('0x3'));var moment=require('moment');var BPromise=require(_0x43d3('0x4'));var rp=require(_0x43d3('0x5'));var fs=require('fs');var path=require('path');var rimraf=require(_0x43d3('0x6'));var config=require(_0x43d3('0x7'));var attributes=require(_0x43d3('0x8'));module[_0x43d3('0x9')]=function(_0x3f63d5,_0x3661b9){return _0x3f63d5[_0x43d3('0xa')](_0x43d3('0xb'),attributes,{'tableName':_0x43d3('0xc'),'paranoid':![],'indexes':[{'name':_0x43d3('0xd'),'fields':[_0x43d3('0xe')],'type':_0x43d3('0xf')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x5216b9,_0x3b37bd,_0x24f0cb){var _0x3d45c2=_0x3f63d5[_0x43d3('0x10')];var _0x4f694b=_0x5216b9[_0x43d3('0x11')]({'plain':!![]});if(_0x4f694b[_0x43d3('0x12')][_0x43d3('0x13')]()==='in'||_0x4f694b['direction'][_0x43d3('0x13')]()===_0x43d3('0x14')&&!_0x4f694b['secret']&&!_[_0x43d3('0x15')](_0x4f694b[_0x43d3('0x16')])){_0x3d45c2[_0x43d3('0x17')][_0x43d3('0x18')]({'where':{'id':_0x4f694b[_0x43d3('0x19')]}})[_0x43d3('0x1a')](function(_0x2e22d2){if(_0x2e22d2){_0x2e22d2[_0x43d3('0x1b')]({'lastMsgAt':_0x4f694b[_0x43d3('0x1c')],'lastMsgDirection':_0x4f694b['direction'][_0x43d3('0x13')]()});}})[_0x43d3('0x1d')](function(_0x4a28e7){console['error'](_0x4a28e7);});}if(_0x4f694b['direction']===_0x43d3('0x14')&&!_0x4f694b[_0x43d3('0x1e')]){var _0x3a483b;_0x3d45c2[_0x43d3('0x1f')]['describe']()[_0x43d3('0x1a')](function(_0x120cf4){return _0x3d45c2[_0x43d3('0x20')][_0x43d3('0x21')]({'where':{'id':_0x4f694b[_0x43d3('0x22')]},'include':[{'model':_0x3d45c2[_0x43d3('0x17')],'as':'Interactions','where':{'id':_0x4f694b[_0x43d3('0x19')]},'limit':0x1,'include':[{'model':_0x3d45c2[_0x43d3('0x1f')],'as':_0x43d3('0x23'),'attributes':_['keys'](_0x120cf4)}]}]});})['then'](function(_0x539c7e){_0x3a483b=_0x539c7e[_0x43d3('0x11')]({'plain':!![]});if(_0x3a483b&&_0x3a483b[_0x43d3('0x24')]){logger[_0x43d3('0x25')]('OpenchannelMessage,\x20%s,\x20%s',_0x43d3('0x26'),util[_0x43d3('0x27')]('Forwarding\x20message\x20%d\x20to\x20%s',_0x4f694b['id'],_0x3a483b[_0x43d3('0x24')]));if(_0x3a483b[_0x43d3('0x28')]&&_0x3a483b['Interactions'][_0x43d3('0x29')]){_0x4f694b[_0x43d3('0x2a')]=_['omit'](_0x3a483b[_0x43d3('0x28')][0x0],'Contact');_0x4f694b[_0x43d3('0x23')]=_0x3a483b[_0x43d3('0x28')][0x0][_0x43d3('0x23')];}var _0x3b37bd={'method':_0x43d3('0x2b'),'uri':encodeURI(_0x3a483b[_0x43d3('0x24')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x3b37bd[_0x43d3('0x2c')]){case _0x43d3('0x2d'):_0x3b37bd['qs']=_0x4f694b;break;case _0x43d3('0x2b'):_0x3b37bd[_0x43d3('0xe')]=_0x4f694b;break;}return rp(_0x3b37bd)[_0x43d3('0x1a')](function(_0x27ff74){logger['info'](_0x43d3('0x2e'),_0x43d3('0x26'),util[_0x43d3('0x27')](_0x43d3('0x2f'),_0x4f694b['id'],_0x3a483b[_0x43d3('0x24')]));if(_0x27ff74[_0x43d3('0xe')]['threadId']&&_0x27ff74[_0x43d3('0xe')][_0x43d3('0x30')]!=_0x4f694b[_0x43d3('0x2a')][_0x43d3('0x30')]){return _0x3d45c2['OpenchannelInteraction'][_0x43d3('0x1b')]({'threadId':_0x27ff74['body'][_0x43d3('0x30')]},{'where':{'id':_0x4f694b['Interaction']['id']}});}else{return;}})[_0x43d3('0x1a')](function(){return _0x5216b9[_0x43d3('0x1b')]({'read':!![]});})[_0x43d3('0x1d')](function(_0x14ed5b){logger[_0x43d3('0x31')](_0x43d3('0x2e'),_0x43d3('0x26'),util[_0x43d3('0x32')](_0x14ed5b,{'showHidden':![],'depth':null}));_0x24f0cb();});}else{_0x24f0cb();}})[_0x43d3('0x33')](function(){_0x24f0cb();});}else{_0x24f0cb();}}},'charset':_0x43d3('0x34'),'collate':_0x43d3('0x35')});};