7251c0214780a0785c9617c06cbb5ff3a67a33e3
[motion2.git] / server / api / whatsappInteraction / whatsappInteraction.rpc.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 _0x596b=['stringify','util','moment','randomstring','ioredis','../../mysqldb','../../config/logger','../../config/environment','client','http','redis','localhost','socket.io-emitter','./whatsappInteraction.socket','then','info','WhatsappInteraction,\x20%s,\x20%s','request\x20sent','debug','error','code','message','catch','UpdateWhatsappInteraction','WhatsappInteraction','options','where','limit','find','addTags','body','ids','spread','AddTags'];(function(_0x44c0e1,_0x28bfbf){var _0x5a3ba4=function(_0x44730f){while(--_0x44730f){_0x44c0e1['push'](_0x44c0e1['shift']());}};_0x5a3ba4(++_0x28bfbf);}(_0x596b,0xef));var _0xb596=function(_0x462e9d,_0x49a430){_0x462e9d=_0x462e9d-0x0;var _0x5bb599=_0x596b[_0x462e9d];return _0x5bb599;};'use strict';var _=require('lodash');var util=require(_0xb596('0x0'));var moment=require(_0xb596('0x1'));var BPromise=require('bluebird');var rs=require(_0xb596('0x2'));var fs=require('fs');var Redis=require(_0xb596('0x3'));var db=require(_0xb596('0x4'))['db'];var utils=require('../../config/utils');var logger=require(_0xb596('0x5'))('rpc');var config=require(_0xb596('0x6'));var jayson=require('jayson/promise');var client=jayson[_0xb596('0x7')][_0xb596('0x8')]({'port':0x232a});config[_0xb596('0x9')]=_['defaults'](config[_0xb596('0x9')],{'host':_0xb596('0xa'),'port':0x18eb});var socket=require(_0xb596('0xb'))(new Redis(config[_0xb596('0x9')]));require(_0xb596('0xc'))['register'](socket);function respondWithRpcPromise(_0x2897d1,_0x26371f,_0x2e15ce){return new BPromise(function(_0x586a9b,_0x44fc14){return client['request'](_0x2897d1,_0x2e15ce)[_0xb596('0xd')](function(_0x2fa5d2){logger[_0xb596('0xe')](_0xb596('0xf'),_0x26371f,_0xb596('0x10'));logger[_0xb596('0x11')]('WhatsappInteraction,\x20%s,\x20%s,\x20%s',_0x26371f,_0xb596('0x10'),JSON['stringify'](_0x2fa5d2));if(_0x2fa5d2[_0xb596('0x12')]){if(_0x2fa5d2[_0xb596('0x12')][_0xb596('0x13')]===0x1f4){logger['error']('WhatsappInteraction,\x20%s,\x20%s',_0x26371f,_0x2fa5d2[_0xb596('0x12')][_0xb596('0x14')]);return _0x44fc14(_0x2fa5d2[_0xb596('0x12')]['message']);}logger['error']('WhatsappInteraction,\x20%s,\x20%s',_0x26371f,_0x2fa5d2[_0xb596('0x12')][_0xb596('0x14')]);return _0x586a9b(_0x2fa5d2[_0xb596('0x12')]['message']);}else{logger[_0xb596('0xe')]('WhatsappInteraction,\x20%s,\x20%s',_0x26371f,'request\x20sent');_0x586a9b(_0x2fa5d2['result'][_0xb596('0x14')]);}})[_0xb596('0x15')](function(_0x8836d3){logger['error'](_0xb596('0xf'),_0x26371f,_0x8836d3);_0x44fc14(_0x8836d3);});});}exports[_0xb596('0x16')]=function(_0x344e0c){var _0x22a9be=this;return new Promise(function(_0x117709,_0x41f234){return db[_0xb596('0x17')]['update'](_0x344e0c['body'],{'raw':_0x344e0c[_0xb596('0x18')]?_0x344e0c['options']['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x344e0c[_0xb596('0x18')]?_0x344e0c['options'][_0xb596('0x19')]||null:null,'attributes':_0x344e0c[_0xb596('0x18')]?_0x344e0c['options']['attributes']||null:null,'limit':_0x344e0c[_0xb596('0x18')]?_0x344e0c['options'][_0xb596('0x1a')]||null:null})['then'](function(_0x408bdf){logger['info']('UpdateWhatsappInteraction',_0x344e0c);logger[_0xb596('0x11')](_0xb596('0x16'),_0x344e0c,JSON['stringify'](_0x408bdf));_0x117709(_0x408bdf);})[_0xb596('0x15')](function(_0x31f077){logger[_0xb596('0x12')](_0xb596('0x16'),_0x31f077[_0xb596('0x14')],_0x344e0c);_0x41f234(_0x22a9be[_0xb596('0x12')](0x1f4,_0x31f077[_0xb596('0x14')]));});});};exports['AddTagsToWhatsappInteraction']=function(_0x238a36){return new Promise(function(_0x2b7537,_0x41f1df){return db[_0xb596('0x17')][_0xb596('0x1b')]({'where':_0x238a36[_0xb596('0x18')]?_0x238a36[_0xb596('0x18')]['where']||null:null})[_0xb596('0xd')](function(_0x49c799){if(_0x49c799){return _0x49c799[_0xb596('0x1c')](_0x238a36[_0xb596('0x1d')][_0xb596('0x1e')],_['omit'](_0x238a36[_0xb596('0x1d')],['ids','id'])||{});}})[_0xb596('0x1f')](function(_0x387d1a){logger[_0xb596('0xe')](_0xb596('0x20'),_0x238a36);logger[_0xb596('0x11')]('AddTags',_0x238a36,JSON[_0xb596('0x21')](_0x387d1a));_0x2b7537(_0x387d1a);})[_0xb596('0x15')](function(_0x224596){logger['error'](_0xb596('0x20'),_0x224596[_0xb596('0x14')],_0x238a36);_0x41f1df(_this[_0xb596('0x12')](0x1f4,_0x224596[_0xb596('0x14')]));});});};