Built motion from commit 5b761a7b.|2.5.36
[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 _0xf7b4=['OpenchannelInteractionId','Contact','replyUri','info','OpenchannelMessage,\x20%s,\x20%s','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','length','omit','POST','method','GET','Message\x20%d\x20forwarded\x20to\x20%s','threadId','Interaction','inspect','finally','utf8mb4','utf8mb4_unicode_ci','lodash','api','moment','path','rimraf','../../config/environment','./openchannelMessage.attributes','exports','define','OpenchannelMessage','openchannel_messages','fti_openchannel_messages','body','FULLTEXT','models','get','direction','toLowerCase','isNil','UserId','OpenchannelInteraction','findOne','then','update','createdAt','catch','error','out','secret','CmContact','OpenchannelAccount','OpenchannelAccountId','Interactions'];(function(_0x5eb6ca,_0x5347e7){var _0x38b2d2=function(_0x73e320){while(--_0x73e320){_0x5eb6ca['push'](_0x5eb6ca['shift']());}};_0x38b2d2(++_0x5347e7);}(_0xf7b4,0x152));var _0x4f7b=function(_0x2573ca,_0x550022){_0x2573ca=_0x2573ca-0x0;var _0x220656=_0xf7b4[_0x2573ca];return _0x220656;};'use strict';var _=require(_0x4f7b('0x0'));var util=require('util');var logger=require('../../config/logger')(_0x4f7b('0x1'));var moment=require(_0x4f7b('0x2'));var BPromise=require('bluebird');var rp=require('request-promise');var fs=require('fs');var path=require(_0x4f7b('0x3'));var rimraf=require(_0x4f7b('0x4'));var config=require(_0x4f7b('0x5'));var attributes=require(_0x4f7b('0x6'));module[_0x4f7b('0x7')]=function(_0x2637f0,_0x427f8b){return _0x2637f0[_0x4f7b('0x8')](_0x4f7b('0x9'),attributes,{'tableName':_0x4f7b('0xa'),'paranoid':![],'indexes':[{'name':_0x4f7b('0xb'),'fields':[_0x4f7b('0xc')],'type':_0x4f7b('0xd')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x5c714d,_0x433563,_0x1016e0){var _0x479208=_0x2637f0[_0x4f7b('0xe')];var _0x3a3d6c=_0x5c714d[_0x4f7b('0xf')]({'plain':!![]});if(_0x3a3d6c[_0x4f7b('0x10')][_0x4f7b('0x11')]()==='in'||_0x3a3d6c['direction'][_0x4f7b('0x11')]()==='out'&&!_0x3a3d6c['secret']&&!_[_0x4f7b('0x12')](_0x3a3d6c[_0x4f7b('0x13')])){_0x479208[_0x4f7b('0x14')][_0x4f7b('0x15')]({'where':{'id':_0x3a3d6c['OpenchannelInteractionId']}})[_0x4f7b('0x16')](function(_0x368091){if(_0x368091){_0x368091[_0x4f7b('0x17')]({'lastMsgAt':_0x3a3d6c[_0x4f7b('0x18')],'lastMsgDirection':_0x3a3d6c[_0x4f7b('0x10')][_0x4f7b('0x11')]()});}})[_0x4f7b('0x19')](function(_0x2437cc){console[_0x4f7b('0x1a')](_0x2437cc);});}if(_0x3a3d6c[_0x4f7b('0x10')]===_0x4f7b('0x1b')&&!_0x3a3d6c[_0x4f7b('0x1c')]){var _0x50a161;_0x479208[_0x4f7b('0x1d')]['describe']()['then'](function(_0x24e5cf){return _0x479208[_0x4f7b('0x1e')]['find']({'where':{'id':_0x3a3d6c[_0x4f7b('0x1f')]},'include':[{'model':_0x479208[_0x4f7b('0x14')],'as':_0x4f7b('0x20'),'where':{'id':_0x3a3d6c[_0x4f7b('0x21')]},'limit':0x1,'include':[{'model':_0x479208['CmContact'],'as':_0x4f7b('0x22'),'attributes':_['keys'](_0x24e5cf)}]}]});})[_0x4f7b('0x16')](function(_0x12374b){_0x50a161=_0x12374b[_0x4f7b('0xf')]({'plain':!![]});if(_0x50a161&&_0x50a161[_0x4f7b('0x23')]){logger[_0x4f7b('0x24')](_0x4f7b('0x25'),_0x4f7b('0x26'),util[_0x4f7b('0x27')](_0x4f7b('0x28'),_0x3a3d6c['id'],_0x50a161['replyUri']));if(_0x50a161[_0x4f7b('0x20')]&&_0x50a161[_0x4f7b('0x20')][_0x4f7b('0x29')]){_0x3a3d6c['Interaction']=_[_0x4f7b('0x2a')](_0x50a161[_0x4f7b('0x20')][0x0],'Contact');_0x3a3d6c[_0x4f7b('0x22')]=_0x50a161['Interactions'][0x0][_0x4f7b('0x22')];}var _0x433563={'method':_0x4f7b('0x2b'),'uri':encodeURI(_0x50a161[_0x4f7b('0x23')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x433563[_0x4f7b('0x2c')]){case _0x4f7b('0x2d'):_0x433563['qs']=_0x3a3d6c;break;case _0x4f7b('0x2b'):_0x433563[_0x4f7b('0xc')]=_0x3a3d6c;break;}return rp(_0x433563)['then'](function(_0x6c9626){logger[_0x4f7b('0x24')](_0x4f7b('0x25'),'afterCreate',util[_0x4f7b('0x27')](_0x4f7b('0x2e'),_0x3a3d6c['id'],_0x50a161[_0x4f7b('0x23')]));if(_0x6c9626[_0x4f7b('0xc')][_0x4f7b('0x2f')]&&_0x6c9626['body'][_0x4f7b('0x2f')]!=_0x3a3d6c[_0x4f7b('0x30')][_0x4f7b('0x2f')]){return _0x479208['OpenchannelInteraction'][_0x4f7b('0x17')]({'threadId':_0x6c9626['body']['threadId']},{'logging':!![],'where':{'id':_0x3a3d6c[_0x4f7b('0x30')]['id']}});}else{return;}})['then'](function(){return _0x5c714d[_0x4f7b('0x17')]({'read':!![]});})[_0x4f7b('0x19')](function(_0x22f489){logger[_0x4f7b('0x1a')](_0x4f7b('0x25'),_0x4f7b('0x26'),util[_0x4f7b('0x31')](_0x22f489,{'showHidden':![],'depth':null}));_0x1016e0();});}else{_0x1016e0();}})[_0x4f7b('0x32')](function(){_0x1016e0();});}else{_0x1016e0();}}},'charset':_0x4f7b('0x33'),'collate':_0x4f7b('0x34')});};