Built motion from commit fa4c4286.|2.6.29
[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 _0x5957=['join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20PRIORITY\x20%s','isBoolean','isNumber','SET\x20VARIABLE\x20%s\x20\x22%s\x22','toString','sayNumber','SAY\x20NUMBER\x20%s\x20%s','sayDigits','sayPhonetic','SAY\x20PHONETIC\x20\x22%s\x22\x20%s','continueAt','extension','setPriority','noop','GOTO\x20%s\x20%s\x20%s','getVariable','GET\x20VARIABLE\x20\x22%s\x22','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','AGI','wait','WAIT','label','exports','util','lodash','./reply','call','setTimeout','setEncoding','headers','emit','ready','line','toLowerCase','hangup','substring','520-Invalid','search','function','no\x20code','replace','result=','substr','split','length','error','code','close','E_AGI_SOCKET_CLOSE','timeout','E_AGI_SOCKET_TIMEOUT','destroy','pipe','command','write','inherits','prototype','sendRequest','sync','answer','ANSWER','getData','beep','format','NO\x20MESSAGE','VERBOSE\x20\x22%s\x22','exec','isArray','EXEC\x20%s\x20%s'];(function(_0x3ff75b,_0x47553b){var _0xd31906=function(_0xeea99){while(--_0xeea99){_0x3ff75b['push'](_0x3ff75b['shift']());}};_0xd31906(++_0x47553b);}(_0x5957,0x158));var _0x7595=function(_0x382c86,_0x504b95){_0x382c86=_0x382c86-0x0;var _0x230c04=_0x5957[_0x382c86];return _0x230c04;};'use strict';var util=require(_0x7595('0x0'));var _=require(_0x7595('0x1'));var EventEmitter=require('events')['EventEmitter'];var AGIReply=require(_0x7595('0x2'));var AGIError=require('./error');function AGIChannel(_0x41348b){var _0x8e95e4=this,_0x27d0ea=new AGIReply(),_0x34e328=![],_0x68627c={};EventEmitter[_0x7595('0x3')](_0x8e95e4);_0x41348b['setEncoding']('utf8');_0x41348b[_0x7595('0x4')](0x8*0x3c*0x3c*0x3e8);_0x27d0ea[_0x7595('0x5')]('utf8');_0x27d0ea['on'](_0x7595('0x6'),function(_0x32581d){for(var _0x27ccd1 in _0x32581d){_0x8e95e4[_0x27ccd1]=_0x32581d[_0x27ccd1];}_0x8e95e4[_0x7595('0x7')](_0x7595('0x8'));});_0x27d0ea['on'](_0x7595('0x9'),function(_0x4c8870){if(_0x4c8870[_0x7595('0xa')]()==_0x7595('0xb')){_0x8e95e4[_0x7595('0x7')](_0x7595('0xb'));return;}if(_0x4c8870[_0x7595('0xc')](0x0,0xb)==_0x7595('0xd')){_0x34e328=!![];}if(_0x34e328){_0x68627c['rx']+=_0x4c8870+'\x0a';if(_0x4c8870[_0x7595('0xe')]('520\x20End\x20of\x20proper')!=-0x1){_0x34e328=![];}}else{_0x68627c['rx']=_0x4c8870;}if(_0x34e328){return;}if(typeof _0x68627c['cb']==_0x7595('0xf')){var _0xff8be1=_0x68627c['rx'][_0x7595('0xc')](0x0,0x3),_0x4f0f37=null,_0x11a9e0=null;_0xff8be1=parseInt(_0xff8be1);if(isNaN(_0xff8be1)){_0x68627c['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x7595('0x10')});return;}if(_0xff8be1!=0xc8){_0x68627c['cb'](null,{'code':_0xff8be1,'result':-0x1,'extra':'KO'});return;}_0x4f0f37=_0x68627c['rx']['substring'](0x4)[_0x7595('0x11')](_0x7595('0x12'),'');if(_0x4f0f37['indexOf']('\x20')!=-0x1){_0x4f0f37=_0x4f0f37[_0x7595('0x13')](0x0,_0x4f0f37['indexOf']('\x20'));}if(_['startsWith'](_0x4f0f37,'-1')){_0x4f0f37=parseInt(_0x4f0f37);}_0x11a9e0=_0x68627c['rx'][_0x7595('0x14')]('\x20');if(_0x11a9e0[_0x7595('0x15')]==0x3){_0x11a9e0=_0x11a9e0[0x2][_0x7595('0xc')](0x1,_0x11a9e0[0x2][_0x7595('0x15')]-0x1);}else if(_0x11a9e0[_0x7595('0x15')]>0x3){var _0x2eefd4=/\((.+)\)/;var _0x2efcec=_0x68627c['rx']['match'](_0x2eefd4);if(_0x2efcec){_0x11a9e0=_0x2efcec[0x1];}else{_0x11a9e0=null;}}else{_0x11a9e0=null;}_0x68627c['cb'](null,{'code':_0xff8be1,'result':_0x4f0f37,'extra':_0x11a9e0});}});_0x41348b['on'](_0x7595('0x16'),function(_0x86dbfa){_0x8e95e4[_0x7595('0x7')]('error',new AGIError('E_AGI_SOCKET_ERROR',_0x86dbfa[_0x7595('0x17')]));});_0x41348b['on'](_0x7595('0x18'),function(){_0x8e95e4[_0x7595('0x7')]('close',new AGIError(_0x7595('0x19')));});_0x41348b['on'](_0x7595('0x1a'),function(){_0x8e95e4[_0x7595('0x7')]('timeout',new AGIError(_0x7595('0x1b')));_0x41348b[_0x7595('0x1c')]();});_0x41348b[_0x7595('0x1d')](_0x27d0ea);this[_0x7595('0x1e')]=function(_0x5c8a0d,_0x302915){var _0x5c8a0d=_0x5c8a0d||'',_0x302915=typeof _0x302915=='function'?_0x302915:new Function();_0x68627c={'tx':_0x5c8a0d,'rx':'','cb':_0x302915};_0x41348b[_0x7595('0x1f')](_0x5c8a0d+'\x0a');},this[_0x7595('0x18')]=function(){_0x41348b[_0x7595('0x1c')]();};}util[_0x7595('0x20')](AGIChannel,EventEmitter);AGIChannel[_0x7595('0x21')][_0x7595('0x22')]=function(_0x1ac7cc){return this[_0x7595('0x1e')][_0x7595('0x23')](this,_0x1ac7cc);};AGIChannel['prototype'][_0x7595('0x24')]=function(){return this[_0x7595('0x22')](_0x7595('0x25'));};AGIChannel[_0x7595('0x21')][_0x7595('0x26')]=function(_0x244174,_0x117d0b,_0x1dc6ef){_0x244174=_0x244174===undefined?_0x7595('0x27'):_0x244174;_0x117d0b=_0x117d0b===undefined?'5':_0x117d0b;_0x1dc6ef=_0x1dc6ef===undefined?'1':_0x1dc6ef;return this[_0x7595('0x22')](util[_0x7595('0x28')]('GET\x20DATA\x20\x22%s\x22\x20%s\x20%s',_0x244174,_0x117d0b*0x3e8,_0x1dc6ef));};AGIChannel[_0x7595('0x21')]['noop']=function(_0x2bacc7){_0x2bacc7=_0x2bacc7||_0x7595('0x29');return this[_0x7595('0x22')](util['format'](_0x7595('0x2a'),_0x2bacc7));};AGIChannel['prototype'][_0x7595('0x2b')]=function(_0x457bcd,_0x482aa7){if(_[_0x7595('0x2c')](_0x482aa7)){return this[_0x7595('0x22')](util[_0x7595('0x28')](_0x7595('0x2d'),_0x457bcd,_0x482aa7[_0x7595('0x2e')](',')));}return this[_0x7595('0x22')](util['format'](_0x7595('0x2d'),_0x457bcd,_0x482aa7));};AGIChannel[_0x7595('0x21')][_0x7595('0x2f')]=function(_0x3b8d60){return this['sendRequest'](util[_0x7595('0x28')](_0x7595('0x30'),_0x3b8d60));};AGIChannel['prototype'][_0x7595('0x31')]=function(_0x17d276){return this['sendRequest'](util['format']('SET\x20EXTENSION\x20%s',_0x17d276));};AGIChannel[_0x7595('0x21')]['setPriority']=function(_0x37d6f7){return this[_0x7595('0x22')](util[_0x7595('0x28')](_0x7595('0x32'),_0x37d6f7));};AGIChannel[_0x7595('0x21')]['hangup']=function(){return this[_0x7595('0x22')]('HANGUP');};AGIChannel[_0x7595('0x21')]['setVariable']=function(_0x2e8c81,_0x6922c8){var _0x1e956e=_[_0x7595('0x33')](_0x6922c8)||_[_0x7595('0x34')](_0x6922c8)?_0x6922c8['toString']():_0x6922c8;return this['sendRequest'](util[_0x7595('0x28')](_0x7595('0x35'),_0x2e8c81,_0x1e956e?_0x1e956e[_0x7595('0x36')]()[_0x7595('0x11')](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x7595('0x21')][_0x7595('0x37')]=function(_0x2964cd,_0x167df1){return this[_0x7595('0x22')](util['format'](_0x7595('0x38'),_0x2964cd,_0x167df1));};AGIChannel[_0x7595('0x21')][_0x7595('0x39')]=function(_0x34b181,_0x101793){return this[_0x7595('0x22')](util[_0x7595('0x28')]('SAY\x20DIGITS\x20%s\x20%s',_0x34b181,_0x101793));};AGIChannel[_0x7595('0x21')][_0x7595('0x3a')]=function(_0x30987c,_0x8dae34){return this[_0x7595('0x22')](util[_0x7595('0x28')](_0x7595('0x3b'),_0x30987c,_0x8dae34));};AGIChannel[_0x7595('0x21')][_0x7595('0x3c')]=function(_0x46fdac,_0x1fb269,_0x6f5e9f){_0x1fb269=_0x1fb269||this[_0x7595('0x3d')];_0x6f5e9f=_0x6f5e9f||0x1;this[_0x7595('0x2f')](_0x46fdac);this[_0x7595('0x31')](_0x1fb269);this[_0x7595('0x3e')](_0x6f5e9f);return this[_0x7595('0x3f')](util[_0x7595('0x28')](_0x7595('0x40'),_0x46fdac,_0x1fb269,_0x6f5e9f));};AGIChannel[_0x7595('0x21')][_0x7595('0x41')]=function(_0x49b100){return this[_0x7595('0x22')](util[_0x7595('0x28')](_0x7595('0x42'),_0x49b100));};AGIChannel[_0x7595('0x21')]['recordFile']=function(_0x5bceff,_0x375ff7,_0x679645,_0x5baf20,_0x418b75,_0x2ec2bf){_0x375ff7=_0x375ff7||_0x7595('0x43');_0x679645=_0x679645||'';_0x5baf20=_0x5baf20===undefined?-0x1:_0x5baf20==='-1'?-0x1:_0x5baf20*0x3e8;_0x418b75=_0x418b75===undefined?'':'s='+_0x418b75;_0x2ec2bf=_0x2ec2bf?_0x7595('0x44'):'';return this[_0x7595('0x22')](util[_0x7595('0x28')](_0x7595('0x45'),_0x5bceff,_0x375ff7,_0x679645,_0x5baf20,_0x2ec2bf,_0x418b75));};AGIChannel[_0x7595('0x21')][_0x7595('0x46')]=function(_0xcddb9b,_0x462f0e){_0x462f0e=_0x462f0e||'';return this[_0x7595('0x22')](util[_0x7595('0x28')](_0x7595('0x47'),_0xcddb9b,_0x462f0e));};AGIChannel[_0x7595('0x21')][_0x7595('0x48')]=function(_0x4fea0b){return this[_0x7595('0x2b')](_0x7595('0x49'),_0x4fea0b);};AGIChannel['prototype'][_0x7595('0x4a')]=function(_0x55878f){return this['exec'](_0x7595('0x4b'),_0x55878f);};AGIChannel['prototype']['error']=function(_0x594898,_0x298f79){this[_0x7595('0x3f')](util[_0x7595('0x28')]('ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s',_0x594898['id'],_0x594898[_0x7595('0x4c')],_0x298f79));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x7595('0x4d')]=AGIChannel;