Built motion from commit 53172ac8.|2.6.30
[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 _0xbd3c=['destroy','inherits','prototype','sendRequest','command','getData','beep','format','GET\x20DATA\x20\x22%s\x22\x20%s\x20%s','noop','VERBOSE\x20\x22%s\x22','exec','isArray','EXEC\x20%s\x20%s','setContext','SET\x20EXTENSION\x20%s','setPriority','HANGUP','setVariable','isNumber','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','SAY\x20DIGITS\x20%s\x20%s','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','setExtension','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','STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22','AGI','wait','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','label','exports','util','lodash','events','./reply','./error','call','setEncoding','setTimeout','utf8','emit','ready','line','hangup','search','520\x20End\x20of\x20proper','function','substring','no\x20code','replace','indexOf','startsWith','split','length','match','error','code','close','E_AGI_SOCKET_CLOSE','E_AGI_SOCKET_TIMEOUT','pipe','write'];(function(_0x18cb8d,_0x272da9){var _0x35c5ae=function(_0x34ee9a){while(--_0x34ee9a){_0x18cb8d['push'](_0x18cb8d['shift']());}};_0x35c5ae(++_0x272da9);}(_0xbd3c,0xc2));var _0xcbd3=function(_0x3d0475,_0x5dcd43){_0x3d0475=_0x3d0475-0x0;var _0x4de6ee=_0xbd3c[_0x3d0475];return _0x4de6ee;};'use strict';var util=require(_0xcbd3('0x0'));var _=require(_0xcbd3('0x1'));var EventEmitter=require(_0xcbd3('0x2'))['EventEmitter'];var AGIReply=require(_0xcbd3('0x3'));var AGIError=require(_0xcbd3('0x4'));function AGIChannel(_0x45274b){var _0x47ff9b=this,_0x505967=new AGIReply(),_0x2b7178=![],_0x5c280d={};EventEmitter[_0xcbd3('0x5')](_0x47ff9b);_0x45274b[_0xcbd3('0x6')]('utf8');_0x45274b[_0xcbd3('0x7')](0x8*0x3c*0x3c*0x3e8);_0x505967[_0xcbd3('0x6')](_0xcbd3('0x8'));_0x505967['on']('headers',function(_0x18fb60){for(var _0x258d74 in _0x18fb60){_0x47ff9b[_0x258d74]=_0x18fb60[_0x258d74];}_0x47ff9b[_0xcbd3('0x9')](_0xcbd3('0xa'));});_0x505967['on'](_0xcbd3('0xb'),function(_0x5826e6){if(_0x5826e6['toLowerCase']()==_0xcbd3('0xc')){_0x47ff9b[_0xcbd3('0x9')]('hangup');return;}if(_0x5826e6['substring'](0x0,0xb)=='520-Invalid'){_0x2b7178=!![];}if(_0x2b7178){_0x5c280d['rx']+=_0x5826e6+'\x0a';if(_0x5826e6[_0xcbd3('0xd')](_0xcbd3('0xe'))!=-0x1){_0x2b7178=![];}}else{_0x5c280d['rx']=_0x5826e6;}if(_0x2b7178){return;}if(typeof _0x5c280d['cb']==_0xcbd3('0xf')){var _0x488258=_0x5c280d['rx'][_0xcbd3('0x10')](0x0,0x3),_0x6e7d38=null,_0x267d31=null;_0x488258=parseInt(_0x488258);if(isNaN(_0x488258)){_0x5c280d['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0xcbd3('0x11')});return;}if(_0x488258!=0xc8){_0x5c280d['cb'](null,{'code':_0x488258,'result':-0x1,'extra':'KO'});return;}_0x6e7d38=_0x5c280d['rx'][_0xcbd3('0x10')](0x4)[_0xcbd3('0x12')]('result=','');if(_0x6e7d38[_0xcbd3('0x13')]('\x20')!=-0x1){_0x6e7d38=_0x6e7d38['substr'](0x0,_0x6e7d38[_0xcbd3('0x13')]('\x20'));}if(_[_0xcbd3('0x14')](_0x6e7d38,'-1')){_0x6e7d38=parseInt(_0x6e7d38);}_0x267d31=_0x5c280d['rx'][_0xcbd3('0x15')]('\x20');if(_0x267d31['length']==0x3){_0x267d31=_0x267d31[0x2][_0xcbd3('0x10')](0x1,_0x267d31[0x2]['length']-0x1);}else if(_0x267d31[_0xcbd3('0x16')]>0x3){var _0x5941a5=/\((.+)\)/;var _0x460c02=_0x5c280d['rx'][_0xcbd3('0x17')](_0x5941a5);if(_0x460c02){_0x267d31=_0x460c02[0x1];}else{_0x267d31=null;}}else{_0x267d31=null;}_0x5c280d['cb'](null,{'code':_0x488258,'result':_0x6e7d38,'extra':_0x267d31});}});_0x45274b['on'](_0xcbd3('0x18'),function(_0x115336){_0x47ff9b[_0xcbd3('0x9')]('error',new AGIError('E_AGI_SOCKET_ERROR',_0x115336[_0xcbd3('0x19')]));});_0x45274b['on'](_0xcbd3('0x1a'),function(){_0x47ff9b[_0xcbd3('0x9')]('close',new AGIError(_0xcbd3('0x1b')));});_0x45274b['on']('timeout',function(){_0x47ff9b[_0xcbd3('0x9')]('timeout',new AGIError(_0xcbd3('0x1c')));_0x45274b['destroy']();});_0x45274b[_0xcbd3('0x1d')](_0x505967);this['command']=function(_0x5f0bcb,_0x3e86c1){var _0x5f0bcb=_0x5f0bcb||'',_0x3e86c1=typeof _0x3e86c1=='function'?_0x3e86c1:new Function();_0x5c280d={'tx':_0x5f0bcb,'rx':'','cb':_0x3e86c1};_0x45274b[_0xcbd3('0x1e')](_0x5f0bcb+'\x0a');},this[_0xcbd3('0x1a')]=function(){_0x45274b[_0xcbd3('0x1f')]();};}util[_0xcbd3('0x20')](AGIChannel,EventEmitter);AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x22')]=function(_0x32d34f){return this[_0xcbd3('0x23')]['sync'](this,_0x32d34f);};AGIChannel[_0xcbd3('0x21')]['answer']=function(){return this[_0xcbd3('0x22')]('ANSWER');};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x24')]=function(_0x4fb411,_0x21520a,_0x52cc97){_0x4fb411=_0x4fb411===undefined?_0xcbd3('0x25'):_0x4fb411;_0x21520a=_0x21520a===undefined?'5':_0x21520a;_0x52cc97=_0x52cc97===undefined?'1':_0x52cc97;return this[_0xcbd3('0x22')](util[_0xcbd3('0x26')](_0xcbd3('0x27'),_0x4fb411,_0x21520a*0x3e8,_0x52cc97));};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x28')]=function(_0x15349e){_0x15349e=_0x15349e||'NO\x20MESSAGE';return this[_0xcbd3('0x22')](util[_0xcbd3('0x26')](_0xcbd3('0x29'),_0x15349e));};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x2a')]=function(_0x45aadb,_0x3a74e2){if(_[_0xcbd3('0x2b')](_0x3a74e2)){return this[_0xcbd3('0x22')](util['format'](_0xcbd3('0x2c'),_0x45aadb,_0x3a74e2['join'](',')));}return this['sendRequest'](util[_0xcbd3('0x26')](_0xcbd3('0x2c'),_0x45aadb,_0x3a74e2));};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x2d')]=function(_0x20ed3b){return this[_0xcbd3('0x22')](util[_0xcbd3('0x26')]('SET\x20CONTEXT\x20%s',_0x20ed3b));};AGIChannel[_0xcbd3('0x21')]['setExtension']=function(_0x9869ce){return this[_0xcbd3('0x22')](util[_0xcbd3('0x26')](_0xcbd3('0x2e'),_0x9869ce));};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x2f')]=function(_0x101266){return this[_0xcbd3('0x22')](util[_0xcbd3('0x26')]('SET\x20PRIORITY\x20%s',_0x101266));};AGIChannel['prototype'][_0xcbd3('0xc')]=function(){return this['sendRequest'](_0xcbd3('0x30'));};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x31')]=function(_0x2ea7a2,_0x15a44f){var _0x35046c=_['isBoolean'](_0x15a44f)||_[_0xcbd3('0x32')](_0x15a44f)?_0x15a44f[_0xcbd3('0x33')]():_0x15a44f;return this['sendRequest'](util[_0xcbd3('0x26')]('SET\x20VARIABLE\x20%s\x20\x22%s\x22',_0x2ea7a2,_0x35046c?_0x35046c[_0xcbd3('0x33')]()[_0xcbd3('0x12')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x34')]=function(_0x55147f,_0x5866c5){return this[_0xcbd3('0x22')](util['format'](_0xcbd3('0x35'),_0x55147f,_0x5866c5));};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x36')]=function(_0x4a2449,_0xf5652e){return this[_0xcbd3('0x22')](util['format'](_0xcbd3('0x37'),_0x4a2449,_0xf5652e));};AGIChannel[_0xcbd3('0x21')]['sayPhonetic']=function(_0x296784,_0x1fc203){return this[_0xcbd3('0x22')](util[_0xcbd3('0x26')](_0xcbd3('0x38'),_0x296784,_0x1fc203));};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x39')]=function(_0x17db0f,_0x5275e8,_0x3784cc){_0x5275e8=_0x5275e8||this[_0xcbd3('0x3a')];_0x3784cc=_0x3784cc||0x1;this[_0xcbd3('0x2d')](_0x17db0f);this[_0xcbd3('0x3b')](_0x5275e8);this[_0xcbd3('0x2f')](_0x3784cc);return this['noop'](util[_0xcbd3('0x26')](_0xcbd3('0x3c'),_0x17db0f,_0x5275e8,_0x3784cc));};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x3d')]=function(_0x45f75b){return this[_0xcbd3('0x22')](util[_0xcbd3('0x26')](_0xcbd3('0x3e'),_0x45f75b));};AGIChannel['prototype'][_0xcbd3('0x3f')]=function(_0x14b681,_0x148a11,_0x1848f3,_0xb486c6,_0x4eb4c3,_0x439429){_0x148a11=_0x148a11||_0xcbd3('0x40');_0x1848f3=_0x1848f3||'';_0xb486c6=_0xb486c6===undefined?-0x1:_0xb486c6==='-1'?-0x1:_0xb486c6*0x3e8;_0x4eb4c3=_0x4eb4c3===undefined?'':'s='+_0x4eb4c3;_0x439429=_0x439429?_0xcbd3('0x41'):'';return this[_0xcbd3('0x22')](util[_0xcbd3('0x26')](_0xcbd3('0x42'),_0x14b681,_0x148a11,_0x1848f3,_0xb486c6,_0x439429,_0x4eb4c3));};AGIChannel['prototype'][_0xcbd3('0x43')]=function(_0xfaadf2,_0x507e1c){_0x507e1c=_0x507e1c||'';return this[_0xcbd3('0x22')](util[_0xcbd3('0x26')](_0xcbd3('0x44'),_0xfaadf2,_0x507e1c));};AGIChannel[_0xcbd3('0x21')]['agi']=function(_0x482e3c){return this[_0xcbd3('0x2a')](_0xcbd3('0x45'),_0x482e3c);};AGIChannel[_0xcbd3('0x21')][_0xcbd3('0x46')]=function(_0x21125b){return this[_0xcbd3('0x2a')](_0xcbd3('0x47'),_0x21125b);};AGIChannel[_0xcbd3('0x21')]['error']=function(_0x33eb4f,_0x557ea0){this[_0xcbd3('0x28')](util['format'](_0xcbd3('0x48'),_0x33eb4f['id'],_0x33eb4f[_0xcbd3('0x49')],_0x557ea0));return{'code':0x1f4,'result':'-1','extra':''};};module[_0xcbd3('0x4a')]=AGIChannel;