Built motion from commit (unavailable).|2.4.4
[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 _0x3626=['GET','POST','info','OpenchannelMessage,\x20%s,\x20%s','Message\x20%d\x20forwarded\x20to\x20%s','threadId','inspect','finally','utf8mb4','utf8mb4_unicode_ci','util','../../config/logger','api','moment','bluebird','path','./openchannelMessage.attributes','exports','define','openchannel_messages','fti_openchannel_messages','body','FULLTEXT','models','get','direction','toLowerCase','secret','isNil','UserId','OpenchannelInteraction','findOne','OpenchannelInteractionId','then','update','createdAt','catch','error','CmContact','describe','OpenchannelAccount','find','OpenchannelAccountId','Interactions','Contact','keys','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','replyUri','Interaction','omit','method'];(function(_0x282bcd,_0x1afec6){var _0x24fb78=function(_0x1a02fc){while(--_0x1a02fc){_0x282bcd['push'](_0x282bcd['shift']());}};_0x24fb78(++_0x1afec6);}(_0x3626,0x113));var _0x6362=function(_0x501510,_0x61caa9){_0x501510=_0x501510-0x0;var _0x1e6ee5=_0x3626[_0x501510];return _0x1e6ee5;};'use strict';var _=require('lodash');var util=require(_0x6362('0x0'));var logger=require(_0x6362('0x1'))(_0x6362('0x2'));var moment=require(_0x6362('0x3'));var BPromise=require(_0x6362('0x4'));var rp=require('request-promise');var fs=require('fs');var path=require(_0x6362('0x5'));var rimraf=require('rimraf');var config=require('../../config/environment');var attributes=require(_0x6362('0x6'));module[_0x6362('0x7')]=function(_0x533e0f,_0x5f1bdf){return _0x533e0f[_0x6362('0x8')]('OpenchannelMessage',attributes,{'tableName':_0x6362('0x9'),'paranoid':![],'indexes':[{'name':_0x6362('0xa'),'fields':[_0x6362('0xb')],'type':_0x6362('0xc')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x2c08fc,_0x2e8698,_0x2c7765){var _0x4eefe6=_0x533e0f[_0x6362('0xd')];var _0x5f0b0d=_0x2c08fc[_0x6362('0xe')]({'plain':!![]});if(_0x5f0b0d[_0x6362('0xf')][_0x6362('0x10')]()==='in'||_0x5f0b0d[_0x6362('0xf')][_0x6362('0x10')]()==='out'&&!_0x5f0b0d[_0x6362('0x11')]&&!_[_0x6362('0x12')](_0x5f0b0d[_0x6362('0x13')])){_0x4eefe6[_0x6362('0x14')][_0x6362('0x15')]({'where':{'id':_0x5f0b0d[_0x6362('0x16')]}})[_0x6362('0x17')](function(_0x1af10e){if(_0x1af10e){_0x1af10e[_0x6362('0x18')]({'lastMsgAt':_0x5f0b0d[_0x6362('0x19')],'lastMsgDirection':_0x5f0b0d[_0x6362('0xf')][_0x6362('0x10')]()});}})[_0x6362('0x1a')](function(_0x523220){console[_0x6362('0x1b')](_0x523220);});}if(_0x5f0b0d[_0x6362('0xf')]==='out'&&!_0x5f0b0d['secret']){var _0xcd4428;_0x4eefe6[_0x6362('0x1c')][_0x6362('0x1d')]()[_0x6362('0x17')](function(_0x303fc4){return _0x4eefe6[_0x6362('0x1e')][_0x6362('0x1f')]({'where':{'id':_0x5f0b0d[_0x6362('0x20')]},'include':[{'model':_0x4eefe6[_0x6362('0x14')],'as':_0x6362('0x21'),'where':{'id':_0x5f0b0d[_0x6362('0x16')]},'limit':0x1,'include':[{'model':_0x4eefe6[_0x6362('0x1c')],'as':_0x6362('0x22'),'attributes':_[_0x6362('0x23')](_0x303fc4)}]}]});})[_0x6362('0x17')](function(_0x34c34f){_0xcd4428=_0x34c34f[_0x6362('0xe')]({'plain':!![]});if(_0xcd4428&&_0xcd4428['replyUri']){logger['info']('OpenchannelMessage,\x20%s,\x20%s',_0x6362('0x24'),util[_0x6362('0x25')](_0x6362('0x26'),_0x5f0b0d['id'],_0xcd4428[_0x6362('0x27')]));if(_0xcd4428['Interactions']&&_0xcd4428['Interactions']['length']){_0x5f0b0d[_0x6362('0x28')]=_[_0x6362('0x29')](_0xcd4428[_0x6362('0x21')][0x0],_0x6362('0x22'));_0x5f0b0d[_0x6362('0x22')]=_0xcd4428['Interactions'][0x0][_0x6362('0x22')];}var _0x2e8698={'method':'POST','uri':encodeURI(_0xcd4428[_0x6362('0x27')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x2e8698[_0x6362('0x2a')]){case _0x6362('0x2b'):_0x2e8698['qs']=_0x5f0b0d;break;case _0x6362('0x2c'):_0x2e8698['body']=_0x5f0b0d;break;}return rp(_0x2e8698)[_0x6362('0x17')](function(_0x5ba884){logger[_0x6362('0x2d')](_0x6362('0x2e'),_0x6362('0x24'),util[_0x6362('0x25')](_0x6362('0x2f'),_0x5f0b0d['id'],_0xcd4428[_0x6362('0x27')]));if(_0x5ba884[_0x6362('0xb')]['threadId']&&_0x5ba884[_0x6362('0xb')][_0x6362('0x30')]!=_0x5f0b0d['Interaction']['threadId']){return _0x4eefe6[_0x6362('0x14')][_0x6362('0x18')]({'threadId':_0x5ba884[_0x6362('0xb')][_0x6362('0x30')]},{'logging':!![],'where':{'id':_0x5f0b0d[_0x6362('0x28')]['id']}});}else{return;}})[_0x6362('0x17')](function(){return _0x2c08fc[_0x6362('0x18')]({'read':!![]});})[_0x6362('0x1a')](function(_0x3e8640){logger[_0x6362('0x1b')](_0x6362('0x2e'),_0x6362('0x24'),util[_0x6362('0x31')](_0x3e8640,{'showHidden':![],'depth':null}));_0x2c7765();});}else{_0x2c7765();}})[_0x6362('0x32')](function(){_0x2c7765();});}else{_0x2c7765();}}},'charset':_0x6362('0x33'),'collate':_0x6362('0x34')});};