Built motion from commit da617fac.|2.6.6
[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 _0x3ec3=['describe','find','OpenchannelAccountId','Interactions','keys','replyUri','OpenchannelMessage,\x20%s,\x20%s','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','length','Interaction','omit','Contact','POST','method','GET','info','Message\x20%d\x20forwarded\x20to\x20%s','threadId','update','catch','inspect','finally','utf8mb4','lodash','util','../../config/logger','api','moment','bluebird','path','rimraf','../../config/environment','define','openchannel_messages','body','FULLTEXT','get','direction','toLowerCase','out','secret','isNil','UserId','OpenchannelInteraction','findOne','OpenchannelInteractionId','then','error','CmContact'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x3ec3,0x17e));var _0x33ec=function(_0x4f96ac,_0x18dc01){_0x4f96ac=_0x4f96ac-0x0;var _0x33bd52=_0x3ec3[_0x4f96ac];return _0x33bd52;};'use strict';var _=require(_0x33ec('0x0'));var util=require(_0x33ec('0x1'));var logger=require(_0x33ec('0x2'))(_0x33ec('0x3'));var moment=require(_0x33ec('0x4'));var BPromise=require(_0x33ec('0x5'));var rp=require('request-promise');var fs=require('fs');var path=require(_0x33ec('0x6'));var rimraf=require(_0x33ec('0x7'));var config=require(_0x33ec('0x8'));var attributes=require('./openchannelMessage.attributes');module['exports']=function(_0x7d57df,_0x18868b){return _0x7d57df[_0x33ec('0x9')]('OpenchannelMessage',attributes,{'tableName':_0x33ec('0xa'),'paranoid':![],'indexes':[{'name':'fti_openchannel_messages','fields':[_0x33ec('0xb')],'type':_0x33ec('0xc')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x47d037,_0x16a63b,_0x1b8566){var _0x251da9=_0x7d57df['models'];var _0x2e962c=_0x47d037[_0x33ec('0xd')]({'plain':!![]});if(_0x2e962c[_0x33ec('0xe')]['toLowerCase']()==='in'||_0x2e962c[_0x33ec('0xe')][_0x33ec('0xf')]()===_0x33ec('0x10')&&!_0x2e962c[_0x33ec('0x11')]&&!_[_0x33ec('0x12')](_0x2e962c[_0x33ec('0x13')])){_0x251da9[_0x33ec('0x14')][_0x33ec('0x15')]({'where':{'id':_0x2e962c[_0x33ec('0x16')]}})[_0x33ec('0x17')](function(_0x25bc2d){if(_0x25bc2d){_0x25bc2d['update']({'lastMsgAt':_0x2e962c['createdAt'],'lastMsgDirection':_0x2e962c[_0x33ec('0xe')][_0x33ec('0xf')]()});}})['catch'](function(_0x4e52fa){console[_0x33ec('0x18')](_0x4e52fa);});}if(_0x2e962c[_0x33ec('0xe')]===_0x33ec('0x10')&&!_0x2e962c[_0x33ec('0x11')]){var _0xca1c37;_0x251da9[_0x33ec('0x19')][_0x33ec('0x1a')]()[_0x33ec('0x17')](function(_0x5806c5){return _0x251da9['OpenchannelAccount'][_0x33ec('0x1b')]({'where':{'id':_0x2e962c[_0x33ec('0x1c')]},'include':[{'model':_0x251da9[_0x33ec('0x14')],'as':_0x33ec('0x1d'),'where':{'id':_0x2e962c['OpenchannelInteractionId']},'limit':0x1,'include':[{'model':_0x251da9['CmContact'],'as':'Contact','attributes':_[_0x33ec('0x1e')](_0x5806c5)}]}]});})['then'](function(_0x3b28ab){_0xca1c37=_0x3b28ab[_0x33ec('0xd')]({'plain':!![]});if(_0xca1c37&&_0xca1c37[_0x33ec('0x1f')]){logger['info'](_0x33ec('0x20'),_0x33ec('0x21'),util[_0x33ec('0x22')](_0x33ec('0x23'),_0x2e962c['id'],_0xca1c37[_0x33ec('0x1f')]));if(_0xca1c37[_0x33ec('0x1d')]&&_0xca1c37['Interactions'][_0x33ec('0x24')]){_0x2e962c[_0x33ec('0x25')]=_[_0x33ec('0x26')](_0xca1c37[_0x33ec('0x1d')][0x0],_0x33ec('0x27'));_0x2e962c[_0x33ec('0x27')]=_0xca1c37[_0x33ec('0x1d')][0x0][_0x33ec('0x27')];}var _0x16a63b={'method':_0x33ec('0x28'),'uri':encodeURI(_0xca1c37[_0x33ec('0x1f')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x16a63b[_0x33ec('0x29')]){case _0x33ec('0x2a'):_0x16a63b['qs']=_0x2e962c;break;case _0x33ec('0x28'):_0x16a63b['body']=_0x2e962c;break;}return rp(_0x16a63b)[_0x33ec('0x17')](function(_0x3b2a53){logger[_0x33ec('0x2b')](_0x33ec('0x20'),_0x33ec('0x21'),util[_0x33ec('0x22')](_0x33ec('0x2c'),_0x2e962c['id'],_0xca1c37[_0x33ec('0x1f')]));if(_0x3b2a53[_0x33ec('0xb')]['threadId']&&_0x3b2a53[_0x33ec('0xb')][_0x33ec('0x2d')]!=_0x2e962c[_0x33ec('0x25')]['threadId']){return _0x251da9[_0x33ec('0x14')][_0x33ec('0x2e')]({'threadId':_0x3b2a53['body'][_0x33ec('0x2d')]},{'where':{'id':_0x2e962c[_0x33ec('0x25')]['id']}});}else{return;}})[_0x33ec('0x17')](function(){return _0x47d037[_0x33ec('0x2e')]({'read':!![]});})[_0x33ec('0x2f')](function(_0x57ccdf){logger[_0x33ec('0x18')](_0x33ec('0x20'),_0x33ec('0x21'),util[_0x33ec('0x30')](_0x57ccdf,{'showHidden':![],'depth':null}));_0x1b8566();});}else{_0x1b8566();}})[_0x33ec('0x31')](function(){_0x1b8566();});}else{_0x1b8566();}}},'charset':_0x33ec('0x32'),'collate':'utf8mb4_unicode_ci'});};