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