d6894f4d6e372caadabf7e68a941cac4b3d474d7
[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 _0x45e0=['lodash','util','../../config/logger','bluebird','../../config/environment','define','OpenchannelMessage','openchannel_messages','fti_openchannel_messages','body','FULLTEXT','models','get','direction','toLowerCase','out','secret','isNil','UserId','OpenchannelInteraction','findOne','OpenchannelInteractionId','createdAt','catch','error','CmContact','then','find','OpenchannelAccountId','Interactions','keys','replyUri','info','OpenchannelMessage,\x20%s,\x20%s','afterCreate','format','Interaction','omit','Contact','POST','method','GET','Message\x20%d\x20forwarded\x20to\x20%s','threadId','update','utf8mb4','utf8mb4_unicode_ci'];(function(_0x4ca0a1,_0x6158d8){var _0x1c26c3=function(_0x3029e5){while(--_0x3029e5){_0x4ca0a1['push'](_0x4ca0a1['shift']());}};_0x1c26c3(++_0x6158d8);}(_0x45e0,0x11a));var _0x045e=function(_0x41e925,_0x1c616e){_0x41e925=_0x41e925-0x0;var _0x455b4b=_0x45e0[_0x41e925];return _0x455b4b;};'use strict';var _=require(_0x045e('0x0'));var util=require(_0x045e('0x1'));var logger=require(_0x045e('0x2'))('api');var moment=require('moment');var BPromise=require(_0x045e('0x3'));var rp=require('request-promise');var fs=require('fs');var path=require('path');var rimraf=require('rimraf');var config=require(_0x045e('0x4'));var attributes=require('./openchannelMessage.attributes');module['exports']=function(_0x2dbbb1,_0x573be7){return _0x2dbbb1[_0x045e('0x5')](_0x045e('0x6'),attributes,{'tableName':_0x045e('0x7'),'paranoid':![],'indexes':[{'name':_0x045e('0x8'),'fields':[_0x045e('0x9')],'type':_0x045e('0xa')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x337dd3,_0x60f218,_0x48cf37){var _0xca6889=_0x2dbbb1[_0x045e('0xb')];var _0x54e2c8=_0x337dd3[_0x045e('0xc')]({'plain':!![]});if(_0x54e2c8[_0x045e('0xd')]['toLowerCase']()==='in'||_0x54e2c8[_0x045e('0xd')][_0x045e('0xe')]()===_0x045e('0xf')&&!_0x54e2c8[_0x045e('0x10')]&&!_[_0x045e('0x11')](_0x54e2c8[_0x045e('0x12')])){_0xca6889[_0x045e('0x13')][_0x045e('0x14')]({'where':{'id':_0x54e2c8[_0x045e('0x15')]}})['then'](function(_0x1ff0f0){if(_0x1ff0f0){_0x1ff0f0['update']({'lastMsgAt':_0x54e2c8[_0x045e('0x16')],'lastMsgDirection':_0x54e2c8[_0x045e('0xd')][_0x045e('0xe')]()});}})[_0x045e('0x17')](function(_0x493a36){console[_0x045e('0x18')](_0x493a36);});}if(_0x54e2c8[_0x045e('0xd')]===_0x045e('0xf')&&!_0x54e2c8['secret']){var _0x2eddb5;_0xca6889[_0x045e('0x19')]['describe']()[_0x045e('0x1a')](function(_0x19133c){return _0xca6889['OpenchannelAccount'][_0x045e('0x1b')]({'where':{'id':_0x54e2c8[_0x045e('0x1c')]},'include':[{'model':_0xca6889[_0x045e('0x13')],'as':_0x045e('0x1d'),'where':{'id':_0x54e2c8[_0x045e('0x15')]},'limit':0x1,'include':[{'model':_0xca6889['CmContact'],'as':'Contact','attributes':_[_0x045e('0x1e')](_0x19133c)}]}]});})['then'](function(_0x767685){_0x2eddb5=_0x767685[_0x045e('0xc')]({'plain':!![]});if(_0x2eddb5&&_0x2eddb5[_0x045e('0x1f')]){logger[_0x045e('0x20')](_0x045e('0x21'),_0x045e('0x22'),util[_0x045e('0x23')]('Forwarding\x20message\x20%d\x20to\x20%s',_0x54e2c8['id'],_0x2eddb5['replyUri']));if(_0x2eddb5[_0x045e('0x1d')]&&_0x2eddb5[_0x045e('0x1d')]['length']){_0x54e2c8[_0x045e('0x24')]=_[_0x045e('0x25')](_0x2eddb5[_0x045e('0x1d')][0x0],_0x045e('0x26'));_0x54e2c8[_0x045e('0x26')]=_0x2eddb5[_0x045e('0x1d')][0x0][_0x045e('0x26')];}var _0x60f218={'method':_0x045e('0x27'),'uri':encodeURI(_0x2eddb5[_0x045e('0x1f')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x60f218[_0x045e('0x28')]){case _0x045e('0x29'):_0x60f218['qs']=_0x54e2c8;break;case _0x045e('0x27'):_0x60f218[_0x045e('0x9')]=_0x54e2c8;break;}return rp(_0x60f218)['then'](function(_0x4b88bd){logger[_0x045e('0x20')](_0x045e('0x21'),'afterCreate',util[_0x045e('0x23')](_0x045e('0x2a'),_0x54e2c8['id'],_0x2eddb5[_0x045e('0x1f')]));if(_0x4b88bd[_0x045e('0x9')]['threadId']&&_0x4b88bd['body'][_0x045e('0x2b')]!=_0x54e2c8[_0x045e('0x24')][_0x045e('0x2b')]){return _0xca6889[_0x045e('0x13')][_0x045e('0x2c')]({'threadId':_0x4b88bd[_0x045e('0x9')]['threadId']},{'where':{'id':_0x54e2c8[_0x045e('0x24')]['id']}});}else{return;}})['then'](function(){return _0x337dd3[_0x045e('0x2c')]({'read':!![]});})[_0x045e('0x17')](function(_0x585a46){logger[_0x045e('0x18')](_0x045e('0x21'),'afterCreate',util['inspect'](_0x585a46,{'showHidden':![],'depth':null}));_0x48cf37();});}else{_0x48cf37();}})['finally'](function(){_0x48cf37();});}else{_0x48cf37();}}},'charset':_0x045e('0x2d'),'collate':_0x045e('0x2e')});};