81d76d2da5a72bcc460975c5a29c8cba75081902
[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 _0x83d0=['../../../../config/logger','../../rpc/chatMessage','../../rpc/smsMessage','../../rpc/faxMessage','../../rpc/whatsappMessage','consequence','isNil','interaction','UserId','[%s][DIALOGFLOW]\x20%s','Agent\x20is\x20managing\x20the\x20interaction.\x20Go\x20to\x20next\x20application.','next','format','out','channel','whatsapp','phone','chat','account','upperFirst','InteractionId','body','getMustacheRender','Message','create','then','info','catch','error','stringify','[%s][DIALOGFLOW]\x20Welcome\x20Message\x20has\x20been\x20sent!','textRequest','message','dialogflow','result','fulfillment','speech','providerName','providerResponse','metadata','endConversation','stop','lodash','moment','apiai-promise','md5','./utils'];(function(_0x5dc66b,_0x58b363){var _0x30eb30=function(_0x3988da){while(--_0x3988da){_0x5dc66b['push'](_0x5dc66b['shift']());}};_0x30eb30(++_0x58b363);}(_0x83d0,0xb7));var _0x083d=function(_0x461647,_0x179644){_0x461647=_0x461647-0x0;var _0x521e07=_0x83d0[_0x461647];return _0x521e07;};'use strict';var _=require(_0x083d('0x0'));var moment=require(_0x083d('0x1'));var apiai=require(_0x083d('0x2'));var md5=require(_0x083d('0x3'));var utils=require(_0x083d('0x4'));var logger=require(_0x083d('0x5'))('routing');var rpc={'chatMessage':require(_0x083d('0x6')),'openchannelMessage':require('../../rpc/openchannelMessage'),'mailMessage':require('../../rpc/mailMessage'),'smsMessage':require(_0x083d('0x7')),'faxMessage':require(_0x083d('0x8')),'whatsappMessage':require(_0x083d('0x9'))};exports[_0x083d('0xa')]=function(_0x472c6b,_0x52a3e7){return function(_0x4ec2e7){try{if(!_[_0x083d('0xb')](this[_0x083d('0xc')][_0x083d('0xd')])){logger['info'](_0x083d('0xe'),_0x472c6b,_0x083d('0xf'));return _0x4ec2e7[_0x083d('0x10')]();}var _0xcf2319={'ContactId':this['contact']['id'],'sentAt':moment()[_0x083d('0x11')]('YYYY-MM-DD\x20HH:mm:ss'),'direction':_0x083d('0x12')};if(this[_0x083d('0x13')]==='sms'||this[_0x083d('0x13')]===_0x083d('0x14')){_0xcf2319[_0x083d('0x15')]=this[_0x083d('0xc')][_0x083d('0x15')];}var _0x59fd41=this[_0x083d('0x13')];if(_0x59fd41===_0x083d('0x16')){_0xcf2319['ChatWebsiteId']=this[_0x083d('0x17')]['id'];}else{_0xcf2319[_['upperFirst'](_0x59fd41)+'AccountId']=this[_0x083d('0x17')]['id'];}_0xcf2319[_[_0x083d('0x18')](_0x59fd41)+_0x083d('0x19')]=this[_0x083d('0xc')]['id'];if(this[_0x083d('0xc')]['created']){var _0x2ec521=_0x52a3e7[0x2];if(!_['isEmpty'](_0x2ec521)){_0xcf2319[_0x083d('0x1a')]=utils[_0x083d('0x1b')](_0x2ec521,this);return rpc[_0x59fd41+_0x083d('0x1c')][_0x083d('0x1d')](_0xcf2319)[_0x083d('0x1e')](function(_0x63c0b6){logger[_0x083d('0x1f')](_0x083d('0xe'),_0x472c6b,_0xcf2319[_0x083d('0x1a')]);})[_0x083d('0x20')](function(_0x3ae260){logger[_0x083d('0x21')]('[%s][DIALOGFLOW]\x20%s',_0x472c6b,JSON[_0x083d('0x22')](_0x3ae260));})['finally'](function(){logger[_0x083d('0x1f')](_0x083d('0x23'),_0x472c6b);_0x4ec2e7['stop']();});}else{logger[_0x083d('0x1f')]('[%s][DIALOGFLOW]\x20Welcome\x20Message\x20is\x20empty.\x20It\x20will\x20wait\x20for\x20a\x20message\x20from\x20customer!',_0x472c6b);_0x4ec2e7['stop']();}}else{var _0x59828a=this;var _0xcde93c=apiai(_0x52a3e7[0x0],{'language':_0x52a3e7[0x1]||'en'});return _0xcde93c[_0x083d('0x24')](this[_0x083d('0x25')][_0x083d('0x1a')],{'sessionId':md5(this[_0x083d('0xc')]['id'])})[_0x083d('0x1e')](function(_0x5d8397){_0x59828a[_0x083d('0x1a')][_0x083d('0x26')]=_0x5d8397;_0xcf2319['body']=_0x5d8397[_0x083d('0x27')][_0x083d('0x28')][_0x083d('0x29')];_0xcf2319[_0x083d('0x2a')]=_0x083d('0x26');_0xcf2319[_0x083d('0x2b')]=JSON[_0x083d('0x22')](_0x5d8397);return rpc[_0x59fd41+_0x083d('0x1c')]['create'](_0xcf2319)[_0x083d('0x1e')](function(_0x50e5ae){logger[_0x083d('0x1f')](_0x083d('0xe'),_0x472c6b,_0xcf2319[_0x083d('0x1a')]);if(_0x5d8397[_0x083d('0x27')][_0x083d('0x2c')][_0x083d('0x2d')]){_0x4ec2e7[_0x083d('0x10')]();}else{_0x4ec2e7[_0x083d('0x2e')]();}})[_0x083d('0x20')](function(_0x3f41a4){logger[_0x083d('0x21')](_0x083d('0xe'),_0x472c6b,JSON[_0x083d('0x22')](_0x3f41a4));_0x4ec2e7[_0x083d('0x10')]();});})[_0x083d('0x20')](function(_0x563817){logger[_0x083d('0x21')](_0x083d('0xe'),_0x472c6b,_0x563817['message']);_0x4ec2e7['next']();});}}catch(_0x21a5d9){logger['error'](_0x083d('0xe'),_0x472c6b,JSON['stringify'](_0x21a5d9));_0x4ec2e7[_0x083d('0x2e')]();}};};