d94aaafaf2ecc2775477c4b1525d9ddaada9d0a2
[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 _0xc55f=['exports','util','lodash','events','EventEmitter','./error','setEncoding','utf8','setTimeout','headers','emit','ready','toLowerCase','hangup','substring','520\x20End\x20of\x20proper','function','no\x20code','replace','result=','indexOf','startsWith','split','length','match','error','E_AGI_SOCKET_ERROR','code','close','timeout','pipe','command','log','command=','destroy','sync','prototype','answer','sendRequest','ANSWER','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','EXEC\x20%s\x20%s','setContext','setExtension','SET\x20EXTENSION\x20%s','SET\x20PRIORITY\x20%s','setVariable','isBoolean','isNumber','toString','SET\x20VARIABLE\x20%s\x20\x22%s\x22','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','setPriority','noop','GOTO\x20%s\x20%s\x20%s','getVariable','getvariable','GET\x20VARIABLE\x20\x22%s\x22','recordFile','wav','BEEP','agi','AGI','wait','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label'];(function(_0x387a73,_0x3cd2a4){var _0x2383a9=function(_0x4343ae){while(--_0x4343ae){_0x387a73['push'](_0x387a73['shift']());}};_0x2383a9(++_0x3cd2a4);}(_0xc55f,0x9f));var _0xfc55=function(_0xac0841,_0xd8de7c){_0xac0841=_0xac0841-0x0;var _0x46a9a6=_0xc55f[_0xac0841];return _0x46a9a6;};'use strict';var util=require(_0xfc55('0x0'));var _=require(_0xfc55('0x1'));var EventEmitter=require(_0xfc55('0x2'))[_0xfc55('0x3')];var AGIReply=require('./reply');var AGIError=require(_0xfc55('0x4'));function AGIChannel(_0x1bbf81){var _0x5416ed=this,_0x5e596f=new AGIReply(),_0xdfeab5=![],_0x158111={};EventEmitter['call'](_0x5416ed);_0x1bbf81[_0xfc55('0x5')](_0xfc55('0x6'));_0x1bbf81[_0xfc55('0x7')](0x8*0x3c*0x3c*0x3e8);_0x5e596f[_0xfc55('0x5')](_0xfc55('0x6'));_0x5e596f['on'](_0xfc55('0x8'),function(_0xb935fd){for(var _0x47e704 in _0xb935fd){_0x5416ed[_0x47e704]=_0xb935fd[_0x47e704];}_0x5416ed[_0xfc55('0x9')](_0xfc55('0xa'));});_0x5e596f['on']('line',function(_0x5518ba){if(_0x5518ba[_0xfc55('0xb')]()==_0xfc55('0xc')){_0x5416ed['emit']('hangup');return;}if(_0x5518ba[_0xfc55('0xd')](0x0,0xb)=='520-Invalid'){_0xdfeab5=!![];}if(_0xdfeab5){_0x158111['rx']+=_0x5518ba+'\x0a';if(_0x5518ba['search'](_0xfc55('0xe'))!=-0x1){_0xdfeab5=![];}}else{_0x158111['rx']=_0x5518ba;}if(_0xdfeab5){return;}if(typeof _0x158111['cb']==_0xfc55('0xf')){var _0x1df4b9=_0x158111['rx']['substring'](0x0,0x3),_0x256c76=null,_0x10b0d3=null;_0x1df4b9=parseInt(_0x1df4b9);if(isNaN(_0x1df4b9)){_0x158111['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xfc55('0x10')});return;}if(_0x1df4b9!=0xc8){_0x158111['cb'](null,{'code':_0x1df4b9,'result':-0x1,'extra':'KO'});return;}_0x256c76=_0x158111['rx']['substring'](0x4)[_0xfc55('0x11')](_0xfc55('0x12'),'');if(_0x256c76['indexOf']('\x20')!=-0x1){_0x256c76=_0x256c76['substr'](0x0,_0x256c76[_0xfc55('0x13')]('\x20'));}if(_[_0xfc55('0x14')](_0x256c76,'-1')){_0x256c76=parseInt(_0x256c76);}_0x10b0d3=_0x158111['rx'][_0xfc55('0x15')]('\x20');if(_0x10b0d3['length']==0x3){_0x10b0d3=_0x10b0d3[0x2]['substring'](0x1,_0x10b0d3[0x2][_0xfc55('0x16')]-0x1);}else if(_0x10b0d3['length']>0x3){var _0x4fe50b=/\((.+)\)/;var _0x4e3650=_0x158111['rx'][_0xfc55('0x17')](_0x4fe50b);if(_0x4e3650){_0x10b0d3=_0x4e3650[0x1];}else{_0x10b0d3=null;}}else{_0x10b0d3=null;}_0x158111['cb'](null,{'code':_0x1df4b9,'result':_0x256c76,'extra':_0x10b0d3});}});_0x1bbf81['on']('error',function(_0x4ac6c8){_0x5416ed['emit'](_0xfc55('0x18'),new AGIError(_0xfc55('0x19'),_0x4ac6c8[_0xfc55('0x1a')]));});_0x1bbf81['on'](_0xfc55('0x1b'),function(){_0x5416ed['emit'](_0xfc55('0x1b'),new AGIError('E_AGI_SOCKET_CLOSE'));});_0x1bbf81['on'](_0xfc55('0x1c'),function(){_0x5416ed['emit'](_0xfc55('0x1c'),new AGIError('E_AGI_SOCKET_TIMEOUT'));_0x1bbf81['destroy']();});_0x1bbf81[_0xfc55('0x1d')](_0x5e596f);this[_0xfc55('0x1e')]=function(_0x32f610,_0x154071){console[_0xfc55('0x1f')](_0xfc55('0x20'),_0x32f610);var _0x32f610=_0x32f610||'',_0x154071=typeof _0x154071=='function'?_0x154071:new Function();_0x158111={'tx':_0x32f610,'rx':'','cb':_0x154071};_0x1bbf81['write'](_0x32f610+'\x0a');},this[_0xfc55('0x1b')]=function(){_0x1bbf81[_0xfc55('0x21')]();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel['prototype']['sendRequest']=function(_0x4411d9){return this[_0xfc55('0x1e')][_0xfc55('0x22')](this,_0x4411d9);};AGIChannel[_0xfc55('0x23')][_0xfc55('0x24')]=function(){return this[_0xfc55('0x25')](_0xfc55('0x26'));};AGIChannel[_0xfc55('0x23')][_0xfc55('0x27')]=function(_0x437a8a,_0x1bba49,_0x531833){_0x437a8a=_0x437a8a===undefined?_0xfc55('0x28'):_0x437a8a;_0x1bba49=_0x1bba49===undefined?'5':_0x1bba49;_0x531833=_0x531833===undefined?'1':_0x531833;return this[_0xfc55('0x25')](util[_0xfc55('0x29')](_0xfc55('0x2a'),_0x437a8a,_0x1bba49*0x3e8,_0x531833));};AGIChannel[_0xfc55('0x23')]['noop']=function(_0x2f6071){_0x2f6071=_0x2f6071||_0xfc55('0x2b');return this[_0xfc55('0x25')](util[_0xfc55('0x29')](_0xfc55('0x2c'),_0x2f6071));};AGIChannel[_0xfc55('0x23')][_0xfc55('0x2d')]=function(_0xb481bd,_0x434e95){if(_['isArray'](_0x434e95)){return this[_0xfc55('0x25')](util[_0xfc55('0x29')](_0xfc55('0x2e'),_0xb481bd,_0x434e95['join'](',')));}return this[_0xfc55('0x25')](util[_0xfc55('0x29')](_0xfc55('0x2e'),_0xb481bd,_0x434e95));};AGIChannel[_0xfc55('0x23')][_0xfc55('0x2f')]=function(_0x23be40){return this[_0xfc55('0x25')](util['format']('SET\x20CONTEXT\x20%s',_0x23be40));};AGIChannel[_0xfc55('0x23')][_0xfc55('0x30')]=function(_0x52a486){return this[_0xfc55('0x25')](util[_0xfc55('0x29')](_0xfc55('0x31'),_0x52a486));};AGIChannel[_0xfc55('0x23')]['setPriority']=function(_0x421295){return this[_0xfc55('0x25')](util[_0xfc55('0x29')](_0xfc55('0x32'),_0x421295));};AGIChannel['prototype'][_0xfc55('0xc')]=function(){return this[_0xfc55('0x25')]('HANGUP');};AGIChannel[_0xfc55('0x23')][_0xfc55('0x33')]=function(_0x41e61a,_0x4c67d5){var _0x284437=_[_0xfc55('0x34')](_0x4c67d5)||_[_0xfc55('0x35')](_0x4c67d5)?_0x4c67d5[_0xfc55('0x36')]():_0x4c67d5;return this[_0xfc55('0x25')](util['format'](_0xfc55('0x37'),_0x41e61a,_0x284437?_0x284437['toString']()[_0xfc55('0x11')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xfc55('0x23')]['sayNumber']=function(_0x59ba08,_0x2a9ed9){return this[_0xfc55('0x25')](util[_0xfc55('0x29')](_0xfc55('0x38'),_0x59ba08,_0x2a9ed9));};AGIChannel[_0xfc55('0x23')][_0xfc55('0x39')]=function(_0x4c9bf8,_0x9d0894){return this[_0xfc55('0x25')](util[_0xfc55('0x29')](_0xfc55('0x3a'),_0x4c9bf8,_0x9d0894));};AGIChannel[_0xfc55('0x23')][_0xfc55('0x3b')]=function(_0x5764f7,_0x1a5cc5){return this['sendRequest'](util[_0xfc55('0x29')](_0xfc55('0x3c'),_0x5764f7,_0x1a5cc5));};AGIChannel[_0xfc55('0x23')][_0xfc55('0x3d')]=function(_0x7cc826,_0x5e4d0e,_0x853cbb){_0x5e4d0e=_0x5e4d0e||this[_0xfc55('0x3e')];_0x853cbb=_0x853cbb||0x1;this[_0xfc55('0x2f')](_0x7cc826);this[_0xfc55('0x30')](_0x5e4d0e);this[_0xfc55('0x3f')](_0x853cbb);return this[_0xfc55('0x40')](util[_0xfc55('0x29')](_0xfc55('0x41'),_0x7cc826,_0x5e4d0e,_0x853cbb));};AGIChannel[_0xfc55('0x23')][_0xfc55('0x42')]=function(_0x3e65b9){console[_0xfc55('0x1f')](_0xfc55('0x43'),_0x3e65b9);return this['sendRequest'](util[_0xfc55('0x29')](_0xfc55('0x44'),_0x3e65b9));};AGIChannel['prototype'][_0xfc55('0x45')]=function(_0x530c3f,_0x35d5a4,_0x81e668,_0x47343f,_0x154da2,_0x381477){_0x35d5a4=_0x35d5a4||_0xfc55('0x46');_0x81e668=_0x81e668||'';_0x47343f=_0x47343f===undefined?-0x1:_0x47343f==='-1'?-0x1:_0x47343f*0x3e8;_0x154da2=_0x154da2===undefined?'':'s='+_0x154da2;_0x381477=_0x381477?_0xfc55('0x47'):'';return this['sendRequest'](util[_0xfc55('0x29')]('RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s',_0x530c3f,_0x35d5a4,_0x81e668,_0x47343f,_0x381477,_0x154da2));};AGIChannel[_0xfc55('0x23')]['streamFile']=function(_0xb56d0b,_0x379f90){_0x379f90=_0x379f90||'';return this[_0xfc55('0x25')](util[_0xfc55('0x29')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0xb56d0b,_0x379f90));};AGIChannel[_0xfc55('0x23')][_0xfc55('0x48')]=function(_0x3f370b){return this[_0xfc55('0x2d')](_0xfc55('0x49'),_0x3f370b);};AGIChannel[_0xfc55('0x23')][_0xfc55('0x4a')]=function(_0xfa8a2e){return this[_0xfc55('0x2d')](_0xfc55('0x4b'),_0xfa8a2e);};AGIChannel[_0xfc55('0x23')][_0xfc55('0x18')]=function(_0x1bf8cc,_0x4e0534){this[_0xfc55('0x40')](util[_0xfc55('0x29')](_0xfc55('0x4c'),_0x1bf8cc['id'],_0x1bf8cc[_0xfc55('0x4d')],_0x4e0534));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xfc55('0x4e')]=AGIChannel;