1aa6fd9eb1ca57e8b3d19418ef84f69cc50cbe26
[motion2.git] / server / api / whatsappMessage / whatsappMessage.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 _0xf26c=['info','catch','CreateWhatsappMessage','WhatsappMessage','create','body','options','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','defaults','redis','socket.io-emitter','./whatsappMessage.socket','register','request','then','request\x20sent','debug','stringify','WhatsappMessage,\x20%s,\x20%s','error','message'];(function(_0x3c86dc,_0x5d22fc){var _0x4aeb79=function(_0x29d7c8){while(--_0x29d7c8){_0x3c86dc['push'](_0x3c86dc['shift']());}};_0x4aeb79(++_0x5d22fc);}(_0xf26c,0xa2));var _0xcf26=function(_0x23a2e3,_0x2531db){_0x23a2e3=_0x23a2e3-0x0;var _0x507ffa=_0xf26c[_0x23a2e3];return _0x507ffa;};'use strict';var _=require('lodash');var util=require('util');var moment=require(_0xcf26('0x0'));var BPromise=require(_0xcf26('0x1'));var rs=require(_0xcf26('0x2'));var fs=require('fs');var Redis=require(_0xcf26('0x3'));var db=require(_0xcf26('0x4'))['db'];var utils=require(_0xcf26('0x5'));var logger=require(_0xcf26('0x6'))(_0xcf26('0x7'));var config=require(_0xcf26('0x8'));var jayson=require(_0xcf26('0x9'));var client=jayson[_0xcf26('0xa')]['http']({'port':0x232a});config['redis']=_[_0xcf26('0xb')](config[_0xcf26('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0xcf26('0xd'))(new Redis(config[_0xcf26('0xc')]));require(_0xcf26('0xe'))[_0xcf26('0xf')](socket);function respondWithRpcPromise(_0x1541a1,_0x304c32,_0x1748cb){return new BPromise(function(_0x4dd64a,_0x504fa1){return client[_0xcf26('0x10')](_0x1541a1,_0x1748cb)[_0xcf26('0x11')](function(_0xa6c2f6){logger['info']('WhatsappMessage,\x20%s,\x20%s',_0x304c32,_0xcf26('0x12'));logger[_0xcf26('0x13')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x304c32,_0xcf26('0x12'),JSON[_0xcf26('0x14')](_0xa6c2f6));if(_0xa6c2f6['error']){if(_0xa6c2f6['error']['code']===0x1f4){logger['error'](_0xcf26('0x15'),_0x304c32,_0xa6c2f6[_0xcf26('0x16')][_0xcf26('0x17')]);return _0x504fa1(_0xa6c2f6[_0xcf26('0x16')][_0xcf26('0x17')]);}logger[_0xcf26('0x16')]('WhatsappMessage,\x20%s,\x20%s',_0x304c32,_0xa6c2f6[_0xcf26('0x16')][_0xcf26('0x17')]);return _0x4dd64a(_0xa6c2f6['error']['message']);}else{logger[_0xcf26('0x18')](_0xcf26('0x15'),_0x304c32,_0xcf26('0x12'));_0x4dd64a(_0xa6c2f6['result'][_0xcf26('0x17')]);}})[_0xcf26('0x19')](function(_0x1657c){logger[_0xcf26('0x16')](_0xcf26('0x15'),_0x304c32,_0x1657c);_0x504fa1(_0x1657c);});});}exports[_0xcf26('0x1a')]=function(_0x5c0c2e){var _0x383f53=this;return new Promise(function(_0x20418c,_0x4cf0e5){return db[_0xcf26('0x1b')][_0xcf26('0x1c')](_0x5c0c2e[_0xcf26('0x1d')],{'raw':_0x5c0c2e[_0xcf26('0x1e')]?_0x5c0c2e['options']['raw']===undefined?!![]:![]:!![]})[_0xcf26('0x11')](function(_0x17fc76){logger['info'](_0xcf26('0x1a'),_0x5c0c2e);logger[_0xcf26('0x13')]('CreateWhatsappMessage',_0x5c0c2e,JSON[_0xcf26('0x14')](_0x17fc76));_0x20418c(_0x17fc76);})[_0xcf26('0x19')](function(_0xa41b0d){logger[_0xcf26('0x16')](_0xcf26('0x1a'),_0xa41b0d['message'],_0x5c0c2e);_0x4cf0e5(_0x383f53[_0xcf26('0x16')](0x1f4,_0xa41b0d[_0xcf26('0x17')]));});});};