Built motion from commit 87cd5f02.|2.5.48
[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 _0x2630=['stringify','error','code','message','result','catch','UpdateWhatsappInteraction','update','body','options','where','attributes','limit','WhatsappInteraction','find','addTags','ids','spread','AddTags','util','bluebird','ioredis','../../mysqldb','../../config/utils','rpc','../../config/environment','defaults','redis','localhost','./whatsappInteraction.socket','register','request','then','info','WhatsappInteraction,\x20%s,\x20%s','request\x20sent','debug','WhatsappInteraction,\x20%s,\x20%s,\x20%s'];(function(_0x9dc6b5,_0x3f542c){var _0x243655=function(_0x357a0e){while(--_0x357a0e){_0x9dc6b5['push'](_0x9dc6b5['shift']());}};_0x243655(++_0x3f542c);}(_0x2630,0xab));var _0x0263=function(_0x5938d2,_0x15cad5){_0x5938d2=_0x5938d2-0x0;var _0x27e9f7=_0x2630[_0x5938d2];return _0x27e9f7;};'use strict';var _=require('lodash');var util=require(_0x0263('0x0'));var moment=require('moment');var BPromise=require(_0x0263('0x1'));var rs=require('randomstring');var fs=require('fs');var Redis=require(_0x0263('0x2'));var db=require(_0x0263('0x3'))['db'];var utils=require(_0x0263('0x4'));var logger=require('../../config/logger')(_0x0263('0x5'));var config=require(_0x0263('0x6'));var jayson=require('jayson/promise');var client=jayson['client']['http']({'port':0x232a});config['redis']=_[_0x0263('0x7')](config[_0x0263('0x8')],{'host':_0x0263('0x9'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x0263('0x8')]));require(_0x0263('0xa'))[_0x0263('0xb')](socket);function respondWithRpcPromise(_0x355792,_0x138e41,_0x3ec1ef){return new BPromise(function(_0x489cfd,_0x48f978){return client[_0x0263('0xc')](_0x355792,_0x3ec1ef)[_0x0263('0xd')](function(_0x29f652){logger[_0x0263('0xe')](_0x0263('0xf'),_0x138e41,_0x0263('0x10'));logger[_0x0263('0x11')](_0x0263('0x12'),_0x138e41,_0x0263('0x10'),JSON[_0x0263('0x13')](_0x29f652));if(_0x29f652['error']){if(_0x29f652[_0x0263('0x14')][_0x0263('0x15')]===0x1f4){logger[_0x0263('0x14')]('WhatsappInteraction,\x20%s,\x20%s',_0x138e41,_0x29f652[_0x0263('0x14')][_0x0263('0x16')]);return _0x48f978(_0x29f652['error'][_0x0263('0x16')]);}logger['error'](_0x0263('0xf'),_0x138e41,_0x29f652[_0x0263('0x14')][_0x0263('0x16')]);return _0x489cfd(_0x29f652[_0x0263('0x14')][_0x0263('0x16')]);}else{logger[_0x0263('0xe')](_0x0263('0xf'),_0x138e41,_0x0263('0x10'));_0x489cfd(_0x29f652[_0x0263('0x17')][_0x0263('0x16')]);}})[_0x0263('0x18')](function(_0x223cea){logger['error'](_0x0263('0xf'),_0x138e41,_0x223cea);_0x48f978(_0x223cea);});});}exports[_0x0263('0x19')]=function(_0x324d31){var _0x1df5cc=this;return new Promise(function(_0x16d336,_0x5afaf6){return db['WhatsappInteraction'][_0x0263('0x1a')](_0x324d31[_0x0263('0x1b')],{'raw':_0x324d31[_0x0263('0x1c')]?_0x324d31[_0x0263('0x1c')]['raw']===undefined?!![]:![]:!![],'individualHooks':!![],'where':_0x324d31['options']?_0x324d31[_0x0263('0x1c')][_0x0263('0x1d')]||null:null,'attributes':_0x324d31[_0x0263('0x1c')]?_0x324d31[_0x0263('0x1c')][_0x0263('0x1e')]||null:null,'limit':_0x324d31['options']?_0x324d31[_0x0263('0x1c')][_0x0263('0x1f')]||null:null})[_0x0263('0xd')](function(_0x3040bc){logger[_0x0263('0xe')]('UpdateWhatsappInteraction',_0x324d31);logger[_0x0263('0x11')](_0x0263('0x19'),_0x324d31,JSON['stringify'](_0x3040bc));_0x16d336(_0x3040bc);})['catch'](function(_0x4047b7){logger[_0x0263('0x14')](_0x0263('0x19'),_0x4047b7[_0x0263('0x16')],_0x324d31);_0x5afaf6(_0x1df5cc['error'](0x1f4,_0x4047b7[_0x0263('0x16')]));});});};exports['AddTagsToWhatsappInteraction']=function(_0x5803a9){return new Promise(function(_0x5b135c,_0x1ecacc){return db[_0x0263('0x20')][_0x0263('0x21')]({'where':_0x5803a9['options']?_0x5803a9[_0x0263('0x1c')][_0x0263('0x1d')]||null:null})[_0x0263('0xd')](function(_0x567dd4){if(_0x567dd4){return _0x567dd4[_0x0263('0x22')](_0x5803a9[_0x0263('0x1b')]['ids'],_['omit'](_0x5803a9[_0x0263('0x1b')],[_0x0263('0x23'),'id'])||{});}})[_0x0263('0x24')](function(_0x130f72){logger['info'](_0x0263('0x25'),_0x5803a9);logger[_0x0263('0x11')]('AddTags',_0x5803a9,JSON[_0x0263('0x13')](_0x130f72));_0x5b135c(_0x130f72);})[_0x0263('0x18')](function(_0x52c89b){logger[_0x0263('0x14')](_0x0263('0x25'),_0x52c89b[_0x0263('0x16')],_0x5803a9);_0x1ecacc(_this[_0x0263('0x14')](0x1f4,_0x52c89b[_0x0263('0x16')]));});});};