Built motion from commit (unavailable).|2.5.15
[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 _0x3f87=['then','update','error','out','CmContact','describe','find','OpenchannelAccountId','keys','get','replyUri','info','OpenchannelMessage,\x20%s,\x20%s','format','Forwarding\x20message\x20%d\x20to\x20%s','Interactions','length','Interaction','Contact','POST','method','afterCreate','Message\x20%d\x20forwarded\x20to\x20%s','threadId','catch','inspect','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','moment','bluebird','request-promise','rimraf','../../config/environment','exports','define','OpenchannelMessage','fti_openchannel_messages','body','FULLTEXT','models','direction','toLowerCase','secret','UserId','OpenchannelInteraction','OpenchannelInteractionId'];(function(_0x4e9285,_0xc0232){var _0x3cda87=function(_0x442f2a){while(--_0x442f2a){_0x4e9285['push'](_0x4e9285['shift']());}};_0x3cda87(++_0xc0232);}(_0x3f87,0x1d6));var _0x73f8=function(_0x56d93d,_0x5087a2){_0x56d93d=_0x56d93d-0x0;var _0x54e602=_0x3f87[_0x56d93d];return _0x54e602;};'use strict';var _=require(_0x73f8('0x0'));var util=require(_0x73f8('0x1'));var logger=require('../../config/logger')('api');var moment=require(_0x73f8('0x2'));var BPromise=require(_0x73f8('0x3'));var rp=require(_0x73f8('0x4'));var fs=require('fs');var path=require('path');var rimraf=require(_0x73f8('0x5'));var config=require(_0x73f8('0x6'));var attributes=require('./openchannelMessage.attributes');module[_0x73f8('0x7')]=function(_0x1dfa7c,_0x18ad94){return _0x1dfa7c[_0x73f8('0x8')](_0x73f8('0x9'),attributes,{'tableName':'openchannel_messages','paranoid':![],'indexes':[{'name':_0x73f8('0xa'),'fields':[_0x73f8('0xb')],'type':_0x73f8('0xc')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x5e1388,_0x4439ae,_0x278343){var _0x250501=_0x1dfa7c[_0x73f8('0xd')];var _0x2c2cf8=_0x5e1388['get']({'plain':!![]});if(_0x2c2cf8[_0x73f8('0xe')]['toLowerCase']()==='in'||_0x2c2cf8[_0x73f8('0xe')][_0x73f8('0xf')]()==='out'&&!_0x2c2cf8[_0x73f8('0x10')]&&!_['isNil'](_0x2c2cf8[_0x73f8('0x11')])){_0x250501[_0x73f8('0x12')]['findOne']({'where':{'id':_0x2c2cf8[_0x73f8('0x13')]}})[_0x73f8('0x14')](function(_0x45cff3){if(_0x45cff3){_0x45cff3[_0x73f8('0x15')]({'lastMsgAt':_0x2c2cf8['createdAt'],'lastMsgDirection':_0x2c2cf8[_0x73f8('0xe')][_0x73f8('0xf')]()});}})['catch'](function(_0x4126aa){console[_0x73f8('0x16')](_0x4126aa);});}if(_0x2c2cf8[_0x73f8('0xe')]===_0x73f8('0x17')&&!_0x2c2cf8[_0x73f8('0x10')]){var _0x34301f;_0x250501[_0x73f8('0x18')][_0x73f8('0x19')]()['then'](function(_0x9de8ea){return _0x250501['OpenchannelAccount'][_0x73f8('0x1a')]({'where':{'id':_0x2c2cf8[_0x73f8('0x1b')]},'include':[{'model':_0x250501[_0x73f8('0x12')],'as':'Interactions','where':{'id':_0x2c2cf8['OpenchannelInteractionId']},'limit':0x1,'include':[{'model':_0x250501[_0x73f8('0x18')],'as':'Contact','attributes':_[_0x73f8('0x1c')](_0x9de8ea)}]}]});})[_0x73f8('0x14')](function(_0x3bdd42){_0x34301f=_0x3bdd42[_0x73f8('0x1d')]({'plain':!![]});if(_0x34301f&&_0x34301f[_0x73f8('0x1e')]){logger[_0x73f8('0x1f')](_0x73f8('0x20'),'afterCreate',util[_0x73f8('0x21')](_0x73f8('0x22'),_0x2c2cf8['id'],_0x34301f[_0x73f8('0x1e')]));if(_0x34301f[_0x73f8('0x23')]&&_0x34301f[_0x73f8('0x23')][_0x73f8('0x24')]){_0x2c2cf8[_0x73f8('0x25')]=_['omit'](_0x34301f['Interactions'][0x0],_0x73f8('0x26'));_0x2c2cf8[_0x73f8('0x26')]=_0x34301f[_0x73f8('0x23')][0x0][_0x73f8('0x26')];}var _0x4439ae={'method':_0x73f8('0x27'),'uri':encodeURI(_0x34301f['replyUri']),'json':!![],'resolveWithFullResponse':!![]};switch(_0x4439ae[_0x73f8('0x28')]){case'GET':_0x4439ae['qs']=_0x2c2cf8;break;case'POST':_0x4439ae[_0x73f8('0xb')]=_0x2c2cf8;break;}return rp(_0x4439ae)[_0x73f8('0x14')](function(_0x1f18ca){logger[_0x73f8('0x1f')](_0x73f8('0x20'),_0x73f8('0x29'),util['format'](_0x73f8('0x2a'),_0x2c2cf8['id'],_0x34301f['replyUri']));if(_0x1f18ca['body'][_0x73f8('0x2b')]&&_0x1f18ca[_0x73f8('0xb')][_0x73f8('0x2b')]!=_0x2c2cf8[_0x73f8('0x25')]['threadId']){return _0x250501[_0x73f8('0x12')][_0x73f8('0x15')]({'threadId':_0x1f18ca['body'][_0x73f8('0x2b')]},{'logging':!![],'where':{'id':_0x2c2cf8[_0x73f8('0x25')]['id']}});}else{return;}})[_0x73f8('0x14')](function(){return _0x5e1388[_0x73f8('0x15')]({'read':!![]});})[_0x73f8('0x2c')](function(_0x5b4cc2){logger['error'](_0x73f8('0x20'),_0x73f8('0x29'),util[_0x73f8('0x2d')](_0x5b4cc2,{'showHidden':![],'depth':null}));_0x278343();});}else{_0x278343();}})[_0x73f8('0x2e')](function(){_0x278343();});}else{_0x278343();}}},'charset':_0x73f8('0x2f'),'collate':_0x73f8('0x30')});};