ce778c422a95ec4fbe69df24e44a0467c2650355
[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 _0x955f=['openchannel_messages','body','FULLTEXT','models','get','toLowerCase','direction','secret','UserId','findOne','OpenchannelInteractionId','then','update','createdAt','catch','CmContact','describe','OpenchannelAccount','find','OpenchannelAccountId','Interactions','Contact','keys','replyUri','OpenchannelMessage,\x20%s,\x20%s','format','Forwarding\x20message\x20%d\x20to\x20%s','Interaction','omit','POST','method','GET','info','afterCreate','Message\x20%d\x20forwarded\x20to\x20%s','threadId','OpenchannelInteraction','error','inspect','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','request-promise','../../config/environment','exports','OpenchannelMessage'];(function(_0x456fb1,_0x859a1d){var _0x4083d6=function(_0xe1d0f2){while(--_0xe1d0f2){_0x456fb1['push'](_0x456fb1['shift']());}};_0x4083d6(++_0x859a1d);}(_0x955f,0x1eb));var _0xf955=function(_0x220e18,_0x1bd108){_0x220e18=_0x220e18-0x0;var _0x3a8474=_0x955f[_0x220e18];return _0x3a8474;};'use strict';var _=require(_0xf955('0x0'));var util=require(_0xf955('0x1'));var logger=require(_0xf955('0x2'))(_0xf955('0x3'));var moment=require(_0xf955('0x4'));var BPromise=require('bluebird');var rp=require(_0xf955('0x5'));var fs=require('fs');var path=require('path');var rimraf=require('rimraf');var config=require(_0xf955('0x6'));var attributes=require('./openchannelMessage.attributes');module[_0xf955('0x7')]=function(_0x2caff2,_0x3fdac2){return _0x2caff2['define'](_0xf955('0x8'),attributes,{'tableName':_0xf955('0x9'),'paranoid':![],'indexes':[{'name':'fti_openchannel_messages','fields':[_0xf955('0xa')],'type':_0xf955('0xb')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x168ffb,_0x38b190,_0x134c1b){var _0x421e4a=_0x2caff2[_0xf955('0xc')];var _0x4d213a=_0x168ffb[_0xf955('0xd')]({'plain':!![]});if(_0x4d213a['direction'][_0xf955('0xe')]()==='in'||_0x4d213a[_0xf955('0xf')][_0xf955('0xe')]()==='out'&&!_0x4d213a[_0xf955('0x10')]&&!_['isNil'](_0x4d213a[_0xf955('0x11')])){_0x421e4a['OpenchannelInteraction'][_0xf955('0x12')]({'where':{'id':_0x4d213a[_0xf955('0x13')]}})[_0xf955('0x14')](function(_0x109bc5){if(_0x109bc5){_0x109bc5[_0xf955('0x15')]({'lastMsgAt':_0x4d213a[_0xf955('0x16')],'lastMsgDirection':_0x4d213a[_0xf955('0xf')][_0xf955('0xe')]()});}})[_0xf955('0x17')](function(_0x24e75c){console['error'](_0x24e75c);});}if(_0x4d213a[_0xf955('0xf')]==='out'&&!_0x4d213a[_0xf955('0x10')]){var _0x3a814f;_0x421e4a[_0xf955('0x18')][_0xf955('0x19')]()['then'](function(_0x5ac6cb){return _0x421e4a[_0xf955('0x1a')][_0xf955('0x1b')]({'where':{'id':_0x4d213a[_0xf955('0x1c')]},'include':[{'model':_0x421e4a['OpenchannelInteraction'],'as':_0xf955('0x1d'),'where':{'id':_0x4d213a[_0xf955('0x13')]},'limit':0x1,'include':[{'model':_0x421e4a[_0xf955('0x18')],'as':_0xf955('0x1e'),'attributes':_[_0xf955('0x1f')](_0x5ac6cb)}]}]});})['then'](function(_0x17d86a){_0x3a814f=_0x17d86a[_0xf955('0xd')]({'plain':!![]});if(_0x3a814f&&_0x3a814f[_0xf955('0x20')]){logger['info'](_0xf955('0x21'),'afterCreate',util[_0xf955('0x22')](_0xf955('0x23'),_0x4d213a['id'],_0x3a814f[_0xf955('0x20')]));if(_0x3a814f[_0xf955('0x1d')]&&_0x3a814f[_0xf955('0x1d')]['length']){_0x4d213a[_0xf955('0x24')]=_[_0xf955('0x25')](_0x3a814f[_0xf955('0x1d')][0x0],_0xf955('0x1e'));_0x4d213a[_0xf955('0x1e')]=_0x3a814f[_0xf955('0x1d')][0x0][_0xf955('0x1e')];}var _0x38b190={'method':_0xf955('0x26'),'uri':encodeURI(_0x3a814f[_0xf955('0x20')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x38b190[_0xf955('0x27')]){case _0xf955('0x28'):_0x38b190['qs']=_0x4d213a;break;case _0xf955('0x26'):_0x38b190[_0xf955('0xa')]=_0x4d213a;break;}return rp(_0x38b190)[_0xf955('0x14')](function(_0x51f3ab){logger[_0xf955('0x29')](_0xf955('0x21'),_0xf955('0x2a'),util[_0xf955('0x22')](_0xf955('0x2b'),_0x4d213a['id'],_0x3a814f[_0xf955('0x20')]));if(_0x51f3ab['body'][_0xf955('0x2c')]&&_0x51f3ab[_0xf955('0xa')]['threadId']!=_0x4d213a[_0xf955('0x24')][_0xf955('0x2c')]){return _0x421e4a[_0xf955('0x2d')][_0xf955('0x15')]({'threadId':_0x51f3ab['body'][_0xf955('0x2c')]},{'logging':!![],'where':{'id':_0x4d213a['Interaction']['id']}});}else{return;}})[_0xf955('0x14')](function(){return _0x168ffb[_0xf955('0x15')]({'read':!![]});})[_0xf955('0x17')](function(_0x4069fe){logger[_0xf955('0x2e')](_0xf955('0x21'),_0xf955('0x2a'),util[_0xf955('0x2f')](_0x4069fe,{'showHidden':![],'depth':null}));_0x134c1b();});}else{_0x134c1b();}})['finally'](function(){_0x134c1b();});}else{_0x134c1b();}}},'charset':_0xf955('0x30'),'collate':_0xf955('0x31')});};