2fb53806cae333fa6d403ffcc8a8e6eba7a8ae9b
[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 _0x18eb=['WhatsappInteraction,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','WhatsappInteraction,\x20%s,\x20%s','message','catch','WhatsappInteraction','update','body','raw','options','where','attributes','limit','UpdateWhatsappInteraction','debug','find','addTags','ids','omit','spread','AddTags','lodash','bluebird','randomstring','ioredis','../../config/logger','../../config/environment','client','http','redis','register','then','info'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x18eb,0x1a4));var _0xb18e=function(_0x5c589f,_0xe758a9){_0x5c589f=_0x5c589f-0x0;var _0x110034=_0x18eb[_0x5c589f];return _0x110034;};'use strict';var _=require(_0xb18e('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0xb18e('0x1'));var rs=require(_0xb18e('0x2'));var fs=require('fs');var Redis=require(_0xb18e('0x3'));var db=require('../../mysqldb')['db'];var utils=require('../../config/utils');var logger=require(_0xb18e('0x4'))('rpc');var config=require(_0xb18e('0x5'));var jayson=require('jayson/promise');var client=jayson[_0xb18e('0x6')][_0xb18e('0x7')]({'port':0x232a});config[_0xb18e('0x8')]=_['defaults'](config[_0xb18e('0x8')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xb18e('0x8')]));require('./whatsappInteraction.socket')[_0xb18e('0x9')](socket);function respondWithRpcPromise(_0x2a9adb,_0x5a4fcd,_0x4c00ff){return new BPromise(function(_0x5aef45,_0x55a35f){return client['request'](_0x2a9adb,_0x4c00ff)[_0xb18e('0xa')](function(_0x566a38){logger[_0xb18e('0xb')]('WhatsappInteraction,\x20%s,\x20%s',_0x5a4fcd,'request\x20sent');logger['debug'](_0xb18e('0xc'),_0x5a4fcd,_0xb18e('0xd'),JSON[_0xb18e('0xe')](_0x566a38));if(_0x566a38[_0xb18e('0xf')]){if(_0x566a38[_0xb18e('0xf')][_0xb18e('0x10')]===0x1f4){logger[_0xb18e('0xf')](_0xb18e('0x11'),_0x5a4fcd,_0x566a38[_0xb18e('0xf')][_0xb18e('0x12')]);return _0x55a35f(_0x566a38[_0xb18e('0xf')][_0xb18e('0x12')]);}logger[_0xb18e('0xf')]('WhatsappInteraction,\x20%s,\x20%s',_0x5a4fcd,_0x566a38[_0xb18e('0xf')]['message']);return _0x5aef45(_0x566a38[_0xb18e('0xf')][_0xb18e('0x12')]);}else{logger[_0xb18e('0xb')](_0xb18e('0x11'),_0x5a4fcd,_0xb18e('0xd'));_0x5aef45(_0x566a38['result'][_0xb18e('0x12')]);}})[_0xb18e('0x13')](function(_0x64fd39){logger[_0xb18e('0xf')]('WhatsappInteraction,\x20%s,\x20%s',_0x5a4fcd,_0x64fd39);_0x55a35f(_0x64fd39);});});}exports['UpdateWhatsappInteraction']=function(_0x221557){var _0x26ae8e=this;return new Promise(function(_0x54f6c0,_0x384603){return db[_0xb18e('0x14')][_0xb18e('0x15')](_0x221557[_0xb18e('0x16')],{'raw':_0x221557['options']?_0x221557['options'][_0xb18e('0x17')]===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x221557[_0xb18e('0x18')]?_0x221557['options'][_0xb18e('0x19')]||null:null,'attributes':_0x221557[_0xb18e('0x18')]?_0x221557[_0xb18e('0x18')][_0xb18e('0x1a')]||null:null,'limit':_0x221557[_0xb18e('0x18')]?_0x221557['options'][_0xb18e('0x1b')]||null:null})[_0xb18e('0xa')](function(_0x5e156b){logger[_0xb18e('0xb')](_0xb18e('0x1c'),_0x221557);logger[_0xb18e('0x1d')](_0xb18e('0x1c'),_0x221557,JSON['stringify'](_0x5e156b));_0x54f6c0(_0x5e156b);})['catch'](function(_0x359459){logger[_0xb18e('0xf')](_0xb18e('0x1c'),_0x359459['message'],_0x221557);_0x384603(_0x26ae8e[_0xb18e('0xf')](0x1f4,_0x359459[_0xb18e('0x12')]));});});};exports['AddTagsToWhatsappInteraction']=function(_0x490019){return new Promise(function(_0x1aa3f7,_0x2eb7a2){return db['WhatsappInteraction'][_0xb18e('0x1e')]({'where':_0x490019['options']?_0x490019[_0xb18e('0x18')]['where']||null:null})['then'](function(_0x8caf10){if(_0x8caf10){return _0x8caf10[_0xb18e('0x1f')](_0x490019['body'][_0xb18e('0x20')],_[_0xb18e('0x21')](_0x490019[_0xb18e('0x16')],['ids','id'])||{});}})[_0xb18e('0x22')](function(_0x9bc28d){logger[_0xb18e('0xb')]('AddTags',_0x490019);logger[_0xb18e('0x1d')]('AddTags',_0x490019,JSON[_0xb18e('0xe')](_0x9bc28d));_0x1aa3f7(_0x9bc28d);})[_0xb18e('0x13')](function(_0x4b7cad){logger[_0xb18e('0xf')](_0xb18e('0x23'),_0x4b7cad[_0xb18e('0x12')],_0x490019);_0x2eb7a2(_this['error'](0x1f4,_0x4b7cad['message']));});});};