Built motion from commit (unavailable).|2.5.23
[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 _0xedbf=['describe','OpenchannelAccount','Interactions','Contact','keys','OpenchannelMessage,\x20%s,\x20%s','Forwarding\x20message\x20%d\x20to\x20%s','replyUri','length','Interaction','omit','method','GET','POST','info','afterCreate','format','Message\x20%d\x20forwarded\x20to\x20%s','threadId','utf8mb4','utf8mb4_unicode_ci','../../config/logger','api','bluebird','rimraf','../../config/environment','exports','define','openchannel_messages','body','FULLTEXT','models','get','direction','toLowerCase','UserId','findOne','OpenchannelInteractionId','then','update','createdAt','catch','error','out','secret'];(function(_0x3237a6,_0x288106){var _0x3447fc=function(_0x510480){while(--_0x510480){_0x3237a6['push'](_0x3237a6['shift']());}};_0x3447fc(++_0x288106);}(_0xedbf,0x6f));var _0xfedb=function(_0x244ddb,_0x107a6c){_0x244ddb=_0x244ddb-0x0;var _0x2aa596=_0xedbf[_0x244ddb];return _0x2aa596;};'use strict';var _=require('lodash');var util=require('util');var logger=require(_0xfedb('0x0'))(_0xfedb('0x1'));var moment=require('moment');var BPromise=require(_0xfedb('0x2'));var rp=require('request-promise');var fs=require('fs');var path=require('path');var rimraf=require(_0xfedb('0x3'));var config=require(_0xfedb('0x4'));var attributes=require('./openchannelMessage.attributes');module[_0xfedb('0x5')]=function(_0x2304df,_0x573dff){return _0x2304df[_0xfedb('0x6')]('OpenchannelMessage',attributes,{'tableName':_0xfedb('0x7'),'paranoid':![],'indexes':[{'name':'fti_openchannel_messages','fields':[_0xfedb('0x8')],'type':_0xfedb('0x9')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x41336b,_0x227165,_0x53cfd1){var _0x429f38=_0x2304df[_0xfedb('0xa')];var _0x58fd38=_0x41336b[_0xfedb('0xb')]({'plain':!![]});if(_0x58fd38[_0xfedb('0xc')]['toLowerCase']()==='in'||_0x58fd38[_0xfedb('0xc')][_0xfedb('0xd')]()==='out'&&!_0x58fd38['secret']&&!_['isNil'](_0x58fd38[_0xfedb('0xe')])){_0x429f38['OpenchannelInteraction'][_0xfedb('0xf')]({'where':{'id':_0x58fd38[_0xfedb('0x10')]}})[_0xfedb('0x11')](function(_0x427b18){if(_0x427b18){_0x427b18[_0xfedb('0x12')]({'lastMsgAt':_0x58fd38[_0xfedb('0x13')],'lastMsgDirection':_0x58fd38[_0xfedb('0xc')][_0xfedb('0xd')]()});}})[_0xfedb('0x14')](function(_0xc4fa5b){console[_0xfedb('0x15')](_0xc4fa5b);});}if(_0x58fd38['direction']===_0xfedb('0x16')&&!_0x58fd38[_0xfedb('0x17')]){var _0x124c68;_0x429f38['CmContact'][_0xfedb('0x18')]()['then'](function(_0x3f7896){return _0x429f38[_0xfedb('0x19')]['find']({'where':{'id':_0x58fd38['OpenchannelAccountId']},'include':[{'model':_0x429f38['OpenchannelInteraction'],'as':_0xfedb('0x1a'),'where':{'id':_0x58fd38[_0xfedb('0x10')]},'limit':0x1,'include':[{'model':_0x429f38['CmContact'],'as':_0xfedb('0x1b'),'attributes':_[_0xfedb('0x1c')](_0x3f7896)}]}]});})[_0xfedb('0x11')](function(_0x5b9ea6){_0x124c68=_0x5b9ea6[_0xfedb('0xb')]({'plain':!![]});if(_0x124c68&&_0x124c68['replyUri']){logger['info'](_0xfedb('0x1d'),'afterCreate',util['format'](_0xfedb('0x1e'),_0x58fd38['id'],_0x124c68[_0xfedb('0x1f')]));if(_0x124c68[_0xfedb('0x1a')]&&_0x124c68[_0xfedb('0x1a')][_0xfedb('0x20')]){_0x58fd38[_0xfedb('0x21')]=_[_0xfedb('0x22')](_0x124c68[_0xfedb('0x1a')][0x0],_0xfedb('0x1b'));_0x58fd38['Contact']=_0x124c68[_0xfedb('0x1a')][0x0][_0xfedb('0x1b')];}var _0x227165={'method':'POST','uri':encodeURI(_0x124c68[_0xfedb('0x1f')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x227165[_0xfedb('0x23')]){case _0xfedb('0x24'):_0x227165['qs']=_0x58fd38;break;case _0xfedb('0x25'):_0x227165[_0xfedb('0x8')]=_0x58fd38;break;}return rp(_0x227165)[_0xfedb('0x11')](function(_0x93c759){logger[_0xfedb('0x26')](_0xfedb('0x1d'),_0xfedb('0x27'),util[_0xfedb('0x28')](_0xfedb('0x29'),_0x58fd38['id'],_0x124c68[_0xfedb('0x1f')]));if(_0x93c759['body'][_0xfedb('0x2a')]&&_0x93c759['body'][_0xfedb('0x2a')]!=_0x58fd38[_0xfedb('0x21')][_0xfedb('0x2a')]){return _0x429f38['OpenchannelInteraction']['update']({'threadId':_0x93c759[_0xfedb('0x8')]['threadId']},{'logging':!![],'where':{'id':_0x58fd38[_0xfedb('0x21')]['id']}});}else{return;}})[_0xfedb('0x11')](function(){return _0x41336b[_0xfedb('0x12')]({'read':!![]});})[_0xfedb('0x14')](function(_0x34e740){logger[_0xfedb('0x15')](_0xfedb('0x1d'),_0xfedb('0x27'),util['inspect'](_0x34e740,{'showHidden':![],'depth':null}));_0x53cfd1();});}else{_0x53cfd1();}})['finally'](function(){_0x53cfd1();});}else{_0x53cfd1();}}},'charset':_0xfedb('0x2b'),'collate':_0xfedb('0x2c')});};