Built motion from commit 377f727e.|2.6.28
[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 _0x1c93=['find','ids','omit','spread','AddTags','lodash','util','bluebird','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','http','localhost','socket.io-emitter','request','then','WhatsappInteraction,\x20%s,\x20%s','request\x20sent','WhatsappInteraction,\x20%s,\x20%s,\x20%s','stringify','error','code','message','info','result','catch','UpdateWhatsappInteraction','WhatsappInteraction','update','body','options','raw','where','attributes','debug','AddTagsToWhatsappInteraction'];(function(_0x4b4277,_0x22676f){var _0x1ff405=function(_0x2fa9e2){while(--_0x2fa9e2){_0x4b4277['push'](_0x4b4277['shift']());}};_0x1ff405(++_0x22676f);}(_0x1c93,0x16d));var _0x31c9=function(_0x29b30c,_0x4f4b69){_0x29b30c=_0x29b30c-0x0;var _0x3e0cd3=_0x1c93[_0x29b30c];return _0x3e0cd3;};'use strict';var _=require(_0x31c9('0x0'));var util=require(_0x31c9('0x1'));var moment=require('moment');var BPromise=require(_0x31c9('0x2'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x31c9('0x3'));var db=require(_0x31c9('0x4'))['db'];var utils=require(_0x31c9('0x5'));var logger=require(_0x31c9('0x6'))(_0x31c9('0x7'));var config=require(_0x31c9('0x8'));var jayson=require(_0x31c9('0x9'));var client=jayson['client'][_0x31c9('0xa')]({'port':0x232a});config['redis']=_['defaults'](config['redis'],{'host':_0x31c9('0xb'),'port':0x18eb});var socket=require(_0x31c9('0xc'))(new Redis(config['redis']));require('./whatsappInteraction.socket')['register'](socket);function respondWithRpcPromise(_0x33e86c,_0x3760d3,_0x58dc24){return new BPromise(function(_0x248ccc,_0x2e0ee6){return client[_0x31c9('0xd')](_0x33e86c,_0x58dc24)[_0x31c9('0xe')](function(_0x54030f){logger['info'](_0x31c9('0xf'),_0x3760d3,_0x31c9('0x10'));logger['debug'](_0x31c9('0x11'),_0x3760d3,_0x31c9('0x10'),JSON[_0x31c9('0x12')](_0x54030f));if(_0x54030f[_0x31c9('0x13')]){if(_0x54030f[_0x31c9('0x13')][_0x31c9('0x14')]===0x1f4){logger['error']('WhatsappInteraction,\x20%s,\x20%s',_0x3760d3,_0x54030f['error'][_0x31c9('0x15')]);return _0x2e0ee6(_0x54030f['error'][_0x31c9('0x15')]);}logger[_0x31c9('0x13')]('WhatsappInteraction,\x20%s,\x20%s',_0x3760d3,_0x54030f[_0x31c9('0x13')][_0x31c9('0x15')]);return _0x248ccc(_0x54030f['error']['message']);}else{logger[_0x31c9('0x16')](_0x31c9('0xf'),_0x3760d3,_0x31c9('0x10'));_0x248ccc(_0x54030f[_0x31c9('0x17')][_0x31c9('0x15')]);}})[_0x31c9('0x18')](function(_0x4828d1){logger[_0x31c9('0x13')](_0x31c9('0xf'),_0x3760d3,_0x4828d1);_0x2e0ee6(_0x4828d1);});});}exports[_0x31c9('0x19')]=function(_0x472b2c){var _0x3d1b6d=this;return new Promise(function(_0x5564a9,_0x49f5ee){return db[_0x31c9('0x1a')][_0x31c9('0x1b')](_0x472b2c[_0x31c9('0x1c')],{'raw':_0x472b2c['options']?_0x472b2c[_0x31c9('0x1d')][_0x31c9('0x1e')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x472b2c[_0x31c9('0x1d')]?_0x472b2c[_0x31c9('0x1d')][_0x31c9('0x1f')]||null:null,'attributes':_0x472b2c[_0x31c9('0x1d')]?_0x472b2c[_0x31c9('0x1d')][_0x31c9('0x20')]||null:null,'limit':_0x472b2c['options']?_0x472b2c[_0x31c9('0x1d')]['limit']||null:null})[_0x31c9('0xe')](function(_0x5934f8){logger[_0x31c9('0x16')]('UpdateWhatsappInteraction',_0x472b2c);logger[_0x31c9('0x21')](_0x31c9('0x19'),_0x472b2c,JSON['stringify'](_0x5934f8));_0x5564a9(_0x5934f8);})['catch'](function(_0x4eb493){logger[_0x31c9('0x13')]('UpdateWhatsappInteraction',_0x4eb493[_0x31c9('0x15')],_0x472b2c);_0x49f5ee(_0x3d1b6d['error'](0x1f4,_0x4eb493[_0x31c9('0x15')]));});});};exports[_0x31c9('0x22')]=function(_0x35e5ed){return new Promise(function(_0x2af656,_0x308975){return db[_0x31c9('0x1a')][_0x31c9('0x23')]({'where':_0x35e5ed[_0x31c9('0x1d')]?_0x35e5ed[_0x31c9('0x1d')]['where']||null:null})[_0x31c9('0xe')](function(_0x12fa38){if(_0x12fa38){return _0x12fa38['addTags'](_0x35e5ed[_0x31c9('0x1c')][_0x31c9('0x24')],_[_0x31c9('0x25')](_0x35e5ed[_0x31c9('0x1c')],['ids','id'])||{});}})[_0x31c9('0x26')](function(_0xf6a4b0){logger['info'](_0x31c9('0x27'),_0x35e5ed);logger[_0x31c9('0x21')](_0x31c9('0x27'),_0x35e5ed,JSON[_0x31c9('0x12')](_0xf6a4b0));_0x2af656(_0xf6a4b0);})['catch'](function(_0x57b05b){logger[_0x31c9('0x13')](_0x31c9('0x27'),_0x57b05b[_0x31c9('0x15')],_0x35e5ed);_0x308975(_this[_0x31c9('0x13')](0x1f4,_0x57b05b['message']));});});};