Built motion from commit (unavailable).|2.5.0
[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 _0x6f51=['get','direction','toLowerCase','out','secret','isNil','UserId','OpenchannelInteraction','findOne','then','update','createdAt','error','CmContact','OpenchannelAccount','OpenchannelAccountId','Interactions','OpenchannelInteractionId','replyUri','info','OpenchannelMessage,\x20%s,\x20%s','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','Interaction','Contact','POST','method','Message\x20%d\x20forwarded\x20to\x20%s','threadId','inspect','finally','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','bluebird','path','rimraf','../../config/environment','./openchannelMessage.attributes','exports','define','OpenchannelMessage','fti_openchannel_messages','body','FULLTEXT','models'];(function(_0xb564e9,_0x1252fc){var _0x3c4ed4=function(_0x435e8b){while(--_0x435e8b){_0xb564e9['push'](_0xb564e9['shift']());}};_0x3c4ed4(++_0x1252fc);}(_0x6f51,0x86));var _0x16f5=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x6f51[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0x16f5('0x0'));var util=require('util');var logger=require(_0x16f5('0x1'))(_0x16f5('0x2'));var moment=require(_0x16f5('0x3'));var BPromise=require(_0x16f5('0x4'));var rp=require('request-promise');var fs=require('fs');var path=require(_0x16f5('0x5'));var rimraf=require(_0x16f5('0x6'));var config=require(_0x16f5('0x7'));var attributes=require(_0x16f5('0x8'));module[_0x16f5('0x9')]=function(_0x3bbfab,_0x65e71b){return _0x3bbfab[_0x16f5('0xa')](_0x16f5('0xb'),attributes,{'tableName':'openchannel_messages','paranoid':![],'indexes':[{'name':_0x16f5('0xc'),'fields':[_0x16f5('0xd')],'type':_0x16f5('0xe')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x26e21e,_0x4d4b23,_0x3ad3fc){var _0x3dd32b=_0x3bbfab[_0x16f5('0xf')];var _0x10f4f5=_0x26e21e[_0x16f5('0x10')]({'plain':!![]});if(_0x10f4f5[_0x16f5('0x11')]['toLowerCase']()==='in'||_0x10f4f5['direction'][_0x16f5('0x12')]()===_0x16f5('0x13')&&!_0x10f4f5[_0x16f5('0x14')]&&!_[_0x16f5('0x15')](_0x10f4f5[_0x16f5('0x16')])){_0x3dd32b[_0x16f5('0x17')][_0x16f5('0x18')]({'where':{'id':_0x10f4f5['OpenchannelInteractionId']}})[_0x16f5('0x19')](function(_0x576349){if(_0x576349){_0x576349[_0x16f5('0x1a')]({'lastMsgAt':_0x10f4f5[_0x16f5('0x1b')],'lastMsgDirection':_0x10f4f5[_0x16f5('0x11')][_0x16f5('0x12')]()});}})['catch'](function(_0x4ed79a){console[_0x16f5('0x1c')](_0x4ed79a);});}if(_0x10f4f5['direction']===_0x16f5('0x13')&&!_0x10f4f5[_0x16f5('0x14')]){var _0x4b05e5;_0x3dd32b[_0x16f5('0x1d')]['describe']()[_0x16f5('0x19')](function(_0x1c331d){return _0x3dd32b[_0x16f5('0x1e')]['find']({'where':{'id':_0x10f4f5[_0x16f5('0x1f')]},'include':[{'model':_0x3dd32b['OpenchannelInteraction'],'as':_0x16f5('0x20'),'where':{'id':_0x10f4f5[_0x16f5('0x21')]},'limit':0x1,'include':[{'model':_0x3dd32b[_0x16f5('0x1d')],'as':'Contact','attributes':_['keys'](_0x1c331d)}]}]});})[_0x16f5('0x19')](function(_0x1075d9){_0x4b05e5=_0x1075d9[_0x16f5('0x10')]({'plain':!![]});if(_0x4b05e5&&_0x4b05e5[_0x16f5('0x22')]){logger[_0x16f5('0x23')](_0x16f5('0x24'),_0x16f5('0x25'),util[_0x16f5('0x26')](_0x16f5('0x27'),_0x10f4f5['id'],_0x4b05e5[_0x16f5('0x22')]));if(_0x4b05e5[_0x16f5('0x20')]&&_0x4b05e5[_0x16f5('0x20')]['length']){_0x10f4f5[_0x16f5('0x28')]=_['omit'](_0x4b05e5[_0x16f5('0x20')][0x0],_0x16f5('0x29'));_0x10f4f5[_0x16f5('0x29')]=_0x4b05e5[_0x16f5('0x20')][0x0][_0x16f5('0x29')];}var _0x4d4b23={'method':_0x16f5('0x2a'),'uri':encodeURI(_0x4b05e5[_0x16f5('0x22')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x4d4b23[_0x16f5('0x2b')]){case'GET':_0x4d4b23['qs']=_0x10f4f5;break;case'POST':_0x4d4b23[_0x16f5('0xd')]=_0x10f4f5;break;}return rp(_0x4d4b23)[_0x16f5('0x19')](function(_0x41e2b3){logger[_0x16f5('0x23')](_0x16f5('0x24'),_0x16f5('0x25'),util[_0x16f5('0x26')](_0x16f5('0x2c'),_0x10f4f5['id'],_0x4b05e5[_0x16f5('0x22')]));if(_0x41e2b3['body'][_0x16f5('0x2d')]&&_0x41e2b3[_0x16f5('0xd')][_0x16f5('0x2d')]!=_0x10f4f5[_0x16f5('0x28')][_0x16f5('0x2d')]){return _0x3dd32b['OpenchannelInteraction'][_0x16f5('0x1a')]({'threadId':_0x41e2b3[_0x16f5('0xd')][_0x16f5('0x2d')]},{'logging':!![],'where':{'id':_0x10f4f5[_0x16f5('0x28')]['id']}});}else{return;}})[_0x16f5('0x19')](function(){return _0x26e21e[_0x16f5('0x1a')]({'read':!![]});})['catch'](function(_0x122c1b){logger[_0x16f5('0x1c')](_0x16f5('0x24'),_0x16f5('0x25'),util[_0x16f5('0x2e')](_0x122c1b,{'showHidden':![],'depth':null}));_0x3ad3fc();});}else{_0x3ad3fc();}})[_0x16f5('0x2f')](function(){_0x3ad3fc();});}else{_0x3ad3fc();}}},'charset':_0x16f5('0x30'),'collate':_0x16f5('0x31')});};