Built motion from commit (unavailable).|2.2.0
[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 _0x5a7e=['body','catch','CmContact','OpenchannelAccount','find','OpenchannelInteraction','Interactions','Contact','keys','get','replyUri','OpenchannelMessage,\x20%s,\x20%s','afterCreate','format','length','Interaction','omit','POST','method','GET','info','Message\x20%d\x20forwarded\x20to\x20%s','threadId','error','inspect','finally','utf8mb4','util','api','moment','bluebird','request-promise','./openchannelMessage.attributes','define','openchannel_messages','direction','toLowerCase','out','secret','isNil','UserId','findOne','OpenchannelInteractionId','then','update','createdAt'];(function(_0x501768,_0x4e9ff6){var _0x41e39d=function(_0x8a1bf1){while(--_0x8a1bf1){_0x501768['push'](_0x501768['shift']());}};_0x41e39d(++_0x4e9ff6);}(_0x5a7e,0x1e7));var _0xe5a7=function(_0x24776c,_0xb68f05){_0x24776c=_0x24776c-0x0;var _0xf56739=_0x5a7e[_0x24776c];return _0xf56739;};'use strict';var _=require('lodash');var util=require(_0xe5a7('0x0'));var logger=require('../../config/logger')(_0xe5a7('0x1'));var moment=require(_0xe5a7('0x2'));var BPromise=require(_0xe5a7('0x3'));var rp=require(_0xe5a7('0x4'));var attributes=require(_0xe5a7('0x5'));module['exports']=function(_0x123cc3,_0x15cd9c){return _0x123cc3[_0xe5a7('0x6')]('OpenchannelMessage',attributes,{'tableName':_0xe5a7('0x7'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'afterCreate':function(_0x13f85f,_0x1890e9,_0x1c5963){var _0x122992=_0x123cc3['models'];var _0x1a3ec7=_0x13f85f['get']({'plain':!![]});if(_0x1a3ec7[_0xe5a7('0x8')][_0xe5a7('0x9')]()==='in'||_0x1a3ec7[_0xe5a7('0x8')]['toLowerCase']()===_0xe5a7('0xa')&&!_0x1a3ec7[_0xe5a7('0xb')]&&!_[_0xe5a7('0xc')](_0x1a3ec7[_0xe5a7('0xd')])){_0x122992['OpenchannelInteraction'][_0xe5a7('0xe')]({'where':{'id':_0x1a3ec7[_0xe5a7('0xf')]}})[_0xe5a7('0x10')](function(_0x33182c){if(_0x33182c){_0x33182c[_0xe5a7('0x11')]({'lastMsgAt':_0x1a3ec7[_0xe5a7('0x12')],'lastMsgDirection':_0x1a3ec7[_0xe5a7('0x8')][_0xe5a7('0x9')](),'lastMsgBody':_0x1a3ec7[_0xe5a7('0x13')]});}})[_0xe5a7('0x14')](function(_0xf561e1){console['error'](_0xf561e1);});}if(_0x1a3ec7[_0xe5a7('0x8')]===_0xe5a7('0xa')&&!_0x1a3ec7[_0xe5a7('0xb')]){var _0x59c502;_0x122992[_0xe5a7('0x15')]['describe']()['then'](function(_0x4531e1){return _0x122992[_0xe5a7('0x16')][_0xe5a7('0x17')]({'where':{'id':_0x1a3ec7['OpenchannelAccountId']},'include':[{'model':_0x122992[_0xe5a7('0x18')],'as':_0xe5a7('0x19'),'where':{'id':_0x1a3ec7[_0xe5a7('0xf')]},'limit':0x1,'include':[{'model':_0x122992['CmContact'],'as':_0xe5a7('0x1a'),'attributes':_[_0xe5a7('0x1b')](_0x4531e1)}]}]});})[_0xe5a7('0x10')](function(_0x3c8073){_0x59c502=_0x3c8073[_0xe5a7('0x1c')]({'plain':!![]});if(_0x59c502&&_0x59c502[_0xe5a7('0x1d')]){logger['info'](_0xe5a7('0x1e'),_0xe5a7('0x1f'),util[_0xe5a7('0x20')]('Forwarding\x20message\x20%d\x20to\x20%s',_0x1a3ec7['id'],_0x59c502[_0xe5a7('0x1d')]));if(_0x59c502[_0xe5a7('0x19')]&&_0x59c502[_0xe5a7('0x19')][_0xe5a7('0x21')]){_0x1a3ec7[_0xe5a7('0x22')]=_[_0xe5a7('0x23')](_0x59c502[_0xe5a7('0x19')][0x0],_0xe5a7('0x1a'));_0x1a3ec7[_0xe5a7('0x1a')]=_0x59c502['Interactions'][0x0][_0xe5a7('0x1a')];}var _0x1890e9={'method':_0xe5a7('0x24'),'uri':encodeURI(_0x59c502[_0xe5a7('0x1d')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x1890e9[_0xe5a7('0x25')]){case _0xe5a7('0x26'):_0x1890e9['qs']=_0x1a3ec7;break;case'POST':_0x1890e9[_0xe5a7('0x13')]=_0x1a3ec7;break;}return rp(_0x1890e9)[_0xe5a7('0x10')](function(_0x3a46ad){logger[_0xe5a7('0x27')](_0xe5a7('0x1e'),_0xe5a7('0x1f'),util[_0xe5a7('0x20')](_0xe5a7('0x28'),_0x1a3ec7['id'],_0x59c502['replyUri']));if(_0x3a46ad['body'][_0xe5a7('0x29')]&&_0x3a46ad[_0xe5a7('0x13')][_0xe5a7('0x29')]!=_0x1a3ec7[_0xe5a7('0x22')][_0xe5a7('0x29')]){return _0x122992[_0xe5a7('0x18')][_0xe5a7('0x11')]({'threadId':_0x3a46ad[_0xe5a7('0x13')][_0xe5a7('0x29')]},{'logging':!![],'where':{'id':_0x1a3ec7[_0xe5a7('0x22')]['id']}});}else{return;}})[_0xe5a7('0x10')](function(){return _0x13f85f[_0xe5a7('0x11')]({'read':!![]});})[_0xe5a7('0x14')](function(_0x14c1c7){logger[_0xe5a7('0x2a')](_0xe5a7('0x1e'),_0xe5a7('0x1f'),util[_0xe5a7('0x2b')](_0x14c1c7,{'showHidden':![],'depth':null}));_0x1c5963();});}else{_0x1c5963();}})[_0xe5a7('0x2c')](function(){_0x1c5963();});}else{_0x1c5963();}}},'charset':_0xe5a7('0x2d'),'collate':'utf8mb4_unicode_ci'});};