ae0becba5c6f30e952ad7570de64329d0c7373c1
[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 _0x19f7=['length','Interaction','omit','Contact','POST','GET','OpenchannelMessage,\x20%s,\x20%s','Message\x20%d\x20forwarded\x20to\x20%s','threadId','inspect','finally','utf8mb4','utf8mb4_unicode_ci','util','../../config/logger','moment','bluebird','request-promise','rimraf','../../config/environment','./openchannelMessage.attributes','exports','define','openchannel_messages','body','FULLTEXT','models','get','direction','toLowerCase','isNil','UserId','OpenchannelInteraction','findOne','OpenchannelInteractionId','then','update','createdAt','catch','error','out','secret','CmContact','describe','OpenchannelAccount','OpenchannelAccountId','keys','replyUri','info','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','Interactions'];(function(_0x21b1c1,_0x4ba63f){var _0x3a181a=function(_0x14a7f1){while(--_0x14a7f1){_0x21b1c1['push'](_0x21b1c1['shift']());}};_0x3a181a(++_0x4ba63f);}(_0x19f7,0x1ea));var _0x719f=function(_0x419f64,_0x82fc7a){_0x419f64=_0x419f64-0x0;var _0x399e39=_0x19f7[_0x419f64];return _0x399e39;};'use strict';var _=require('lodash');var util=require(_0x719f('0x0'));var logger=require(_0x719f('0x1'))('api');var moment=require(_0x719f('0x2'));var BPromise=require(_0x719f('0x3'));var rp=require(_0x719f('0x4'));var fs=require('fs');var path=require('path');var rimraf=require(_0x719f('0x5'));var config=require(_0x719f('0x6'));var attributes=require(_0x719f('0x7'));module[_0x719f('0x8')]=function(_0x5a8a5,_0x4f3f08){return _0x5a8a5[_0x719f('0x9')]('OpenchannelMessage',attributes,{'tableName':_0x719f('0xa'),'paranoid':![],'indexes':[{'name':'fti_openchannel_messages','fields':[_0x719f('0xb')],'type':_0x719f('0xc')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x443815,_0x36bda8,_0x5907b1){var _0xd7ad20=_0x5a8a5[_0x719f('0xd')];var _0x35d479=_0x443815[_0x719f('0xe')]({'plain':!![]});if(_0x35d479[_0x719f('0xf')][_0x719f('0x10')]()==='in'||_0x35d479[_0x719f('0xf')][_0x719f('0x10')]()==='out'&&!_0x35d479['secret']&&!_[_0x719f('0x11')](_0x35d479[_0x719f('0x12')])){_0xd7ad20[_0x719f('0x13')][_0x719f('0x14')]({'where':{'id':_0x35d479[_0x719f('0x15')]}})[_0x719f('0x16')](function(_0xea3a1e){if(_0xea3a1e){_0xea3a1e[_0x719f('0x17')]({'lastMsgAt':_0x35d479[_0x719f('0x18')],'lastMsgDirection':_0x35d479['direction'][_0x719f('0x10')]()});}})[_0x719f('0x19')](function(_0x527311){console[_0x719f('0x1a')](_0x527311);});}if(_0x35d479[_0x719f('0xf')]===_0x719f('0x1b')&&!_0x35d479[_0x719f('0x1c')]){var _0x53301e;_0xd7ad20[_0x719f('0x1d')][_0x719f('0x1e')]()[_0x719f('0x16')](function(_0x1e5006){return _0xd7ad20[_0x719f('0x1f')]['find']({'where':{'id':_0x35d479[_0x719f('0x20')]},'include':[{'model':_0xd7ad20[_0x719f('0x13')],'as':'Interactions','where':{'id':_0x35d479[_0x719f('0x15')]},'limit':0x1,'include':[{'model':_0xd7ad20[_0x719f('0x1d')],'as':'Contact','attributes':_[_0x719f('0x21')](_0x1e5006)}]}]});})['then'](function(_0x51e7cf){_0x53301e=_0x51e7cf['get']({'plain':!![]});if(_0x53301e&&_0x53301e[_0x719f('0x22')]){logger[_0x719f('0x23')]('OpenchannelMessage,\x20%s,\x20%s',_0x719f('0x24'),util[_0x719f('0x25')](_0x719f('0x26'),_0x35d479['id'],_0x53301e['replyUri']));if(_0x53301e[_0x719f('0x27')]&&_0x53301e['Interactions'][_0x719f('0x28')]){_0x35d479[_0x719f('0x29')]=_[_0x719f('0x2a')](_0x53301e[_0x719f('0x27')][0x0],'Contact');_0x35d479[_0x719f('0x2b')]=_0x53301e[_0x719f('0x27')][0x0]['Contact'];}var _0x36bda8={'method':_0x719f('0x2c'),'uri':encodeURI(_0x53301e[_0x719f('0x22')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x36bda8['method']){case _0x719f('0x2d'):_0x36bda8['qs']=_0x35d479;break;case _0x719f('0x2c'):_0x36bda8[_0x719f('0xb')]=_0x35d479;break;}return rp(_0x36bda8)[_0x719f('0x16')](function(_0x25e3b2){logger[_0x719f('0x23')](_0x719f('0x2e'),'afterCreate',util['format'](_0x719f('0x2f'),_0x35d479['id'],_0x53301e[_0x719f('0x22')]));if(_0x25e3b2[_0x719f('0xb')][_0x719f('0x30')]&&_0x25e3b2[_0x719f('0xb')][_0x719f('0x30')]!=_0x35d479[_0x719f('0x29')][_0x719f('0x30')]){return _0xd7ad20[_0x719f('0x13')][_0x719f('0x17')]({'threadId':_0x25e3b2[_0x719f('0xb')][_0x719f('0x30')]},{'where':{'id':_0x35d479[_0x719f('0x29')]['id']}});}else{return;}})[_0x719f('0x16')](function(){return _0x443815[_0x719f('0x17')]({'read':!![]});})[_0x719f('0x19')](function(_0x649ac3){logger['error'](_0x719f('0x2e'),_0x719f('0x24'),util[_0x719f('0x31')](_0x649ac3,{'showHidden':![],'depth':null}));_0x5907b1();});}else{_0x5907b1();}})[_0x719f('0x32')](function(){_0x5907b1();});}else{_0x5907b1();}}},'charset':_0x719f('0x33'),'collate':_0x719f('0x34')});};