Built motion from commit 9d0783e6.|2.6.13
[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 _0x495e=['replyUri','info','afterCreate','format','Forwarding\x20message\x20%d\x20to\x20%s','length','Interaction','omit','method','GET','POST','OpenchannelMessage,\x20%s,\x20%s','Message\x20%d\x20forwarded\x20to\x20%s','threadId','update','inspect','finally','utf8mb4_unicode_ci','lodash','util','api','moment','bluebird','request-promise','path','rimraf','define','OpenchannelMessage','openchannel_messages','fti_openchannel_messages','body','FULLTEXT','models','get','direction','toLowerCase','out','secret','isNil','UserId','OpenchannelInteraction','findOne','OpenchannelInteractionId','then','createdAt','catch','CmContact','find','OpenchannelAccountId','Interactions','Contact','keys'];(function(_0x5f0089,_0x227e2c){var _0x193892=function(_0x24051f){while(--_0x24051f){_0x5f0089['push'](_0x5f0089['shift']());}};_0x193892(++_0x227e2c);}(_0x495e,0x1e6));var _0xe495=function(_0x5c814d,_0x4d81c7){_0x5c814d=_0x5c814d-0x0;var _0x89b71=_0x495e[_0x5c814d];return _0x89b71;};'use strict';var _=require(_0xe495('0x0'));var util=require(_0xe495('0x1'));var logger=require('../../config/logger')(_0xe495('0x2'));var moment=require(_0xe495('0x3'));var BPromise=require(_0xe495('0x4'));var rp=require(_0xe495('0x5'));var fs=require('fs');var path=require(_0xe495('0x6'));var rimraf=require(_0xe495('0x7'));var config=require('../../config/environment');var attributes=require('./openchannelMessage.attributes');module['exports']=function(_0x8c4c03,_0x29e40f){return _0x8c4c03[_0xe495('0x8')](_0xe495('0x9'),attributes,{'tableName':_0xe495('0xa'),'paranoid':![],'indexes':[{'name':_0xe495('0xb'),'fields':[_0xe495('0xc')],'type':_0xe495('0xd')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x2e6dfb,_0x16b6fa,_0x52cf6b){var _0x149c2e=_0x8c4c03[_0xe495('0xe')];var _0x3a45ce=_0x2e6dfb[_0xe495('0xf')]({'plain':!![]});if(_0x3a45ce[_0xe495('0x10')][_0xe495('0x11')]()==='in'||_0x3a45ce['direction'][_0xe495('0x11')]()===_0xe495('0x12')&&!_0x3a45ce[_0xe495('0x13')]&&!_[_0xe495('0x14')](_0x3a45ce[_0xe495('0x15')])){_0x149c2e[_0xe495('0x16')][_0xe495('0x17')]({'where':{'id':_0x3a45ce[_0xe495('0x18')]}})[_0xe495('0x19')](function(_0x38b728){if(_0x38b728){_0x38b728['update']({'lastMsgAt':_0x3a45ce[_0xe495('0x1a')],'lastMsgDirection':_0x3a45ce[_0xe495('0x10')][_0xe495('0x11')]()});}})[_0xe495('0x1b')](function(_0x354524){console['error'](_0x354524);});}if(_0x3a45ce[_0xe495('0x10')]==='out'&&!_0x3a45ce[_0xe495('0x13')]){var _0x28bb5f;_0x149c2e[_0xe495('0x1c')]['describe']()[_0xe495('0x19')](function(_0x12b707){return _0x149c2e['OpenchannelAccount'][_0xe495('0x1d')]({'where':{'id':_0x3a45ce[_0xe495('0x1e')]},'include':[{'model':_0x149c2e[_0xe495('0x16')],'as':_0xe495('0x1f'),'where':{'id':_0x3a45ce[_0xe495('0x18')]},'limit':0x1,'include':[{'model':_0x149c2e[_0xe495('0x1c')],'as':_0xe495('0x20'),'attributes':_[_0xe495('0x21')](_0x12b707)}]}]});})['then'](function(_0x45fd99){_0x28bb5f=_0x45fd99[_0xe495('0xf')]({'plain':!![]});if(_0x28bb5f&&_0x28bb5f[_0xe495('0x22')]){logger[_0xe495('0x23')]('OpenchannelMessage,\x20%s,\x20%s',_0xe495('0x24'),util[_0xe495('0x25')](_0xe495('0x26'),_0x3a45ce['id'],_0x28bb5f[_0xe495('0x22')]));if(_0x28bb5f['Interactions']&&_0x28bb5f['Interactions'][_0xe495('0x27')]){_0x3a45ce[_0xe495('0x28')]=_[_0xe495('0x29')](_0x28bb5f[_0xe495('0x1f')][0x0],_0xe495('0x20'));_0x3a45ce['Contact']=_0x28bb5f[_0xe495('0x1f')][0x0][_0xe495('0x20')];}var _0x16b6fa={'method':'POST','uri':encodeURI(_0x28bb5f[_0xe495('0x22')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x16b6fa[_0xe495('0x2a')]){case _0xe495('0x2b'):_0x16b6fa['qs']=_0x3a45ce;break;case _0xe495('0x2c'):_0x16b6fa['body']=_0x3a45ce;break;}return rp(_0x16b6fa)[_0xe495('0x19')](function(_0x17138a){logger['info'](_0xe495('0x2d'),_0xe495('0x24'),util['format'](_0xe495('0x2e'),_0x3a45ce['id'],_0x28bb5f['replyUri']));if(_0x17138a[_0xe495('0xc')]['threadId']&&_0x17138a['body']['threadId']!=_0x3a45ce[_0xe495('0x28')][_0xe495('0x2f')]){return _0x149c2e[_0xe495('0x16')][_0xe495('0x30')]({'threadId':_0x17138a['body']['threadId']},{'where':{'id':_0x3a45ce[_0xe495('0x28')]['id']}});}else{return;}})['then'](function(){return _0x2e6dfb[_0xe495('0x30')]({'read':!![]});})[_0xe495('0x1b')](function(_0x2a61ca){logger['error'](_0xe495('0x2d'),_0xe495('0x24'),util[_0xe495('0x31')](_0x2a61ca,{'showHidden':![],'depth':null}));_0x52cf6b();});}else{_0x52cf6b();}})[_0xe495('0x32')](function(){_0x52cf6b();});}else{_0x52cf6b();}}},'charset':'utf8mb4','collate':_0xe495('0x33')});};