Built motion from commit 26d08302.|2.6.31
[motion2.git] / server / services / agi / channel.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 _0xe604=['line','hangup','emit','substring','search','function','indexOf','substr','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','command','inherits','prototype','sendRequest','sync','answer','getData','beep','format','noop','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','isArray','join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isBoolean','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','setPriority','GOTO\x20%s\x20%s\x20%s','getVariable','GET\x20VARIABLE\x20\x22%s\x22','recordFile','wav','BEEP','RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s','streamFile','agi','AGI','util','./error','call','setEncoding','utf8','headers','ready'];(function(_0x3bf83f,_0x181cac){var _0x22c4a9=function(_0xb3ff0d){while(--_0xb3ff0d){_0x3bf83f['push'](_0x3bf83f['shift']());}};_0x22c4a9(++_0x181cac);}(_0xe604,0x101));var _0x4e60=function(_0x195e75,_0x3271d1){_0x195e75=_0x195e75-0x0;var _0x5ca017=_0xe604[_0x195e75];return _0x5ca017;};'use strict';var util=require(_0x4e60('0x0'));var _=require('lodash');var EventEmitter=require('events')['EventEmitter'];var AGIReply=require('./reply');var AGIError=require(_0x4e60('0x1'));function AGIChannel(_0x292759){var _0x23df4d=this,_0x4288c0=new AGIReply(),_0x511ab9=![],_0x56c300={};EventEmitter[_0x4e60('0x2')](_0x23df4d);_0x292759[_0x4e60('0x3')](_0x4e60('0x4'));_0x292759['setTimeout'](0x8*0x3c*0x3c*0x3e8);_0x4288c0[_0x4e60('0x3')](_0x4e60('0x4'));_0x4288c0['on'](_0x4e60('0x5'),function(_0x4700a8){for(var _0x90559 in _0x4700a8){_0x23df4d[_0x90559]=_0x4700a8[_0x90559];}_0x23df4d['emit'](_0x4e60('0x6'));});_0x4288c0['on'](_0x4e60('0x7'),function(_0x5d88ad){if(_0x5d88ad['toLowerCase']()==_0x4e60('0x8')){_0x23df4d[_0x4e60('0x9')](_0x4e60('0x8'));return;}if(_0x5d88ad[_0x4e60('0xa')](0x0,0xb)=='520-Invalid'){_0x511ab9=!![];}if(_0x511ab9){_0x56c300['rx']+=_0x5d88ad+'\x0a';if(_0x5d88ad[_0x4e60('0xb')]('520\x20End\x20of\x20proper')!=-0x1){_0x511ab9=![];}}else{_0x56c300['rx']=_0x5d88ad;}if(_0x511ab9){return;}if(typeof _0x56c300['cb']==_0x4e60('0xc')){var _0x54a1ac=_0x56c300['rx'][_0x4e60('0xa')](0x0,0x3),_0x5672ac=null,_0x563c42=null;_0x54a1ac=parseInt(_0x54a1ac);if(isNaN(_0x54a1ac)){_0x56c300['cb'](null,{'code':0x1f4,'result':-0x1,'extra':'no\x20code'});return;}if(_0x54a1ac!=0xc8){_0x56c300['cb'](null,{'code':_0x54a1ac,'result':-0x1,'extra':'KO'});return;}_0x5672ac=_0x56c300['rx'][_0x4e60('0xa')](0x4)['replace']('result=','');if(_0x5672ac[_0x4e60('0xd')]('\x20')!=-0x1){_0x5672ac=_0x5672ac[_0x4e60('0xe')](0x0,_0x5672ac['indexOf']('\x20'));}if(_[_0x4e60('0xf')](_0x5672ac,'-1')){_0x5672ac=parseInt(_0x5672ac);}_0x563c42=_0x56c300['rx'][_0x4e60('0x10')]('\x20');if(_0x563c42['length']==0x3){_0x563c42=_0x563c42[0x2][_0x4e60('0xa')](0x1,_0x563c42[0x2][_0x4e60('0x11')]-0x1);}else if(_0x563c42['length']>0x3){var _0x4c9709=/\((.+)\)/;var _0x28d04b=_0x56c300['rx'][_0x4e60('0x12')](_0x4c9709);if(_0x28d04b){_0x563c42=_0x28d04b[0x1];}else{_0x563c42=null;}}else{_0x563c42=null;}_0x56c300['cb'](null,{'code':_0x54a1ac,'result':_0x5672ac,'extra':_0x563c42});}});_0x292759['on'](_0x4e60('0x13'),function(_0x5ef6bd){_0x23df4d[_0x4e60('0x9')]('error',new AGIError(_0x4e60('0x14'),_0x5ef6bd[_0x4e60('0x15')]));});_0x292759['on'](_0x4e60('0x16'),function(){_0x23df4d[_0x4e60('0x9')](_0x4e60('0x16'),new AGIError(_0x4e60('0x17')));});_0x292759['on'](_0x4e60('0x18'),function(){_0x23df4d[_0x4e60('0x9')]('timeout',new AGIError(_0x4e60('0x19')));_0x292759[_0x4e60('0x1a')]();});_0x292759['pipe'](_0x4288c0);this[_0x4e60('0x1b')]=function(_0x29394d,_0x3857c3){var _0x29394d=_0x29394d||'',_0x3857c3=typeof _0x3857c3==_0x4e60('0xc')?_0x3857c3:new Function();_0x56c300={'tx':_0x29394d,'rx':'','cb':_0x3857c3};_0x292759['write'](_0x29394d+'\x0a');},this[_0x4e60('0x16')]=function(){_0x292759[_0x4e60('0x1a')]();};}util[_0x4e60('0x1c')](AGIChannel,EventEmitter);AGIChannel[_0x4e60('0x1d')][_0x4e60('0x1e')]=function(_0xccac84){return this[_0x4e60('0x1b')][_0x4e60('0x1f')](this,_0xccac84);};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x20')]=function(){return this['sendRequest']('ANSWER');};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x21')]=function(_0x5d3ada,_0x5bd778,_0x28d11f){_0x5d3ada=_0x5d3ada===undefined?_0x4e60('0x22'):_0x5d3ada;_0x5bd778=_0x5bd778===undefined?'5':_0x5bd778;_0x28d11f=_0x28d11f===undefined?'1':_0x28d11f;return this[_0x4e60('0x1e')](util[_0x4e60('0x23')]('GET\x20DATA\x20\x22%s\x22\x20%s\x20%s',_0x5d3ada,_0x5bd778*0x3e8,_0x28d11f));};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x24')]=function(_0x4e145a){_0x4e145a=_0x4e145a||_0x4e60('0x25');return this[_0x4e60('0x1e')](util['format'](_0x4e60('0x26'),_0x4e145a));};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x27')]=function(_0x2f359d,_0x2d121c){if(_[_0x4e60('0x28')](_0x2d121c)){return this['sendRequest'](util['format']('EXEC\x20%s\x20%s',_0x2f359d,_0x2d121c[_0x4e60('0x29')](',')));}return this['sendRequest'](util[_0x4e60('0x23')]('EXEC\x20%s\x20%s',_0x2f359d,_0x2d121c));};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x2a')]=function(_0x356294){return this['sendRequest'](util[_0x4e60('0x23')](_0x4e60('0x2b'),_0x356294));};AGIChannel['prototype'][_0x4e60('0x2c')]=function(_0x33bd8a){return this['sendRequest'](util['format']('SET\x20EXTENSION\x20%s',_0x33bd8a));};AGIChannel[_0x4e60('0x1d')]['setPriority']=function(_0x27e837){return this[_0x4e60('0x1e')](util[_0x4e60('0x23')](_0x4e60('0x2d'),_0x27e837));};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x8')]=function(){return this[_0x4e60('0x1e')](_0x4e60('0x2e'));};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x2f')]=function(_0x3b7716,_0x1c40b4){var _0x4ca6bf=_[_0x4e60('0x30')](_0x1c40b4)||_['isNumber'](_0x1c40b4)?_0x1c40b4['toString']():_0x1c40b4;return this['sendRequest'](util['format']('SET\x20VARIABLE\x20%s\x20\x22%s\x22',_0x3b7716,_0x4ca6bf?_0x4ca6bf[_0x4e60('0x31')]()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x32')]=function(_0x3d6e56,_0x3586c5){return this[_0x4e60('0x1e')](util[_0x4e60('0x23')](_0x4e60('0x33'),_0x3d6e56,_0x3586c5));};AGIChannel['prototype'][_0x4e60('0x34')]=function(_0xcd78ae,_0xe341a9){return this[_0x4e60('0x1e')](util[_0x4e60('0x23')](_0x4e60('0x35'),_0xcd78ae,_0xe341a9));};AGIChannel[_0x4e60('0x1d')]['sayPhonetic']=function(_0x4a9304,_0x5b84cf){return this[_0x4e60('0x1e')](util[_0x4e60('0x23')](_0x4e60('0x36'),_0x4a9304,_0x5b84cf));};AGIChannel[_0x4e60('0x1d')]['continueAt']=function(_0x5e0837,_0x322825,_0x5dcafe){_0x322825=_0x322825||this['extension'];_0x5dcafe=_0x5dcafe||0x1;this[_0x4e60('0x2a')](_0x5e0837);this[_0x4e60('0x2c')](_0x322825);this[_0x4e60('0x37')](_0x5dcafe);return this[_0x4e60('0x24')](util[_0x4e60('0x23')](_0x4e60('0x38'),_0x5e0837,_0x322825,_0x5dcafe));};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x39')]=function(_0x2e1ce3){return this[_0x4e60('0x1e')](util[_0x4e60('0x23')](_0x4e60('0x3a'),_0x2e1ce3));};AGIChannel['prototype'][_0x4e60('0x3b')]=function(_0x2d162e,_0x2d0c46,_0x2fda40,_0x9f36ba,_0x14e621,_0x440a59){_0x2d0c46=_0x2d0c46||_0x4e60('0x3c');_0x2fda40=_0x2fda40||'';_0x9f36ba=_0x9f36ba===undefined?-0x1:_0x9f36ba==='-1'?-0x1:_0x9f36ba*0x3e8;_0x14e621=_0x14e621===undefined?'':'s='+_0x14e621;_0x440a59=_0x440a59?_0x4e60('0x3d'):'';return this[_0x4e60('0x1e')](util[_0x4e60('0x23')](_0x4e60('0x3e'),_0x2d162e,_0x2d0c46,_0x2fda40,_0x9f36ba,_0x440a59,_0x14e621));};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x3f')]=function(_0x3ebace,_0x38e00f){_0x38e00f=_0x38e00f||'';return this[_0x4e60('0x1e')](util['format']('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x3ebace,_0x38e00f));};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x40')]=function(_0x492066){return this[_0x4e60('0x27')](_0x4e60('0x41'),_0x492066);};AGIChannel['prototype']['wait']=function(_0x342340){return this[_0x4e60('0x27')]('WAIT',_0x342340);};AGIChannel[_0x4e60('0x1d')][_0x4e60('0x13')]=function(_0x242832,_0x33e2ce){this[_0x4e60('0x24')](util[_0x4e60('0x23')]('ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s',_0x242832['id'],_0x242832['label'],_0x33e2ce));return{'code':0x1f4,'result':'-1','extra':''};};module['exports']=AGIChannel;