Built motion from commit 3c2ce842.|2.6.31
[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 _0x45a3=['Interactions','Contact','then','replyUri','info','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','Interaction','omit','POST','method','OpenchannelMessage,\x20%s,\x20%s','threadId','error','inspect','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','bluebird','request-promise','path','rimraf','../../config/environment','./openchannelMessage.attributes','exports','define','OpenchannelMessage','fti_openchannel_messages','body','FULLTEXT','models','get','direction','toLowerCase','isNil','OpenchannelInteraction','findOne','OpenchannelInteractionId','update','createdAt','catch','secret','CmContact','describe','OpenchannelAccount','OpenchannelAccountId'];(function(_0x2f3f7e,_0x25dba8){var _0x2c8ee4=function(_0x36eea7){while(--_0x36eea7){_0x2f3f7e['push'](_0x2f3f7e['shift']());}};_0x2c8ee4(++_0x25dba8);}(_0x45a3,0xaf));var _0x345a=function(_0x186dbb,_0x1352c4){_0x186dbb=_0x186dbb-0x0;var _0x28fe9f=_0x45a3[_0x186dbb];return _0x28fe9f;};'use strict';var _=require(_0x345a('0x0'));var util=require(_0x345a('0x1'));var logger=require(_0x345a('0x2'))(_0x345a('0x3'));var moment=require(_0x345a('0x4'));var BPromise=require(_0x345a('0x5'));var rp=require(_0x345a('0x6'));var fs=require('fs');var path=require(_0x345a('0x7'));var rimraf=require(_0x345a('0x8'));var config=require(_0x345a('0x9'));var attributes=require(_0x345a('0xa'));module[_0x345a('0xb')]=function(_0x5467fd,_0x5c362e){return _0x5467fd[_0x345a('0xc')](_0x345a('0xd'),attributes,{'tableName':'openchannel_messages','paranoid':![],'indexes':[{'name':_0x345a('0xe'),'fields':[_0x345a('0xf')],'type':_0x345a('0x10')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x2a80b5,_0x506aa0,_0x13f5d8){var _0x50e941=_0x5467fd[_0x345a('0x11')];var _0x1a4164=_0x2a80b5[_0x345a('0x12')]({'plain':!![]});if(_0x1a4164[_0x345a('0x13')][_0x345a('0x14')]()==='in'||_0x1a4164['direction'][_0x345a('0x14')]()==='out'&&!_0x1a4164['secret']&&!_[_0x345a('0x15')](_0x1a4164['UserId'])){_0x50e941[_0x345a('0x16')][_0x345a('0x17')]({'where':{'id':_0x1a4164[_0x345a('0x18')]}})['then'](function(_0x4b6442){if(_0x4b6442){_0x4b6442[_0x345a('0x19')]({'lastMsgAt':_0x1a4164[_0x345a('0x1a')],'lastMsgDirection':_0x1a4164['direction'][_0x345a('0x14')]()});}})[_0x345a('0x1b')](function(_0xb3271){console['error'](_0xb3271);});}if(_0x1a4164[_0x345a('0x13')]==='out'&&!_0x1a4164[_0x345a('0x1c')]){var _0x55e395;_0x50e941[_0x345a('0x1d')][_0x345a('0x1e')]()['then'](function(_0x29930a){return _0x50e941[_0x345a('0x1f')]['find']({'where':{'id':_0x1a4164[_0x345a('0x20')]},'include':[{'model':_0x50e941['OpenchannelInteraction'],'as':_0x345a('0x21'),'where':{'id':_0x1a4164[_0x345a('0x18')]},'limit':0x1,'include':[{'model':_0x50e941[_0x345a('0x1d')],'as':_0x345a('0x22'),'attributes':_['keys'](_0x29930a)}]}]});})[_0x345a('0x23')](function(_0x2f6d52){_0x55e395=_0x2f6d52[_0x345a('0x12')]({'plain':!![]});if(_0x55e395&&_0x55e395[_0x345a('0x24')]){logger[_0x345a('0x25')]('OpenchannelMessage,\x20%s,\x20%s',_0x345a('0x26'),util[_0x345a('0x27')](_0x345a('0x28'),_0x1a4164['id'],_0x55e395[_0x345a('0x24')]));if(_0x55e395[_0x345a('0x21')]&&_0x55e395['Interactions']['length']){_0x1a4164[_0x345a('0x29')]=_[_0x345a('0x2a')](_0x55e395['Interactions'][0x0],'Contact');_0x1a4164[_0x345a('0x22')]=_0x55e395['Interactions'][0x0][_0x345a('0x22')];}var _0x506aa0={'method':_0x345a('0x2b'),'uri':encodeURI(_0x55e395[_0x345a('0x24')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x506aa0[_0x345a('0x2c')]){case'GET':_0x506aa0['qs']=_0x1a4164;break;case'POST':_0x506aa0[_0x345a('0xf')]=_0x1a4164;break;}return rp(_0x506aa0)[_0x345a('0x23')](function(_0xb2356d){logger[_0x345a('0x25')](_0x345a('0x2d'),_0x345a('0x26'),util[_0x345a('0x27')]('Message\x20%d\x20forwarded\x20to\x20%s',_0x1a4164['id'],_0x55e395[_0x345a('0x24')]));if(_0xb2356d[_0x345a('0xf')]['threadId']&&_0xb2356d[_0x345a('0xf')][_0x345a('0x2e')]!=_0x1a4164[_0x345a('0x29')][_0x345a('0x2e')]){return _0x50e941['OpenchannelInteraction'][_0x345a('0x19')]({'threadId':_0xb2356d[_0x345a('0xf')][_0x345a('0x2e')]},{'where':{'id':_0x1a4164[_0x345a('0x29')]['id']}});}else{return;}})[_0x345a('0x23')](function(){return _0x2a80b5[_0x345a('0x19')]({'read':!![]});})[_0x345a('0x1b')](function(_0x3a8346){logger[_0x345a('0x2f')](_0x345a('0x2d'),_0x345a('0x26'),util[_0x345a('0x30')](_0x3a8346,{'showHidden':![],'depth':null}));_0x13f5d8();});}else{_0x13f5d8();}})[_0x345a('0x31')](function(){_0x13f5d8();});}else{_0x13f5d8();}}},'charset':_0x345a('0x32'),'collate':_0x345a('0x33')});};