Built motion from commit d1eab355.|2.6.28
[motion2.git] / server / services / routing / server / applications / dialogflow.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 _0x2e88=['../../rpc/openchannelMessage','../../rpc/smsMessage','../../rpc/faxMessage','consequence','isNil','interaction','UserId','info','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','contact','format','YYYY-MM-DD\x20HH:mm:ss','out','channel','sms','phone','ChatWebsiteId','account','upperFirst','AccountId','InteractionId','created','isEmpty','body','Message','create','then','error','stringify','finally','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!','stop','textRequest','message','dialogflow','result','fulfillment','speech','providerResponse','metadata','endConversation','catch','lodash','moment','apiai-promise','md5','./utils','../../../../config/logger','../../rpc/chatMessage'];(function(_0x25c1bd,_0x2b9085){var _0x1eea5f=function(_0x3b720c){while(--_0x3b720c){_0x25c1bd['push'](_0x25c1bd['shift']());}};_0x1eea5f(++_0x2b9085);}(_0x2e88,0x95));var _0x82e8=function(_0x179e11,_0xf65436){_0x179e11=_0x179e11-0x0;var _0x549f04=_0x2e88[_0x179e11];return _0x549f04;};'use strict';var _=require(_0x82e8('0x0'));var moment=require(_0x82e8('0x1'));var apiai=require(_0x82e8('0x2'));var md5=require(_0x82e8('0x3'));var utils=require(_0x82e8('0x4'));var logger=require(_0x82e8('0x5'))('routing');var rpc={'chatMessage':require(_0x82e8('0x6')),'openchannelMessage':require(_0x82e8('0x7')),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x82e8('0x8')),'faxMessage':require(_0x82e8('0x9')),'whatsappMessage':require('../../rpc/whatsappMessage')};exports[_0x82e8('0xa')]=function(_0x1e2496,_0x3db496){return function(_0x27df44){try{if(!_[_0x82e8('0xb')](this[_0x82e8('0xc')][_0x82e8('0xd')])){logger[_0x82e8('0xe')](_0x82e8('0xf'),_0x1e2496,_0x82e8('0x10'));return _0x27df44[_0x82e8('0x11')]();}var _0x4c6e6a={'ContactId':this[_0x82e8('0x12')]['id'],'sentAt':moment()[_0x82e8('0x13')](_0x82e8('0x14')),'direction':_0x82e8('0x15')};if(this[_0x82e8('0x16')]===_0x82e8('0x17')||this[_0x82e8('0x16')]==='whatsapp'){_0x4c6e6a[_0x82e8('0x18')]=this[_0x82e8('0xc')][_0x82e8('0x18')];}var _0x2cfe6b=this[_0x82e8('0x16')];if(_0x2cfe6b==='chat'){_0x4c6e6a[_0x82e8('0x19')]=this[_0x82e8('0x1a')]['id'];}else{_0x4c6e6a[_[_0x82e8('0x1b')](_0x2cfe6b)+_0x82e8('0x1c')]=this['account']['id'];}_0x4c6e6a[_[_0x82e8('0x1b')](_0x2cfe6b)+_0x82e8('0x1d')]=this[_0x82e8('0xc')]['id'];if(this[_0x82e8('0xc')][_0x82e8('0x1e')]){var _0x541c58=_0x3db496[0x2];if(!_[_0x82e8('0x1f')](_0x541c58)){_0x4c6e6a[_0x82e8('0x20')]=utils['getMustacheRender'](_0x541c58,this);return rpc[_0x2cfe6b+_0x82e8('0x21')][_0x82e8('0x22')](_0x4c6e6a)[_0x82e8('0x23')](function(_0x380f44){logger[_0x82e8('0xe')](_0x82e8('0xf'),_0x1e2496,_0x4c6e6a[_0x82e8('0x20')]);})['catch'](function(_0x31e8dc){logger[_0x82e8('0x24')](_0x82e8('0xf'),_0x1e2496,JSON[_0x82e8('0x25')](_0x31e8dc));})[_0x82e8('0x26')](function(){logger['info'](_0x82e8('0x27'),_0x1e2496);_0x27df44['stop']();});}else{logger[_0x82e8('0xe')](_0x82e8('0x28'),_0x1e2496);_0x27df44[_0x82e8('0x29')]();}}else{var _0x3ab5a2=this;var _0x198c3d=apiai(_0x3db496[0x0],{'language':_0x3db496[0x1]||'en'});return _0x198c3d[_0x82e8('0x2a')](this[_0x82e8('0x2b')]['body'],{'sessionId':md5(this[_0x82e8('0xc')]['id'])})['then'](function(_0x4de0d2){_0x3ab5a2['body'][_0x82e8('0x2c')]=_0x4de0d2;_0x4c6e6a['body']=_0x4de0d2[_0x82e8('0x2d')][_0x82e8('0x2e')][_0x82e8('0x2f')];_0x4c6e6a['providerName']=_0x82e8('0x2c');_0x4c6e6a[_0x82e8('0x30')]=JSON[_0x82e8('0x25')](_0x4de0d2);return rpc[_0x2cfe6b+_0x82e8('0x21')][_0x82e8('0x22')](_0x4c6e6a)['then'](function(_0x55c0d0){logger[_0x82e8('0xe')](_0x82e8('0xf'),_0x1e2496,_0x4c6e6a[_0x82e8('0x20')]);if(_0x4de0d2[_0x82e8('0x2d')][_0x82e8('0x31')][_0x82e8('0x32')]){_0x27df44[_0x82e8('0x11')]();}else{_0x27df44[_0x82e8('0x29')]();}})[_0x82e8('0x33')](function(_0xf52391){logger[_0x82e8('0x24')](_0x82e8('0xf'),_0x1e2496,JSON[_0x82e8('0x25')](_0xf52391));_0x27df44['next']();});})[_0x82e8('0x33')](function(_0x3ff82d){logger[_0x82e8('0x24')](_0x82e8('0xf'),_0x1e2496,_0x3ff82d[_0x82e8('0x2b')]);_0x27df44[_0x82e8('0x11')]();});}}catch(_0x289f08){logger[_0x82e8('0x24')](_0x82e8('0xf'),_0x1e2496,JSON[_0x82e8('0x25')](_0x289f08));_0x27df44[_0x82e8('0x29')]();}};};