Built motion from commit (unavailable).|2.5.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 _0xc46b=['info','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','Interactions','Interaction','omit','Contact','replyUri','GET','POST','body','OpenchannelMessage,\x20%s,\x20%s','Message\x20%d\x20forwarded\x20to\x20%s','threadId','catch','error','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','bluebird','request-promise','path','rimraf','../../config/environment','./openchannelMessage.attributes','define','OpenchannelMessage','openchannel_messages','fti_openchannel_messages','models','get','direction','toLowerCase','out','isNil','UserId','OpenchannelInteraction','findOne','OpenchannelInteractionId','then','update','createdAt','secret','CmContact','OpenchannelAccount','find','OpenchannelAccountId','keys'];(function(_0x1aeb29,_0x245cfd){var _0x27b597=function(_0x2fbdea){while(--_0x2fbdea){_0x1aeb29['push'](_0x1aeb29['shift']());}};_0x27b597(++_0x245cfd);}(_0xc46b,0x7a));var _0xbc46=function(_0x45c1ca,_0x683fea){_0x45c1ca=_0x45c1ca-0x0;var _0x131c82=_0xc46b[_0x45c1ca];return _0x131c82;};'use strict';var _=require(_0xbc46('0x0'));var util=require(_0xbc46('0x1'));var logger=require(_0xbc46('0x2'))(_0xbc46('0x3'));var moment=require(_0xbc46('0x4'));var BPromise=require(_0xbc46('0x5'));var rp=require(_0xbc46('0x6'));var fs=require('fs');var path=require(_0xbc46('0x7'));var rimraf=require(_0xbc46('0x8'));var config=require(_0xbc46('0x9'));var attributes=require(_0xbc46('0xa'));module['exports']=function(_0x34d771,_0x137b04){return _0x34d771[_0xbc46('0xb')](_0xbc46('0xc'),attributes,{'tableName':_0xbc46('0xd'),'paranoid':![],'indexes':[{'name':_0xbc46('0xe'),'fields':['body'],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x2f96d9,_0x4f4a60,_0x437244){var _0x32b05b=_0x34d771[_0xbc46('0xf')];var _0x1887d4=_0x2f96d9[_0xbc46('0x10')]({'plain':!![]});if(_0x1887d4[_0xbc46('0x11')][_0xbc46('0x12')]()==='in'||_0x1887d4[_0xbc46('0x11')][_0xbc46('0x12')]()===_0xbc46('0x13')&&!_0x1887d4['secret']&&!_[_0xbc46('0x14')](_0x1887d4[_0xbc46('0x15')])){_0x32b05b[_0xbc46('0x16')][_0xbc46('0x17')]({'where':{'id':_0x1887d4[_0xbc46('0x18')]}})[_0xbc46('0x19')](function(_0x3c17fc){if(_0x3c17fc){_0x3c17fc[_0xbc46('0x1a')]({'lastMsgAt':_0x1887d4[_0xbc46('0x1b')],'lastMsgDirection':_0x1887d4[_0xbc46('0x11')]['toLowerCase']()});}})['catch'](function(_0x46067f){console['error'](_0x46067f);});}if(_0x1887d4[_0xbc46('0x11')]==='out'&&!_0x1887d4[_0xbc46('0x1c')]){var _0x380d2f;_0x32b05b[_0xbc46('0x1d')]['describe']()[_0xbc46('0x19')](function(_0x5e34fd){return _0x32b05b[_0xbc46('0x1e')][_0xbc46('0x1f')]({'where':{'id':_0x1887d4[_0xbc46('0x20')]},'include':[{'model':_0x32b05b[_0xbc46('0x16')],'as':'Interactions','where':{'id':_0x1887d4[_0xbc46('0x18')]},'limit':0x1,'include':[{'model':_0x32b05b[_0xbc46('0x1d')],'as':'Contact','attributes':_[_0xbc46('0x21')](_0x5e34fd)}]}]});})[_0xbc46('0x19')](function(_0xdef835){_0x380d2f=_0xdef835[_0xbc46('0x10')]({'plain':!![]});if(_0x380d2f&&_0x380d2f['replyUri']){logger[_0xbc46('0x22')]('OpenchannelMessage,\x20%s,\x20%s',_0xbc46('0x23'),util[_0xbc46('0x24')](_0xbc46('0x25'),_0x1887d4['id'],_0x380d2f['replyUri']));if(_0x380d2f[_0xbc46('0x26')]&&_0x380d2f[_0xbc46('0x26')]['length']){_0x1887d4[_0xbc46('0x27')]=_[_0xbc46('0x28')](_0x380d2f[_0xbc46('0x26')][0x0],_0xbc46('0x29'));_0x1887d4[_0xbc46('0x29')]=_0x380d2f[_0xbc46('0x26')][0x0][_0xbc46('0x29')];}var _0x4f4a60={'method':'POST','uri':encodeURI(_0x380d2f[_0xbc46('0x2a')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x4f4a60['method']){case _0xbc46('0x2b'):_0x4f4a60['qs']=_0x1887d4;break;case _0xbc46('0x2c'):_0x4f4a60[_0xbc46('0x2d')]=_0x1887d4;break;}return rp(_0x4f4a60)['then'](function(_0x3ca047){logger[_0xbc46('0x22')](_0xbc46('0x2e'),_0xbc46('0x23'),util['format'](_0xbc46('0x2f'),_0x1887d4['id'],_0x380d2f[_0xbc46('0x2a')]));if(_0x3ca047['body'][_0xbc46('0x30')]&&_0x3ca047[_0xbc46('0x2d')][_0xbc46('0x30')]!=_0x1887d4[_0xbc46('0x27')]['threadId']){return _0x32b05b[_0xbc46('0x16')][_0xbc46('0x1a')]({'threadId':_0x3ca047['body'][_0xbc46('0x30')]},{'logging':!![],'where':{'id':_0x1887d4[_0xbc46('0x27')]['id']}});}else{return;}})[_0xbc46('0x19')](function(){return _0x2f96d9[_0xbc46('0x1a')]({'read':!![]});})[_0xbc46('0x31')](function(_0x455a8f){logger[_0xbc46('0x32')](_0xbc46('0x2e'),_0xbc46('0x23'),util['inspect'](_0x455a8f,{'showHidden':![],'depth':null}));_0x437244();});}else{_0x437244();}})['finally'](function(){_0x437244();});}else{_0x437244();}}},'charset':'utf8mb4','collate':_0xbc46('0x33')});};