Built motion from commit efa66e19.|2.6.22
[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 _0x6a15=['fti_openchannel_messages','body','models','get','direction','toLowerCase','out','secret','isNil','UserId','OpenchannelInteraction','OpenchannelInteractionId','update','createdAt','catch','error','CmContact','OpenchannelAccount','OpenchannelAccountId','Interactions','Contact','keys','then','replyUri','OpenchannelMessage,\x20%s,\x20%s','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','length','Interaction','omit','POST','method','GET','Message\x20%d\x20forwarded\x20to\x20%s','threadId','inspect','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','moment','bluebird','request-promise','path','rimraf','../../config/environment','./openchannelMessage.attributes','define','OpenchannelMessage','openchannel_messages'];(function(_0x57b484,_0x2272b4){var _0x823cf6=function(_0x4849be){while(--_0x4849be){_0x57b484['push'](_0x57b484['shift']());}};_0x823cf6(++_0x2272b4);}(_0x6a15,0xf7));var _0x56a1=function(_0x39f8da,_0x313ea0){_0x39f8da=_0x39f8da-0x0;var _0x2f3ea6=_0x6a15[_0x39f8da];return _0x2f3ea6;};'use strict';var _=require(_0x56a1('0x0'));var util=require(_0x56a1('0x1'));var logger=require(_0x56a1('0x2'))('api');var moment=require(_0x56a1('0x3'));var BPromise=require(_0x56a1('0x4'));var rp=require(_0x56a1('0x5'));var fs=require('fs');var path=require(_0x56a1('0x6'));var rimraf=require(_0x56a1('0x7'));var config=require(_0x56a1('0x8'));var attributes=require(_0x56a1('0x9'));module['exports']=function(_0x554e39,_0x3a4e83){return _0x554e39[_0x56a1('0xa')](_0x56a1('0xb'),attributes,{'tableName':_0x56a1('0xc'),'paranoid':![],'indexes':[{'name':_0x56a1('0xd'),'fields':[_0x56a1('0xe')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x591339,_0x4f8794,_0x5f183b){var _0x476c42=_0x554e39[_0x56a1('0xf')];var _0x4acf8e=_0x591339[_0x56a1('0x10')]({'plain':!![]});if(_0x4acf8e[_0x56a1('0x11')][_0x56a1('0x12')]()==='in'||_0x4acf8e[_0x56a1('0x11')][_0x56a1('0x12')]()===_0x56a1('0x13')&&!_0x4acf8e[_0x56a1('0x14')]&&!_[_0x56a1('0x15')](_0x4acf8e[_0x56a1('0x16')])){_0x476c42[_0x56a1('0x17')]['findOne']({'where':{'id':_0x4acf8e[_0x56a1('0x18')]}})['then'](function(_0x14c0d6){if(_0x14c0d6){_0x14c0d6[_0x56a1('0x19')]({'lastMsgAt':_0x4acf8e[_0x56a1('0x1a')],'lastMsgDirection':_0x4acf8e['direction']['toLowerCase']()});}})[_0x56a1('0x1b')](function(_0x366c4f){console[_0x56a1('0x1c')](_0x366c4f);});}if(_0x4acf8e[_0x56a1('0x11')]===_0x56a1('0x13')&&!_0x4acf8e['secret']){var _0x83fa3f;_0x476c42[_0x56a1('0x1d')]['describe']()['then'](function(_0x3fa5db){return _0x476c42[_0x56a1('0x1e')]['find']({'where':{'id':_0x4acf8e[_0x56a1('0x1f')]},'include':[{'model':_0x476c42['OpenchannelInteraction'],'as':_0x56a1('0x20'),'where':{'id':_0x4acf8e[_0x56a1('0x18')]},'limit':0x1,'include':[{'model':_0x476c42[_0x56a1('0x1d')],'as':_0x56a1('0x21'),'attributes':_[_0x56a1('0x22')](_0x3fa5db)}]}]});})[_0x56a1('0x23')](function(_0x3f6fdf){_0x83fa3f=_0x3f6fdf[_0x56a1('0x10')]({'plain':!![]});if(_0x83fa3f&&_0x83fa3f[_0x56a1('0x24')]){logger['info'](_0x56a1('0x25'),_0x56a1('0x26'),util[_0x56a1('0x27')](_0x56a1('0x28'),_0x4acf8e['id'],_0x83fa3f[_0x56a1('0x24')]));if(_0x83fa3f[_0x56a1('0x20')]&&_0x83fa3f[_0x56a1('0x20')][_0x56a1('0x29')]){_0x4acf8e[_0x56a1('0x2a')]=_[_0x56a1('0x2b')](_0x83fa3f['Interactions'][0x0],_0x56a1('0x21'));_0x4acf8e[_0x56a1('0x21')]=_0x83fa3f[_0x56a1('0x20')][0x0]['Contact'];}var _0x4f8794={'method':_0x56a1('0x2c'),'uri':encodeURI(_0x83fa3f['replyUri']),'json':!![],'resolveWithFullResponse':!![]};switch(_0x4f8794[_0x56a1('0x2d')]){case _0x56a1('0x2e'):_0x4f8794['qs']=_0x4acf8e;break;case'POST':_0x4f8794['body']=_0x4acf8e;break;}return rp(_0x4f8794)['then'](function(_0x5899d2){logger['info'](_0x56a1('0x25'),_0x56a1('0x26'),util['format'](_0x56a1('0x2f'),_0x4acf8e['id'],_0x83fa3f['replyUri']));if(_0x5899d2[_0x56a1('0xe')]['threadId']&&_0x5899d2[_0x56a1('0xe')][_0x56a1('0x30')]!=_0x4acf8e['Interaction'][_0x56a1('0x30')]){return _0x476c42['OpenchannelInteraction'][_0x56a1('0x19')]({'threadId':_0x5899d2[_0x56a1('0xe')][_0x56a1('0x30')]},{'where':{'id':_0x4acf8e[_0x56a1('0x2a')]['id']}});}else{return;}})[_0x56a1('0x23')](function(){return _0x591339[_0x56a1('0x19')]({'read':!![]});})['catch'](function(_0x148332){logger[_0x56a1('0x1c')](_0x56a1('0x25'),_0x56a1('0x26'),util[_0x56a1('0x31')](_0x148332,{'showHidden':![],'depth':null}));_0x5f183b();});}else{_0x5f183b();}})['finally'](function(){_0x5f183b();});}else{_0x5f183b();}}},'charset':_0x56a1('0x32'),'collate':_0x56a1('0x33')});};