be18326af4cf90944cfa943d8b14b23c709565d4
[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 _0x9c51=['timeout','E_AGI_SOCKET_TIMEOUT','destroy','command','function','write','sync','sendRequest','ANSWER','prototype','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','join','setContext','SET\x20CONTEXT\x20%s','setExtension','SET\x20EXTENSION\x20%s','setPriority','SET\x20PRIORITY\x20%s','HANGUP','setVariable','isBoolean','isNumber','toString','SAY\x20NUMBER\x20%s\x20%s','SAY\x20DIGITS\x20%s\x20%s','extension','getVariable','GET\x20VARIABLE\x20\x22%s\x22','BEEP','streamFile','agi','AGI','wait','WAIT','ID:%s\x20-\x20LABEL:\x20%s\x20-\x20MSG:\x20%s','exports','lodash','EventEmitter','./reply','./error','setEncoding','utf8','headers','ready','line','hangup','substring','search','no\x20code','replace','indexOf','substr','startsWith','length','match','error','emit','E_AGI_SOCKET_ERROR','code','close'];(function(_0x4ee2c5,_0x28a0e3){var _0x2b23a7=function(_0x2f0e8c){while(--_0x2f0e8c){_0x4ee2c5['push'](_0x4ee2c5['shift']());}};_0x2b23a7(++_0x28a0e3);}(_0x9c51,0x13c));var _0x19c5=function(_0x120b78,_0x1b727){_0x120b78=_0x120b78-0x0;var _0x2483d8=_0x9c51[_0x120b78];return _0x2483d8;};'use strict';var util=require('util');var _=require(_0x19c5('0x0'));var EventEmitter=require('events')[_0x19c5('0x1')];var AGIReply=require(_0x19c5('0x2'));var AGIError=require(_0x19c5('0x3'));function AGIChannel(_0x485392){var _0x37ae46=this,_0x521694=new AGIReply(),_0x3e626e=![],_0x569d76={};EventEmitter['call'](_0x37ae46);_0x485392[_0x19c5('0x4')](_0x19c5('0x5'));_0x485392['setTimeout'](0x8*0x3c*0x3c*0x3e8);_0x521694[_0x19c5('0x4')]('utf8');_0x521694['on'](_0x19c5('0x6'),function(_0x4157fe){for(var _0x29d5df in _0x4157fe){_0x37ae46[_0x29d5df]=_0x4157fe[_0x29d5df];}_0x37ae46['emit'](_0x19c5('0x7'));});_0x521694['on'](_0x19c5('0x8'),function(_0x5994b5){if(_0x5994b5['toLowerCase']()==_0x19c5('0x9')){_0x37ae46['emit']('hangup');return;}if(_0x5994b5[_0x19c5('0xa')](0x0,0xb)=='520-Invalid'){_0x3e626e=!![];}if(_0x3e626e){_0x569d76['rx']+=_0x5994b5+'\x0a';if(_0x5994b5[_0x19c5('0xb')]('520\x20End\x20of\x20proper')!=-0x1){_0x3e626e=![];}}else{_0x569d76['rx']=_0x5994b5;}if(_0x3e626e){return;}if(typeof _0x569d76['cb']=='function'){var _0x2a36e1=_0x569d76['rx'][_0x19c5('0xa')](0x0,0x3),_0x9523b2=null,_0x5ac08f=null;_0x2a36e1=parseInt(_0x2a36e1);if(isNaN(_0x2a36e1)){_0x569d76['cb'](null,{'code':0x1f4,'result':-0x1,'extra':_0x19c5('0xc')});return;}if(_0x2a36e1!=0xc8){_0x569d76['cb'](null,{'code':_0x2a36e1,'result':-0x1,'extra':'KO'});return;}_0x9523b2=_0x569d76['rx'][_0x19c5('0xa')](0x4)[_0x19c5('0xd')]('result=','');if(_0x9523b2[_0x19c5('0xe')]('\x20')!=-0x1){_0x9523b2=_0x9523b2[_0x19c5('0xf')](0x0,_0x9523b2['indexOf']('\x20'));}if(_[_0x19c5('0x10')](_0x9523b2,'-1')){_0x9523b2=parseInt(_0x9523b2);}_0x5ac08f=_0x569d76['rx']['split']('\x20');if(_0x5ac08f[_0x19c5('0x11')]==0x3){_0x5ac08f=_0x5ac08f[0x2][_0x19c5('0xa')](0x1,_0x5ac08f[0x2][_0x19c5('0x11')]-0x1);}else if(_0x5ac08f[_0x19c5('0x11')]>0x3){var _0x355ea3=/\((.+)\)/;var _0x2c9f3e=_0x569d76['rx'][_0x19c5('0x12')](_0x355ea3);if(_0x2c9f3e){_0x5ac08f=_0x2c9f3e[0x1];}else{_0x5ac08f=null;}}else{_0x5ac08f=null;}_0x569d76['cb'](null,{'code':_0x2a36e1,'result':_0x9523b2,'extra':_0x5ac08f});}});_0x485392['on'](_0x19c5('0x13'),function(_0x51d630){_0x37ae46[_0x19c5('0x14')](_0x19c5('0x13'),new AGIError(_0x19c5('0x15'),_0x51d630[_0x19c5('0x16')]));});_0x485392['on'](_0x19c5('0x17'),function(){_0x37ae46[_0x19c5('0x14')](_0x19c5('0x17'),new AGIError('E_AGI_SOCKET_CLOSE'));});_0x485392['on'](_0x19c5('0x18'),function(){_0x37ae46['emit']('timeout',new AGIError(_0x19c5('0x19')));_0x485392[_0x19c5('0x1a')]();});_0x485392['pipe'](_0x521694);this[_0x19c5('0x1b')]=function(_0x354855,_0x197dd3){var _0x354855=_0x354855||'',_0x197dd3=typeof _0x197dd3==_0x19c5('0x1c')?_0x197dd3:new Function();_0x569d76={'tx':_0x354855,'rx':'','cb':_0x197dd3};_0x485392[_0x19c5('0x1d')](_0x354855+'\x0a');},this[_0x19c5('0x17')]=function(){_0x485392['destroy']();};}util['inherits'](AGIChannel,EventEmitter);AGIChannel['prototype']['sendRequest']=function(_0xd78ec){return this['command'][_0x19c5('0x1e')](this,_0xd78ec);};AGIChannel['prototype']['answer']=function(){return this[_0x19c5('0x1f')](_0x19c5('0x20'));};AGIChannel[_0x19c5('0x21')][_0x19c5('0x22')]=function(_0x268aac,_0xbb7662,_0x1cf4b0){_0x268aac=_0x268aac===undefined?_0x19c5('0x23'):_0x268aac;_0xbb7662=_0xbb7662===undefined?'5':_0xbb7662;_0x1cf4b0=_0x1cf4b0===undefined?'1':_0x1cf4b0;return this[_0x19c5('0x1f')](util[_0x19c5('0x24')](_0x19c5('0x25'),_0x268aac,_0xbb7662*0x3e8,_0x1cf4b0));};AGIChannel[_0x19c5('0x21')][_0x19c5('0x26')]=function(_0x1bf443){_0x1bf443=_0x1bf443||'NO\x20MESSAGE';return this['sendRequest'](util[_0x19c5('0x24')](_0x19c5('0x27'),_0x1bf443));};AGIChannel['prototype'][_0x19c5('0x28')]=function(_0x497529,_0x3a526d){if(_[_0x19c5('0x29')](_0x3a526d)){return this[_0x19c5('0x1f')](util['format'](_0x19c5('0x2a'),_0x497529,_0x3a526d[_0x19c5('0x2b')](',')));}return this[_0x19c5('0x1f')](util[_0x19c5('0x24')](_0x19c5('0x2a'),_0x497529,_0x3a526d));};AGIChannel[_0x19c5('0x21')][_0x19c5('0x2c')]=function(_0x43ad09){return this['sendRequest'](util['format'](_0x19c5('0x2d'),_0x43ad09));};AGIChannel[_0x19c5('0x21')][_0x19c5('0x2e')]=function(_0x447152){return this[_0x19c5('0x1f')](util[_0x19c5('0x24')](_0x19c5('0x2f'),_0x447152));};AGIChannel['prototype'][_0x19c5('0x30')]=function(_0x5082d4){return this[_0x19c5('0x1f')](util[_0x19c5('0x24')](_0x19c5('0x31'),_0x5082d4));};AGIChannel['prototype'][_0x19c5('0x9')]=function(){return this['sendRequest'](_0x19c5('0x32'));};AGIChannel[_0x19c5('0x21')][_0x19c5('0x33')]=function(_0x43f47e,_0x1be924){var _0x89274d=_[_0x19c5('0x34')](_0x1be924)||_[_0x19c5('0x35')](_0x1be924)?_0x1be924['toString']():_0x1be924;return this[_0x19c5('0x1f')](util[_0x19c5('0x24')]('SET\x20VARIABLE\x20%s\x20\x22%s\x22',_0x43f47e,_0x89274d?_0x89274d[_0x19c5('0x36')]()['replace'](/(\r\n|\n|\r)/gm,'\x20'):''));};AGIChannel[_0x19c5('0x21')]['sayNumber']=function(_0x3fe507,_0x4d268b){return this['sendRequest'](util[_0x19c5('0x24')](_0x19c5('0x37'),_0x3fe507,_0x4d268b));};AGIChannel[_0x19c5('0x21')]['sayDigits']=function(_0x5bba61,_0x567c4b){return this[_0x19c5('0x1f')](util[_0x19c5('0x24')](_0x19c5('0x38'),_0x5bba61,_0x567c4b));};AGIChannel[_0x19c5('0x21')]['sayPhonetic']=function(_0x10f5fa,_0x33eb07){return this[_0x19c5('0x1f')](util[_0x19c5('0x24')]('SAY\x20PHONETIC\x20\x22%s\x22\x20%s',_0x10f5fa,_0x33eb07));};AGIChannel[_0x19c5('0x21')]['continueAt']=function(_0x378fa8,_0x307fe0,_0x122b85){_0x307fe0=_0x307fe0||this[_0x19c5('0x39')];_0x122b85=_0x122b85||0x1;this[_0x19c5('0x2c')](_0x378fa8);this[_0x19c5('0x2e')](_0x307fe0);this['setPriority'](_0x122b85);return this[_0x19c5('0x26')](util[_0x19c5('0x24')]('GOTO\x20%s\x20%s\x20%s',_0x378fa8,_0x307fe0,_0x122b85));};AGIChannel[_0x19c5('0x21')][_0x19c5('0x3a')]=function(_0x16823b){return this[_0x19c5('0x1f')](util[_0x19c5('0x24')](_0x19c5('0x3b'),_0x16823b));};AGIChannel[_0x19c5('0x21')]['recordFile']=function(_0x1a7354,_0x1e5278,_0x1b385c,_0x26d4f4,_0x3b26cf,_0x4ec4c9){_0x1e5278=_0x1e5278||'wav';_0x1b385c=_0x1b385c||'';_0x26d4f4=_0x26d4f4===undefined?-0x1:_0x26d4f4==='-1'?-0x1:_0x26d4f4*0x3e8;_0x3b26cf=_0x3b26cf===undefined?'':'s='+_0x3b26cf;_0x4ec4c9=_0x4ec4c9?_0x19c5('0x3c'):'';return this[_0x19c5('0x1f')](util[_0x19c5('0x24')]('RECORD\x20FILE\x20\x22%s\x22\x20\x22%s\x22\x20\x22%s\x22\x20%s\x20%s\x20%s',_0x1a7354,_0x1e5278,_0x1b385c,_0x26d4f4,_0x4ec4c9,_0x3b26cf));};AGIChannel[_0x19c5('0x21')][_0x19c5('0x3d')]=function(_0x5cc486,_0x1efbbd){_0x1efbbd=_0x1efbbd||'';return this[_0x19c5('0x1f')](util[_0x19c5('0x24')]('STREAM\x20FILE\x20\x22%s\x22\x20\x22%s\x22',_0x5cc486,_0x1efbbd));};AGIChannel[_0x19c5('0x21')][_0x19c5('0x3e')]=function(_0x5d946b){return this[_0x19c5('0x28')](_0x19c5('0x3f'),_0x5d946b);};AGIChannel[_0x19c5('0x21')][_0x19c5('0x40')]=function(_0xdc9529){return this[_0x19c5('0x28')](_0x19c5('0x41'),_0xdc9529);};AGIChannel[_0x19c5('0x21')][_0x19c5('0x13')]=function(_0x2a220b,_0x21dee0){this['noop'](util['format'](_0x19c5('0x42'),_0x2a220b['id'],_0x2a220b['label'],_0x21dee0));return{'code':0x1f4,'result':'-1','extra':''};};module[_0x19c5('0x43')]=AGIChannel;