Built motion from commit (unavailable).|2.4.18
[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 _0x36ef=['method','GET','body','afterCreate','threadId','Interaction','inspect','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','bluebird','request-promise','path','rimraf','../../config/environment','exports','define','OpenchannelMessage','openchannel_messages','fti_openchannel_messages','FULLTEXT','models','toLowerCase','direction','out','secret','isNil','UserId','OpenchannelInteraction','then','update','catch','error','CmContact','describe','OpenchannelAccount','find','OpenchannelAccountId','Interactions','OpenchannelInteractionId','replyUri','info','OpenchannelMessage,\x20%s,\x20%s','format','Forwarding\x20message\x20%d\x20to\x20%s','length','omit','Contact','POST'];(function(_0x476768,_0x70af63){var _0x5cd65d=function(_0x59d7ec){while(--_0x59d7ec){_0x476768['push'](_0x476768['shift']());}};_0x5cd65d(++_0x70af63);}(_0x36ef,0x1ba));var _0xf36e=function(_0x53d8c9,_0x1cae2e){_0x53d8c9=_0x53d8c9-0x0;var _0x51a939=_0x36ef[_0x53d8c9];return _0x51a939;};'use strict';var _=require(_0xf36e('0x0'));var util=require(_0xf36e('0x1'));var logger=require(_0xf36e('0x2'))(_0xf36e('0x3'));var moment=require(_0xf36e('0x4'));var BPromise=require(_0xf36e('0x5'));var rp=require(_0xf36e('0x6'));var fs=require('fs');var path=require(_0xf36e('0x7'));var rimraf=require(_0xf36e('0x8'));var config=require(_0xf36e('0x9'));var attributes=require('./openchannelMessage.attributes');module[_0xf36e('0xa')]=function(_0x1874ca,_0x1abb7b){return _0x1874ca[_0xf36e('0xb')](_0xf36e('0xc'),attributes,{'tableName':_0xf36e('0xd'),'paranoid':![],'indexes':[{'name':_0xf36e('0xe'),'fields':['body'],'type':_0xf36e('0xf')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x17a882,_0x1896d5,_0x75a33e){var _0x20c6bf=_0x1874ca[_0xf36e('0x10')];var _0x29280e=_0x17a882['get']({'plain':!![]});if(_0x29280e['direction'][_0xf36e('0x11')]()==='in'||_0x29280e[_0xf36e('0x12')]['toLowerCase']()===_0xf36e('0x13')&&!_0x29280e[_0xf36e('0x14')]&&!_[_0xf36e('0x15')](_0x29280e[_0xf36e('0x16')])){_0x20c6bf[_0xf36e('0x17')]['findOne']({'where':{'id':_0x29280e['OpenchannelInteractionId']}})[_0xf36e('0x18')](function(_0x4fa94b){if(_0x4fa94b){_0x4fa94b[_0xf36e('0x19')]({'lastMsgAt':_0x29280e['createdAt'],'lastMsgDirection':_0x29280e[_0xf36e('0x12')][_0xf36e('0x11')]()});}})[_0xf36e('0x1a')](function(_0x57e411){console[_0xf36e('0x1b')](_0x57e411);});}if(_0x29280e[_0xf36e('0x12')]==='out'&&!_0x29280e[_0xf36e('0x14')]){var _0x2e45c8;_0x20c6bf[_0xf36e('0x1c')][_0xf36e('0x1d')]()[_0xf36e('0x18')](function(_0x4d452d){return _0x20c6bf[_0xf36e('0x1e')][_0xf36e('0x1f')]({'where':{'id':_0x29280e[_0xf36e('0x20')]},'include':[{'model':_0x20c6bf[_0xf36e('0x17')],'as':_0xf36e('0x21'),'where':{'id':_0x29280e[_0xf36e('0x22')]},'limit':0x1,'include':[{'model':_0x20c6bf[_0xf36e('0x1c')],'as':'Contact','attributes':_['keys'](_0x4d452d)}]}]});})[_0xf36e('0x18')](function(_0x8b76c2){_0x2e45c8=_0x8b76c2['get']({'plain':!![]});if(_0x2e45c8&&_0x2e45c8[_0xf36e('0x23')]){logger[_0xf36e('0x24')](_0xf36e('0x25'),'afterCreate',util[_0xf36e('0x26')](_0xf36e('0x27'),_0x29280e['id'],_0x2e45c8['replyUri']));if(_0x2e45c8[_0xf36e('0x21')]&&_0x2e45c8[_0xf36e('0x21')][_0xf36e('0x28')]){_0x29280e['Interaction']=_[_0xf36e('0x29')](_0x2e45c8[_0xf36e('0x21')][0x0],'Contact');_0x29280e[_0xf36e('0x2a')]=_0x2e45c8[_0xf36e('0x21')][0x0]['Contact'];}var _0x1896d5={'method':_0xf36e('0x2b'),'uri':encodeURI(_0x2e45c8[_0xf36e('0x23')]),'json':!![],'resolveWithFullResponse':!![]};switch(_0x1896d5[_0xf36e('0x2c')]){case _0xf36e('0x2d'):_0x1896d5['qs']=_0x29280e;break;case _0xf36e('0x2b'):_0x1896d5[_0xf36e('0x2e')]=_0x29280e;break;}return rp(_0x1896d5)[_0xf36e('0x18')](function(_0x30d7a3){logger['info'](_0xf36e('0x25'),_0xf36e('0x2f'),util['format']('Message\x20%d\x20forwarded\x20to\x20%s',_0x29280e['id'],_0x2e45c8[_0xf36e('0x23')]));if(_0x30d7a3[_0xf36e('0x2e')]['threadId']&&_0x30d7a3[_0xf36e('0x2e')][_0xf36e('0x30')]!=_0x29280e['Interaction']['threadId']){return _0x20c6bf[_0xf36e('0x17')]['update']({'threadId':_0x30d7a3['body'][_0xf36e('0x30')]},{'logging':!![],'where':{'id':_0x29280e[_0xf36e('0x31')]['id']}});}else{return;}})[_0xf36e('0x18')](function(){return _0x17a882[_0xf36e('0x19')]({'read':!![]});})[_0xf36e('0x1a')](function(_0x16a473){logger[_0xf36e('0x1b')]('OpenchannelMessage,\x20%s,\x20%s',_0xf36e('0x2f'),util[_0xf36e('0x32')](_0x16a473,{'showHidden':![],'depth':null}));_0x75a33e();});}else{_0x75a33e();}})[_0xf36e('0x33')](function(){_0x75a33e();});}else{_0x75a33e();}}},'charset':_0xf36e('0x34'),'collate':_0xf36e('0x35')});};