Built motion from commit 10af8726.|2.6.34
[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 _0xa552=['util','moment','bluebird','ioredis','../../mysqldb','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','localhost','socket.io-emitter','./whatsappInteraction.socket','register','request','then','info','request\x20sent','debug','error','code','WhatsappInteraction,\x20%s,\x20%s','message','result','catch','UpdateWhatsappInteraction','update','body','options','where','attributes','AddTagsToWhatsappInteraction','find','addTags','ids','omit','spread','AddTags','lodash'];(function(_0x2becba,_0x4ea656){var _0x90b5dd=function(_0x26ae2b){while(--_0x26ae2b){_0x2becba['push'](_0x2becba['shift']());}};_0x90b5dd(++_0x4ea656);}(_0xa552,0x147));var _0x2a55=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xa552[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0x2a55('0x0'));var util=require(_0x2a55('0x1'));var moment=require(_0x2a55('0x2'));var BPromise=require(_0x2a55('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x2a55('0x4'));var db=require(_0x2a55('0x5'))['db'];var utils=require('../../config/utils');var logger=require('../../config/logger')(_0x2a55('0x6'));var config=require(_0x2a55('0x7'));var jayson=require(_0x2a55('0x8'));var client=jayson[_0x2a55('0x9')][_0x2a55('0xa')]({'port':0x232a});config[_0x2a55('0xb')]=_[_0x2a55('0xc')](config['redis'],{'host':_0x2a55('0xd'),'port':0x18eb});var socket=require(_0x2a55('0xe'))(new Redis(config['redis']));require(_0x2a55('0xf'))[_0x2a55('0x10')](socket);function respondWithRpcPromise(_0x5ea39b,_0x4d7001,_0xb71862){return new BPromise(function(_0x378ca7,_0x11289c){return client[_0x2a55('0x11')](_0x5ea39b,_0xb71862)[_0x2a55('0x12')](function(_0x1539d8){logger[_0x2a55('0x13')]('WhatsappInteraction,\x20%s,\x20%s',_0x4d7001,_0x2a55('0x14'));logger[_0x2a55('0x15')]('WhatsappInteraction,\x20%s,\x20%s,\x20%s',_0x4d7001,_0x2a55('0x14'),JSON['stringify'](_0x1539d8));if(_0x1539d8['error']){if(_0x1539d8[_0x2a55('0x16')][_0x2a55('0x17')]===0x1f4){logger[_0x2a55('0x16')]('WhatsappInteraction,\x20%s,\x20%s',_0x4d7001,_0x1539d8[_0x2a55('0x16')]['message']);return _0x11289c(_0x1539d8['error']['message']);}logger[_0x2a55('0x16')](_0x2a55('0x18'),_0x4d7001,_0x1539d8[_0x2a55('0x16')]['message']);return _0x378ca7(_0x1539d8[_0x2a55('0x16')][_0x2a55('0x19')]);}else{logger['info'](_0x2a55('0x18'),_0x4d7001,'request\x20sent');_0x378ca7(_0x1539d8[_0x2a55('0x1a')]['message']);}})[_0x2a55('0x1b')](function(_0x145c89){logger[_0x2a55('0x16')]('WhatsappInteraction,\x20%s,\x20%s',_0x4d7001,_0x145c89);_0x11289c(_0x145c89);});});}exports[_0x2a55('0x1c')]=function(_0x24161c){var _0x167385=this;return new Promise(function(_0xc01aa7,_0x4b1cc5){return db['WhatsappInteraction'][_0x2a55('0x1d')](_0x24161c[_0x2a55('0x1e')],{'raw':_0x24161c['options']?_0x24161c[_0x2a55('0x1f')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x24161c[_0x2a55('0x1f')]?_0x24161c[_0x2a55('0x1f')][_0x2a55('0x20')]||null:null,'attributes':_0x24161c['options']?_0x24161c[_0x2a55('0x1f')][_0x2a55('0x21')]||null:null,'limit':_0x24161c[_0x2a55('0x1f')]?_0x24161c[_0x2a55('0x1f')]['limit']||null:null})[_0x2a55('0x12')](function(_0x47d6ff){logger[_0x2a55('0x13')](_0x2a55('0x1c'),_0x24161c);logger[_0x2a55('0x15')](_0x2a55('0x1c'),_0x24161c,JSON['stringify'](_0x47d6ff));_0xc01aa7(_0x47d6ff);})[_0x2a55('0x1b')](function(_0x319944){logger[_0x2a55('0x16')](_0x2a55('0x1c'),_0x319944[_0x2a55('0x19')],_0x24161c);_0x4b1cc5(_0x167385[_0x2a55('0x16')](0x1f4,_0x319944[_0x2a55('0x19')]));});});};exports[_0x2a55('0x22')]=function(_0x43e23d){return new Promise(function(_0x573137,_0x5bca70){return db['WhatsappInteraction'][_0x2a55('0x23')]({'where':_0x43e23d['options']?_0x43e23d[_0x2a55('0x1f')]['where']||null:null})[_0x2a55('0x12')](function(_0x39d1ce){if(_0x39d1ce){return _0x39d1ce[_0x2a55('0x24')](_0x43e23d[_0x2a55('0x1e')][_0x2a55('0x25')],_[_0x2a55('0x26')](_0x43e23d[_0x2a55('0x1e')],[_0x2a55('0x25'),'id'])||{});}})[_0x2a55('0x27')](function(_0x2a83dc){logger[_0x2a55('0x13')](_0x2a55('0x28'),_0x43e23d);logger['debug'](_0x2a55('0x28'),_0x43e23d,JSON['stringify'](_0x2a83dc));_0x573137(_0x2a83dc);})['catch'](function(_0x1a58f4){logger[_0x2a55('0x16')]('AddTags',_0x1a58f4[_0x2a55('0x19')],_0x43e23d);_0x5bca70(_this['error'](0x1f4,_0x1a58f4['message']));});});};