Built motion from commit d1eab355.|2.6.28
[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 _0xbf72=['threadId','Interaction','inspect','utf8mb4','lodash','util','../../config/logger','api','moment','bluebird','path','rimraf','../../config/environment','./openchannelMessage.attributes','exports','OpenchannelMessage','openchannel_messages','body','FULLTEXT','models','direction','toLowerCase','out','secret','isNil','OpenchannelInteraction','findOne','then','update','createdAt','catch','error','CmContact','describe','find','OpenchannelAccountId','Interactions','OpenchannelInteractionId','keys','info','OpenchannelMessage,\x20%s,\x20%s','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','replyUri','length','omit','Contact','POST','method','GET','Message\x20%d\x20forwarded\x20to\x20%s'];(function(_0xc54957,_0x5b1e6a){var _0x4ea905=function(_0x2d743e){while(--_0x2d743e){_0xc54957['push'](_0xc54957['shift']());}};_0x4ea905(++_0x5b1e6a);}(_0xbf72,0x170));var _0x2bf7=function(_0x40177b,_0x245ffb){_0x40177b=_0x40177b-0x0;var _0x46d6b6=_0xbf72[_0x40177b];return _0x46d6b6;};'use strict';var _=require(_0x2bf7('0x0'));var util=require(_0x2bf7('0x1'));var logger=require(_0x2bf7('0x2'))(_0x2bf7('0x3'));var moment=require(_0x2bf7('0x4'));var BPromise=require(_0x2bf7('0x5'));var rp=require('request-promise');var fs=require('fs');var path=require(_0x2bf7('0x6'));var rimraf=require(_0x2bf7('0x7'));var config=require(_0x2bf7('0x8'));var attributes=require(_0x2bf7('0x9'));module[_0x2bf7('0xa')]=function(_0x118abc,_0xe3a3de){return _0x118abc['define'](_0x2bf7('0xb'),attributes,{'tableName':_0x2bf7('0xc'),'paranoid':![],'indexes':[{'name':'fti_openchannel_messages','fields':[_0x2bf7('0xd')],'type':_0x2bf7('0xe')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x53b0ad,_0x115489,_0x356f7b){var _0x48f83d=_0x118abc[_0x2bf7('0xf')];var _0x584ba3=_0x53b0ad['get']({'plain':!![]});if(_0x584ba3[_0x2bf7('0x10')][_0x2bf7('0x11')]()==='in'||_0x584ba3[_0x2bf7('0x10')]['toLowerCase']()===_0x2bf7('0x12')&&!_0x584ba3[_0x2bf7('0x13')]&&!_[_0x2bf7('0x14')](_0x584ba3['UserId'])){_0x48f83d[_0x2bf7('0x15')][_0x2bf7('0x16')]({'where':{'id':_0x584ba3['OpenchannelInteractionId']}})[_0x2bf7('0x17')](function(_0x44c113){if(_0x44c113){_0x44c113[_0x2bf7('0x18')]({'lastMsgAt':_0x584ba3[_0x2bf7('0x19')],'lastMsgDirection':_0x584ba3[_0x2bf7('0x10')][_0x2bf7('0x11')]()});}})[_0x2bf7('0x1a')](function(_0x572394){console[_0x2bf7('0x1b')](_0x572394);});}if(_0x584ba3['direction']===_0x2bf7('0x12')&&!_0x584ba3['secret']){var _0x3907ed;_0x48f83d[_0x2bf7('0x1c')][_0x2bf7('0x1d')]()['then'](function(_0x113f0b){return _0x48f83d['OpenchannelAccount'][_0x2bf7('0x1e')]({'where':{'id':_0x584ba3[_0x2bf7('0x1f')]},'include':[{'model':_0x48f83d[_0x2bf7('0x15')],'as':_0x2bf7('0x20'),'where':{'id':_0x584ba3[_0x2bf7('0x21')]},'limit':0x1,'include':[{'model':_0x48f83d[_0x2bf7('0x1c')],'as':'Contact','attributes':_[_0x2bf7('0x22')](_0x113f0b)}]}]});})['then'](function(_0x5cc08d){_0x3907ed=_0x5cc08d['get']({'plain':!![]});if(_0x3907ed&&_0x3907ed['replyUri']){logger[_0x2bf7('0x23')](_0x2bf7('0x24'),_0x2bf7('0x25'),util[_0x2bf7('0x26')](_0x2bf7('0x27'),_0x584ba3['id'],_0x3907ed[_0x2bf7('0x28')]));if(_0x3907ed['Interactions']&&_0x3907ed[_0x2bf7('0x20')][_0x2bf7('0x29')]){_0x584ba3['Interaction']=_[_0x2bf7('0x2a')](_0x3907ed[_0x2bf7('0x20')][0x0],_0x2bf7('0x2b'));_0x584ba3[_0x2bf7('0x2b')]=_0x3907ed[_0x2bf7('0x20')][0x0][_0x2bf7('0x2b')];}var _0x115489={'method':_0x2bf7('0x2c'),'uri':encodeURI(_0x3907ed['replyUri']),'json':!![],'resolveWithFullResponse':!![]};switch(_0x115489[_0x2bf7('0x2d')]){case _0x2bf7('0x2e'):_0x115489['qs']=_0x584ba3;break;case _0x2bf7('0x2c'):_0x115489['body']=_0x584ba3;break;}return rp(_0x115489)['then'](function(_0x5178e9){logger[_0x2bf7('0x23')](_0x2bf7('0x24'),_0x2bf7('0x25'),util[_0x2bf7('0x26')](_0x2bf7('0x2f'),_0x584ba3['id'],_0x3907ed[_0x2bf7('0x28')]));if(_0x5178e9[_0x2bf7('0xd')][_0x2bf7('0x30')]&&_0x5178e9['body'][_0x2bf7('0x30')]!=_0x584ba3[_0x2bf7('0x31')][_0x2bf7('0x30')]){return _0x48f83d['OpenchannelInteraction'][_0x2bf7('0x18')]({'threadId':_0x5178e9[_0x2bf7('0xd')][_0x2bf7('0x30')]},{'where':{'id':_0x584ba3[_0x2bf7('0x31')]['id']}});}else{return;}})[_0x2bf7('0x17')](function(){return _0x53b0ad[_0x2bf7('0x18')]({'read':!![]});})['catch'](function(_0x1ca196){logger[_0x2bf7('0x1b')](_0x2bf7('0x24'),_0x2bf7('0x25'),util[_0x2bf7('0x32')](_0x1ca196,{'showHidden':![],'depth':null}));_0x356f7b();});}else{_0x356f7b();}})['finally'](function(){_0x356f7b();});}else{_0x356f7b();}}},'charset':_0x2bf7('0x33'),'collate':'utf8mb4_unicode_ci'});};