Built motion from commit d5e4af8c.|2.6.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 _0x77cf=['format','Forwarding\x20message\x20%d\x20to\x20%s','replyUri','Interaction','Contact','GET','info','OpenchannelMessage,\x20%s,\x20%s','Message\x20%d\x20forwarded\x20to\x20%s','threadId','inspect','utf8mb4','utf8mb4_unicode_ci','lodash','api','moment','bluebird','request-promise','rimraf','../../config/environment','./openchannelMessage.attributes','openchannel_messages','fti_openchannel_messages','body','FULLTEXT','models','toLowerCase','direction','out','isNil','UserId','findOne','OpenchannelInteractionId','then','update','error','secret','CmContact','describe','OpenchannelInteraction','Interactions','keys','get','afterCreate'];(function(_0x4b8920,_0x38e8db){var _0x1665dd=function(_0x4505c2){while(--_0x4505c2){_0x4b8920['push'](_0x4b8920['shift']());}};_0x1665dd(++_0x38e8db);}(_0x77cf,0x65));var _0xf77c=function(_0x4ecaa9,_0x5db383){_0x4ecaa9=_0x4ecaa9-0x0;var _0x19fe6a=_0x77cf[_0x4ecaa9];return _0x19fe6a;};'use strict';var _=require(_0xf77c('0x0'));var util=require('util');var logger=require('../../config/logger')(_0xf77c('0x1'));var moment=require(_0xf77c('0x2'));var BPromise=require(_0xf77c('0x3'));var rp=require(_0xf77c('0x4'));var fs=require('fs');var path=require('path');var rimraf=require(_0xf77c('0x5'));var config=require(_0xf77c('0x6'));var attributes=require(_0xf77c('0x7'));module['exports']=function(_0x416949,_0x2df621){return _0x416949['define']('OpenchannelMessage',attributes,{'tableName':_0xf77c('0x8'),'paranoid':![],'indexes':[{'name':_0xf77c('0x9'),'fields':[_0xf77c('0xa')],'type':_0xf77c('0xb')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x322886,_0x6bff41,_0x1cd727){var _0x5b335e=_0x416949[_0xf77c('0xc')];var _0x3842c1=_0x322886['get']({'plain':!![]});if(_0x3842c1['direction'][_0xf77c('0xd')]()==='in'||_0x3842c1[_0xf77c('0xe')][_0xf77c('0xd')]()===_0xf77c('0xf')&&!_0x3842c1['secret']&&!_[_0xf77c('0x10')](_0x3842c1[_0xf77c('0x11')])){_0x5b335e['OpenchannelInteraction'][_0xf77c('0x12')]({'where':{'id':_0x3842c1[_0xf77c('0x13')]}})[_0xf77c('0x14')](function(_0x23309d){if(_0x23309d){_0x23309d[_0xf77c('0x15')]({'lastMsgAt':_0x3842c1['createdAt'],'lastMsgDirection':_0x3842c1[_0xf77c('0xe')][_0xf77c('0xd')]()});}})['catch'](function(_0x2cf6f9){console[_0xf77c('0x16')](_0x2cf6f9);});}if(_0x3842c1['direction']===_0xf77c('0xf')&&!_0x3842c1[_0xf77c('0x17')]){var _0x37588d;_0x5b335e[_0xf77c('0x18')][_0xf77c('0x19')]()[_0xf77c('0x14')](function(_0x4eac00){return _0x5b335e['OpenchannelAccount']['find']({'where':{'id':_0x3842c1['OpenchannelAccountId']},'include':[{'model':_0x5b335e[_0xf77c('0x1a')],'as':_0xf77c('0x1b'),'where':{'id':_0x3842c1[_0xf77c('0x13')]},'limit':0x1,'include':[{'model':_0x5b335e['CmContact'],'as':'Contact','attributes':_[_0xf77c('0x1c')](_0x4eac00)}]}]});})[_0xf77c('0x14')](function(_0x599642){_0x37588d=_0x599642[_0xf77c('0x1d')]({'plain':!![]});if(_0x37588d&&_0x37588d['replyUri']){logger['info']('OpenchannelMessage,\x20%s,\x20%s',_0xf77c('0x1e'),util[_0xf77c('0x1f')](_0xf77c('0x20'),_0x3842c1['id'],_0x37588d[_0xf77c('0x21')]));if(_0x37588d[_0xf77c('0x1b')]&&_0x37588d[_0xf77c('0x1b')]['length']){_0x3842c1[_0xf77c('0x22')]=_['omit'](_0x37588d['Interactions'][0x0],_0xf77c('0x23'));_0x3842c1['Contact']=_0x37588d[_0xf77c('0x1b')][0x0][_0xf77c('0x23')];}var _0x6bff41={'method':'POST','uri':encodeURI(_0x37588d['replyUri']),'json':!![],'resolveWithFullResponse':!![]};switch(_0x6bff41['method']){case _0xf77c('0x24'):_0x6bff41['qs']=_0x3842c1;break;case'POST':_0x6bff41['body']=_0x3842c1;break;}return rp(_0x6bff41)[_0xf77c('0x14')](function(_0x3ef1ba){logger[_0xf77c('0x25')](_0xf77c('0x26'),'afterCreate',util[_0xf77c('0x1f')](_0xf77c('0x27'),_0x3842c1['id'],_0x37588d[_0xf77c('0x21')]));if(_0x3ef1ba['body']['threadId']&&_0x3ef1ba['body'][_0xf77c('0x28')]!=_0x3842c1[_0xf77c('0x22')]['threadId']){return _0x5b335e['OpenchannelInteraction'][_0xf77c('0x15')]({'threadId':_0x3ef1ba['body']['threadId']},{'where':{'id':_0x3842c1[_0xf77c('0x22')]['id']}});}else{return;}})[_0xf77c('0x14')](function(){return _0x322886[_0xf77c('0x15')]({'read':!![]});})['catch'](function(_0x51f1f8){logger[_0xf77c('0x16')](_0xf77c('0x26'),_0xf77c('0x1e'),util[_0xf77c('0x29')](_0x51f1f8,{'showHidden':![],'depth':null}));_0x1cd727();});}else{_0x1cd727();}})['finally'](function(){_0x1cd727();});}else{_0x1cd727();}}},'charset':_0xf77c('0x2a'),'collate':_0xf77c('0x2b')});};