Built motion from commit c116dc8b.|2.6.30
[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 _0xce0d=['finally','utf8mb4','utf8mb4_unicode_ci','lodash','api','moment','bluebird','request-promise','path','rimraf','../../config/environment','./openchannelMessage.attributes','exports','define','OpenchannelMessage','openchannel_messages','fti_openchannel_messages','body','FULLTEXT','get','toLowerCase','direction','out','secret','isNil','UserId','OpenchannelInteraction','findOne','OpenchannelInteractionId','update','CmContact','then','find','OpenchannelAccountId','Interactions','replyUri','info','afterCreate','length','Interaction','omit','Contact','POST','method','GET','OpenchannelMessage,\x20%s,\x20%s','Message\x20%d\x20forwarded\x20to\x20%s','threadId','catch','error'];(function(_0x6a9978,_0x27409d){var _0x123322=function(_0x12f170){while(--_0x12f170){_0x6a9978['push'](_0x6a9978['shift']());}};_0x123322(++_0x27409d);}(_0xce0d,0xcb));var _0xdce0=function(_0x28d6b9,_0xbe9964){_0x28d6b9=_0x28d6b9-0x0;var _0x1e2bee=_0xce0d[_0x28d6b9];return _0x1e2bee;};'use strict';var _=require(_0xdce0('0x0'));var util=require('util');var logger=require('../../config/logger')(_0xdce0('0x1'));var moment=require(_0xdce0('0x2'));var BPromise=require(_0xdce0('0x3'));var rp=require(_0xdce0('0x4'));var fs=require('fs');var path=require(_0xdce0('0x5'));var rimraf=require(_0xdce0('0x6'));var config=require(_0xdce0('0x7'));var attributes=require(_0xdce0('0x8'));module[_0xdce0('0x9')]=function(_0x16376b,_0x3cc9a9){return _0x16376b[_0xdce0('0xa')](_0xdce0('0xb'),attributes,{'tableName':_0xdce0('0xc'),'paranoid':![],'indexes':[{'name':_0xdce0('0xd'),'fields':[_0xdce0('0xe')],'type':_0xdce0('0xf')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x2a7b74,_0x3f9415,_0x6ac996){var _0x28c332=_0x16376b['models'];var _0x690cff=_0x2a7b74[_0xdce0('0x10')]({'plain':!![]});if(_0x690cff['direction'][_0xdce0('0x11')]()==='in'||_0x690cff[_0xdce0('0x12')]['toLowerCase']()===_0xdce0('0x13')&&!_0x690cff[_0xdce0('0x14')]&&!_[_0xdce0('0x15')](_0x690cff[_0xdce0('0x16')])){_0x28c332[_0xdce0('0x17')][_0xdce0('0x18')]({'where':{'id':_0x690cff[_0xdce0('0x19')]}})['then'](function(_0x13f6f6){if(_0x13f6f6){_0x13f6f6[_0xdce0('0x1a')]({'lastMsgAt':_0x690cff['createdAt'],'lastMsgDirection':_0x690cff['direction'][_0xdce0('0x11')]()});}})['catch'](function(_0x12335b){console['error'](_0x12335b);});}if(_0x690cff[_0xdce0('0x12')]===_0xdce0('0x13')&&!_0x690cff[_0xdce0('0x14')]){var _0xa7bab4;_0x28c332[_0xdce0('0x1b')]['describe']()[_0xdce0('0x1c')](function(_0x10bb64){return _0x28c332['OpenchannelAccount'][_0xdce0('0x1d')]({'where':{'id':_0x690cff[_0xdce0('0x1e')]},'include':[{'model':_0x28c332[_0xdce0('0x17')],'as':_0xdce0('0x1f'),'where':{'id':_0x690cff[_0xdce0('0x19')]},'limit':0x1,'include':[{'model':_0x28c332['CmContact'],'as':'Contact','attributes':_['keys'](_0x10bb64)}]}]});})[_0xdce0('0x1c')](function(_0x5a0e82){_0xa7bab4=_0x5a0e82[_0xdce0('0x10')]({'plain':!![]});if(_0xa7bab4&&_0xa7bab4[_0xdce0('0x20')]){logger[_0xdce0('0x21')]('OpenchannelMessage,\x20%s,\x20%s',_0xdce0('0x22'),util['format']('Forwarding\x20message\x20%d\x20to\x20%s',_0x690cff['id'],_0xa7bab4[_0xdce0('0x20')]));if(_0xa7bab4['Interactions']&&_0xa7bab4[_0xdce0('0x1f')][_0xdce0('0x23')]){_0x690cff[_0xdce0('0x24')]=_[_0xdce0('0x25')](_0xa7bab4['Interactions'][0x0],_0xdce0('0x26'));_0x690cff[_0xdce0('0x26')]=_0xa7bab4[_0xdce0('0x1f')][0x0]['Contact'];}var _0x3f9415={'method':_0xdce0('0x27'),'uri':encodeURI(_0xa7bab4['replyUri']),'json':!![],'resolveWithFullResponse':!![]};switch(_0x3f9415[_0xdce0('0x28')]){case _0xdce0('0x29'):_0x3f9415['qs']=_0x690cff;break;case _0xdce0('0x27'):_0x3f9415[_0xdce0('0xe')]=_0x690cff;break;}return rp(_0x3f9415)[_0xdce0('0x1c')](function(_0x262e87){logger['info'](_0xdce0('0x2a'),_0xdce0('0x22'),util['format'](_0xdce0('0x2b'),_0x690cff['id'],_0xa7bab4[_0xdce0('0x20')]));if(_0x262e87['body'][_0xdce0('0x2c')]&&_0x262e87[_0xdce0('0xe')][_0xdce0('0x2c')]!=_0x690cff[_0xdce0('0x24')][_0xdce0('0x2c')]){return _0x28c332[_0xdce0('0x17')][_0xdce0('0x1a')]({'threadId':_0x262e87[_0xdce0('0xe')][_0xdce0('0x2c')]},{'where':{'id':_0x690cff[_0xdce0('0x24')]['id']}});}else{return;}})[_0xdce0('0x1c')](function(){return _0x2a7b74[_0xdce0('0x1a')]({'read':!![]});})[_0xdce0('0x2d')](function(_0x459cfa){logger[_0xdce0('0x2e')](_0xdce0('0x2a'),_0xdce0('0x22'),util['inspect'](_0x459cfa,{'showHidden':![],'depth':null}));_0x6ac996();});}else{_0x6ac996();}})[_0xdce0('0x2f')](function(){_0x6ac996();});}else{_0x6ac996();}}},'charset':_0xdce0('0x30'),'collate':_0xdce0('0x31')});};