Built motion from commit (unavailable).|2.5.9
[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 _0x509c=['get','direction','toLowerCase','secret','OpenchannelInteractionId','then','update','createdAt','catch','error','out','CmContact','describe','OpenchannelAccount','find','OpenchannelAccountId','OpenchannelInteraction','Contact','keys','replyUri','info','OpenchannelMessage,\x20%s,\x20%s','afterCreate','Forwarding\x20message\x20%d\x20to\x20%s','Interactions','length','Interaction','omit','POST','method','GET','format','Message\x20%d\x20forwarded\x20to\x20%s','threadId','inspect','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','request-promise','../../config/environment','./openchannelMessage.attributes','define','OpenchannelMessage','openchannel_messages','body','FULLTEXT','models'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x509c,0x15e));var _0xc509=function(_0x309b29,_0x2a1a61){_0x309b29=_0x309b29-0x0;var _0x599890=_0x509c[_0x309b29];return _0x599890;};'use strict';var _=require(_0xc509('0x0'));var util=require(_0xc509('0x1'));var logger=require(_0xc509('0x2'))(_0xc509('0x3'));var moment=require(_0xc509('0x4'));var BPromise=require('bluebird');var rp=require(_0xc509('0x5'));var fs=require('fs');var path=require('path');var rimraf=require('rimraf');var config=require(_0xc509('0x6'));var attributes=require(_0xc509('0x7'));module['exports']=function(_0x442f35,_0x870232){return _0x442f35[_0xc509('0x8')](_0xc509('0x9'),attributes,{'tableName':_0xc509('0xa'),'paranoid':![],'indexes':[{'name':'fti_openchannel_messages','fields':[_0xc509('0xb')],'type':_0xc509('0xc')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x36debf,_0x11bd13,_0x1fdbad){var _0x44ecac=_0x442f35[_0xc509('0xd')];var _0x3bfca1=_0x36debf[_0xc509('0xe')]({'plain':!![]});if(_0x3bfca1[_0xc509('0xf')][_0xc509('0x10')]()==='in'||_0x3bfca1['direction'][_0xc509('0x10')]()==='out'&&!_0x3bfca1[_0xc509('0x11')]&&!_['isNil'](_0x3bfca1['UserId'])){_0x44ecac['OpenchannelInteraction']['findOne']({'where':{'id':_0x3bfca1[_0xc509('0x12')]}})[_0xc509('0x13')](function(_0x3b7ed6){if(_0x3b7ed6){_0x3b7ed6[_0xc509('0x14')]({'lastMsgAt':_0x3bfca1[_0xc509('0x15')],'lastMsgDirection':_0x3bfca1['direction'][_0xc509('0x10')]()});}})[_0xc509('0x16')](function(_0x2b38a7){console[_0xc509('0x17')](_0x2b38a7);});}if(_0x3bfca1[_0xc509('0xf')]===_0xc509('0x18')&&!_0x3bfca1[_0xc509('0x11')]){var _0x528bcf;_0x44ecac[_0xc509('0x19')][_0xc509('0x1a')]()[_0xc509('0x13')](function(_0x2a3632){return _0x44ecac[_0xc509('0x1b')][_0xc509('0x1c')]({'where':{'id':_0x3bfca1[_0xc509('0x1d')]},'include':[{'model':_0x44ecac[_0xc509('0x1e')],'as':'Interactions','where':{'id':_0x3bfca1[_0xc509('0x12')]},'limit':0x1,'include':[{'model':_0x44ecac[_0xc509('0x19')],'as':_0xc509('0x1f'),'attributes':_[_0xc509('0x20')](_0x2a3632)}]}]});})['then'](function(_0x5acd7f){_0x528bcf=_0x5acd7f[_0xc509('0xe')]({'plain':!![]});if(_0x528bcf&&_0x528bcf[_0xc509('0x21')]){logger[_0xc509('0x22')](_0xc509('0x23'),_0xc509('0x24'),util['format'](_0xc509('0x25'),_0x3bfca1['id'],_0x528bcf['replyUri']));if(_0x528bcf[_0xc509('0x26')]&&_0x528bcf[_0xc509('0x26')][_0xc509('0x27')]){_0x3bfca1[_0xc509('0x28')]=_[_0xc509('0x29')](_0x528bcf[_0xc509('0x26')][0x0],'Contact');_0x3bfca1[_0xc509('0x1f')]=_0x528bcf[_0xc509('0x26')][0x0][_0xc509('0x1f')];}var _0x11bd13={'method':_0xc509('0x2a'),'uri':encodeURI(_0x528bcf['replyUri']),'json':!![],'resolveWithFullResponse':!![]};switch(_0x11bd13[_0xc509('0x2b')]){case _0xc509('0x2c'):_0x11bd13['qs']=_0x3bfca1;break;case _0xc509('0x2a'):_0x11bd13[_0xc509('0xb')]=_0x3bfca1;break;}return rp(_0x11bd13)[_0xc509('0x13')](function(_0x59c95d){logger[_0xc509('0x22')](_0xc509('0x23'),'afterCreate',util[_0xc509('0x2d')](_0xc509('0x2e'),_0x3bfca1['id'],_0x528bcf[_0xc509('0x21')]));if(_0x59c95d[_0xc509('0xb')][_0xc509('0x2f')]&&_0x59c95d[_0xc509('0xb')][_0xc509('0x2f')]!=_0x3bfca1[_0xc509('0x28')]['threadId']){return _0x44ecac[_0xc509('0x1e')]['update']({'threadId':_0x59c95d[_0xc509('0xb')]['threadId']},{'logging':!![],'where':{'id':_0x3bfca1['Interaction']['id']}});}else{return;}})['then'](function(){return _0x36debf[_0xc509('0x14')]({'read':!![]});})[_0xc509('0x16')](function(_0x1bf194){logger[_0xc509('0x17')](_0xc509('0x23'),_0xc509('0x24'),util[_0xc509('0x30')](_0x1bf194,{'showHidden':![],'depth':null}));_0x1fdbad();});}else{_0x1fdbad();}})[_0xc509('0x31')](function(){_0x1fdbad();});}else{_0x1fdbad();}}},'charset':_0xc509('0x32'),'collate':_0xc509('0x33')});};