-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnode-shift8.js
1340 lines (1164 loc) · 36.1 KB
/
node-shift8.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var http = require('http');
var https = require('https');
var events = require('events');
var libxmljs = require("libxmljs");
var winston = require('winston');
Shift8 = function( options ) {
var self = this;
var options = options || {};
/**
* The ip address of the remote asterisk server
*
* @var string
*/
this.server = options.server || null;
/**
* The port on which the remote asterisk server is listening
*
* @var int
*/
this.port = options.port || 8088;
/**
* The location of the AJAM interface on the remote server
*
* @var string
*/
this.ajam = options.ajam || '/mxml';
/**
* The manager to use to connect with
*
* @var string
*/
this.manager = options.manager || null;
/**
* The secret of the manager to connect with
*
* @var string
*/
this.secret = options.secret || null;
/**
* Use https to connect to remote server
*
* @var boolean
*/
this.useHttps = options.useHttps || false;
/**
* The client to the remove AJAM interface
*
* @var object
*/
this.client;
/**
* The session id from the remote asterisk
*
* @var string
*/
this.sessionId;
/**
* The XML Parser
*
* @var object
*/
this.parser;
this.connected = (this.sessionId != null);
events.EventEmitter.call(this);
};
Shift8.super_ = events.EventEmitter;
Shift8.prototype = Object.create(events.EventEmitter.prototype, {
constructor: {
value: Shift8,
enumerable: false
}
});
module.exports = Shift8;
/**
* Basic function of the whole library, responsible for dispatching the messages to the
* remote asterisk
*
* @param array parameters The parameters to pass to the remote AJAM
* @param function callback The callback function to execute on return
*/
Shift8.prototype.send = function( parameters, callback ) {
var self = this;
var url = parameters.ajam || self.ajam;
url += "?";
for( var key in parameters ) {
url += key + "=" + encodeURIComponent(parameters[key]) + "&";
}
//winston.debug("Performing request on: " + url);
var request = http.request({
host: self.server,
port: self.port,
path: url,
method: 'GET',
headers: {
'Host': self.server,
'Cookie': (self.sessionId) ? "mansession_id=\"" + self.sessionId + "\"" : ""
}
}, function(response) {
var buffer = [];
// Fix the XML a bit
buffer.push("<?xml version='1.0' encoding='UTF-8'?>");
response.on('data', function(chunk) {
buffer.push(chunk);
});
response.on('end', function() {
var cookie = response.headers['set-cookie'];
if (cookie) {
cookie = (cookie + "").split(";").shift()
if( cookie ) {
self.sessionId = cookie.split("=").pop().replace(/"/g, "");
}
}
buffer = buffer.join("").replace(/\n/g, "");
//winston.debug(buffer);
try {
var xml = libxmljs.parseXmlString(buffer);
} catch( exception ) {
self.emit('error', "Unable to process response retrieved from the remote asterisk: " + exception);
//winston.error("Unable to process response retrieved from the remote asterisk (" + exception + ")");
return;
}
var results = xml.find("///generic");
// First in array is always the response to the command sent
if( results[0].attr('response') && results[0].attr('response').value() == 'Error') {
callback && callback( (results[0].attr('message')) ? results[0].attr('message').value() : "Unable to process command" );
}
else {
var events = [];
for( var c in results ) {
var event = {};
var attributes = results[c].attrs();
for ( var i in attributes ) {
var variable = attributes[i].name();
event[variable] = attributes[i].value();
}
// Handle the AsyncAGI environment
if( event.event == 'AsyncAGI' && event.subevent == 'Start' && event.env != null ) {
var env = decodeURIComponent(event.env);
var lines = env.split("\n");
var environment = {};
for( i = 0; i < lines.length; i++ ) {
var data = lines[i].split(":");
if( data.length != 2 )
continue;
var variable = data[0];
environment[variable] = data[1].trim();
}
event['environment'] = environment;
}
events.push(event);
}
callback && callback(null, events);
}
});
response.on('error', function( error ) {
self.emit('error', "Unable to receive response from remote asterisk: " + error);
//winston.error("Unable to receive response from remote asterisk: " + error);
});
});
request.on('error', function(error) {
self.emit('error', "Unable to perform the request on the remote asterisk: " + error);
//winston.error("Unable to perform the request on the remote asterisk: " + error);
});
request.end();
};
/**
* Kick a ConfBridge member
*
* @param string conference The conference id to kick the member of
* @param string channel The channel of the member to kick
* @param function callback The callback function if any to execute when the command has finished
*
*/
Shift8.prototype.kickConfBridgeMember = function( conference, channel, callback ) {
this.send({
'Action' : 'ConfbridgeKick',
'Conference' : conference,
'Channel' : channel
}, callback);
};
/**
* Login to the remote asterisk's manager interface. Will emit the 'connected' event on connection
*/
Shift8.prototype.login = function() {
var self = this;
self.send({
'Action': 'login',
'Username': self.manager,
'Secret': self.secret
}, function( error, response ) {
if( error ) {
self.emit('error', "Unable to connect to remote asterisk (" + error + ")");
}
else {
self.emit('connected');
}
});
};
/**
* Logoffs from the remote asterisk's manager interface. Will emit the 'disconnected' event on completion
*/
Shift8.prototype.logoff = function() {
this.send({
'Action': 'logoff'
}, function( error, response ) {
if( error ) {
self.emit('error', "Unable to connect to remote asterisk (" + error + ")");
}
else {
self.emit('disconnected');
}
});
};
/**
* Wait for asterisk to send us events. This will emit 'event' which can be listened
*
* @param boolean perm Whether the waitEvent is permanent. (On WaitEventComplete to fire a new event)
*/
Shift8.prototype.waitEvent = function( perm ) {
var self = this;
this.send({
'Action': 'WaitEvent'
}, function( error, events ) {
if( error ) {
self.emit('error', error);
return;
}
for( var c in events ) {
self.emit('event', events[c]);
if( events[c].event == 'WaitEventComplete' && perm ) {
self.waitEvent(perm);
}
}
});
};
/**
* Adds a new interface in the Queue
*
* @param string queue The queue to add the interface to
* @param string interface The interface to add to the queue
* @param string member The member name for this interface
* @param int penalty The penalty for this agent
* @param boolean paused Whether the agent will be paused on login
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.queueAddInterface = function( queue, interface, member, penalty, paused, callback ) {
var parameters = {
'Action': 'QueueAdd',
'Queue': queue,
'Interface': interface
};
if( member )
parameters.MemberName = member;
if( penalty )
parameters.Penalty = penalty;
if( paused )
parameters.Paused = 1;
this.send(parameters, callback);
};
/**
* Remove an interface from the Queue
*
* @param string queue The queue to remove the interface from
* @param string interface The interface to remove from the queue
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.queueRemoveInterface = function( queue, interface, callback ) {
this.send({
'Action': 'QueueRemove',
'Queue': queue,
'Interface': interface
}, callback);
};
/**
* Changes the paused status of an interface.
*
* @param string inteface The interface to change the status
* @param integer paused The paused value. 1 for Paused, 0 for Unpaused
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.changeQueuePaused = function( interface, paused, callback ) {
this.send({
'Action': 'QueuePause',
'Interface': interface,
'Paused': paused
}, callback);
};
/**
* Performs an agent pause on the interface
*
* @param string interface The interface to pause
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.pauseQueueInterface = function( interface, callback ) {
this.changeQueuePaused( interface, 1, callback );
};
/**
* Performs an agent un-pause on the interface
*
* @param string interface The interface to unpause
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.unpauseQueueInterface = function( interface, callback ) {
this.changeQueuePaused( interface, 0, callback );
};
/**
* Retrieves the status from the Queues mechanism. It can retrieve either the status for all the Queues
* or the status for a specific queue/queue member
*
* @param string queue The queue to retrieve status for. (Optional)
* @param string member The member to retrieve status for. (Optional)
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getQueueStatus = function( queue, member, callback ) {
var parameters = {
'Action': 'QueueStatus'
};
if( queue )
parameters.Queue = queue;
if( member )
parameters.Member = member;
this.send( parameters, callback );
};
/**
* Retrieves the Queue summary for a specific queue if one has been defined, or for the entire system
*
* @param string queue The queue to get the summary for. If not specified the summary for all the queues is returned
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getQueueSummary = function( queue, callback ) {
var parameters = {
'Action': 'QueueSummary'
};
if( queue )
parameters.Queue = queue;
this.send(parameters, callback);
};
/**
* Lists agents and their status
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getAgents = function( callback ) {
this.send({
'Action': 'Agents'
}, callback);
};
/**
* Get a queue rule
*
* @param string rule The queue rule to get
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getQueueRule = function( rule, callback ) {
this.send({
'Action': 'QueueRule',
'Rule' : rule
}, callback);
};
/**
* Sets the Queue Penalty for a member
*
* @param string member The queue member to set the penalty
* @param string queue The queue this member
* @param integer penalty The penalty to set
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.setQueueMemberPenalty = function( member, queue, penalty, callback ) {
this.send({
'Action': 'QueuePenalty',
'Interface': member,
'Queue' : queue,
'Penalty': penalty
}, callback);
};
/**
* Get the queues from the remote asterisk server
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getQueues = function( callback ) {
this.send({
'Action': 'Queues'
}, callback);
};
/**
* Allows you to write your own events into the queue log
*
* @param string queue The queue to write the event for
* @param integer unique_id The unique id for the queue log
* @param string interface The interface for the log
* @param string event The actual event that needs to be recorded
* @param string message The message to log in the queue log
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.addQueueLog = function( queue, unique_id, interface, event, message, callback ) {
this.send({
'Action': 'QueueLog',
'Queue' : queue,
'UniqueID': unique_id,
'Interface': interface,
'Event' : event,
'Message': message
}, callback);
};
/**
* Get a SIP Peer from the remote asterisk as specified by peer
*
* @param string peer The peer to get information for
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getSipPeer = function( peer, callback ) {
this.send({
'Action': 'sipshowpeer',
'Peer' : peer
}, callback);
};
/**
* Retrieve the SIP Peers from the remote asterisk server
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getSipPeers = function( callback ) {
this.send({
'Action': 'SipPeers'
}, callback);
};
/**
* Plays a dtmf digit on the specified channel
*
* @param string dtmf The dtmf digit to play
* @param string channel Channel name to send digit to
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.playDTMF = function( dtmf, channel, callback ) {
this.send({
'Action': 'PlayDTMF',
'Channel': channel,
'Digit' : dtmf
}, callback);
};
/**
* Sends a SIP Notify message to a peer
*
* @param string channel The channel to sent the notify
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.sentSIPNotify = function( channel, callback ) {
this.send({
'Action': 'SIPnotify',
'Channel': channel
}, callback);
};
/**
* Retrieves the SIP Registry from the remote Asterisk server
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getSipRegistry = function( callback ) {
this.send({
'Action': 'SIPshowregistry'
}, callback);
};
/**
* List All Voicemail User Information
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getVoicemailUsers = function( callback ) {
this.send({
'Action': 'VoicemailUsersList'
}, callback);
};
/**
* Retrieves the IAX Peers from the remote asterisk server
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getIAXPeers = function( callback ) {
this.send({
'Action': 'IAXpeers'
}, callback);
};
/**
* Retrieves the IAX Peers from the remote asterisk server
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getIAXPeerList = function( callback ) {
this.send({
'Action': 'IAXpeerlist'
}, callback);
};
/**
* Retrieve the IAX Net stats
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getIAXNetStats = function( callback ) {
this.send({
'Action': 'IAXnetstats'
}, callback);
};
/**
* Unpauses monitoring of a channel on which monitoring had previously been paused with PauseMonitor.
*
* @param string channel The channel to unpause monitor
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.unpauseMonitor = function( channel, callback ) {
this.send({
'Action': 'UnpauseMonitor',
'Channel': channel
}, callback);
};
/**
* The 'PauseMonitor' action may be used to temporarily stop the recording of a channel
*
* @param string channel The channel to pause monitor
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.pauseMonitor = function( channel, callback ) {
this.send({
'Action': 'PauseMonitor',
'Channel': channel
}, callback);
};
/**
* Change monitoring filename of a channel. Has no effect if the channel is not monitored
*
* @param string channel Used to specify the channel to record
* @param string file Is the new name of the file created in the monitor spool directory
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.changeMonitor = function( channel, file, callback ) {
this.send({
'Action': 'ChangeMonitor',
'Channel': channel,
'File' : file
}, callback);
};
/**
* Stops monitoring a channel. Has no effect if the channel is not monitored
*
* @param string channel The channel to stop monitoring
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.stopMonitor = function( channel, callback ) {
this.send({
'Action': 'StopMonitor',
'Channel': channel
}, callback);
};
/**
* The 'Monitor' action may be used to record the audio on a specified channel.
*
* @param string channel Used to specify the channel to record
* @param string file Is the name of the file created in the monitor spool directory. Defaults to the same name as the channel (with slashes replaced with dashes)
* @param string format Is the audio recording format. Defaults to wav
* @param boolean mix Boolean parameter as to whether to mix the input and output channels together after the recording is finished
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.monitor = function( channel, file, format, mix, callback ) {
var parameters = {
'Action': 'Monitor',
'Channel': channel
};
if( file )
parameters.File = file;
if( format )
parameters.Format = format;
if( mix )
parameters.Mix = 1;
this.send(parameters, callback);
};
/**
* Send a message to a Jabber Channel
*
* @param string jabber Client or transport Asterisk uses to connect to JABBER
* @param string screenName User Name to message.
* @param string message Message to be sent to the buddy
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.sendMessageToJabberChannel = function( jabber, screenName, message, callback ) {
this.send({
'Action': 'JabberSend',
'Jabber': jabber,
'ScreenName': screenName,
'Message': message
}, callback);
};
/**
* Add a new command to execute by the Async AGI application
*
* @param string channel The channel to execute the command at
* @param string command The command to execute
* @param string command_id The command id
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.AGI = function( channel, command, command_id, callback ) {
this.send({
'Action': 'AGI',
'Channel': channel,
'Command': command,
'CommandID': command_id
}, callback);
};
/**
* Removes database keytree/values
*
* @param string family
* @param string key (Optional)
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.DBDelTree = function( family, key, callback ) {
var parameters = {
'Action': 'DBDelTree',
'Family': family
};
if( key )
parameters.Key = key;
this.send( parameters, callback );
};
/**
* Removes database key/value
*
* @param string family
* @param string key
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.DBDel = function( family, key, callback ) {
this.send({
'Action': 'DBDel',
'Family': family,
'Key' : key
}, callback);
this.send( parameters, callback );
};
/**
* Gets a database value
*
* @param string family
* @param string key
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.DBGet = function( family, key, callback ) {
this.send({
'Action': 'DBGet',
'Family': family,
'Key' : key
}, callback);
};
/**
* Adds / updates a database value
*
* @param string family
* @param string key
* @param string value (Optional)
*/
Shift8.prototype.DBPut = function( family, key, value, callback ) {
this.send({
'Action': 'DBPut',
'Family': family,
'Key' : key,
'Val' : (value) ? value : ''
}, callback);
};
/**
* Bridge channels together
*
* @param string channelA The first channel to bridge
* @param string channelB The second channel to bridge
* @param string tone Play a tone to the bridged channels. (Optional)
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.bridge = function( channelA, channelB, callback ) {
var parameters = {
'Action': 'Bridge',
'Channel1': channelA,
'Channel2': channelB
};
if( tone )
parameters.Tone = tone;
this.send(parameters, callback);
};
/**
* Park a channel
*
* @param string channelA
* @param string channelB
* @param integer timeout
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.park = function( channelA, channelB, timeout, callback ) {
var parameters = {
'Action': 'Bridge',
'Channel': channelA,
'Channel2': channelB
};
if( timeout )
parameters.Timeout = timeout;
this.send( parameters, callback );
};
/**
* List parked calls
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getParkedCalls = function( callback ) {
this.send({
'Action': 'ParkedCalls'
}, callback);
};
/**
* Show dialplan extensions
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getDialplan = function( callback ) {
this.send({
'Action': 'ShowDialPlan'
}, callback);
};
/**
* Checks if Asterisk module is loaded
*
* @param string module Asterisk module name (not including extension)
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.isModuleLoaded = function( module, callback ) {
this.send({
'Action': 'ModuleCheck',
'Module': module
}, callback);
};
/**
* Loads, unloads or reloads an Asterisk module in a running system.
* If no module is specified for a reload loadtype, all modules are reloaded
*
* @param string module Asterisk module name (not including extension) or subsystem identifier: cdr, enum, dnsmgr, extconfig, manager, rtp, http (Optional)
* @param string loadType load | unload | reload The operation to be done on module
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.loadModule = function( module, loadType, callback ) {
var parameters = {
'Action': 'ModuleLoad',
'LoadType': loadType
};
if( loadType != 'reload' && !module )
return false;
if( module )
parameters.Module = module;
this.send( parameters, callback );
};
/**
* List currently defined channels and some information about them.
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getActiveChannels = function( callback ) {
this.send({
'Action': 'CoreShowChannels'
}, callback);
};
/**
* Send a reload event. Works the same as sending a ModuleLoad event (reload) without specifying
* any modules
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.reload = function( callback ) {
this.send({
'Action': 'Reload'
}, callback);
};
/**
* Show PBX core status information
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getCoreStatusVariables = function( callback ) {
this.send({
'Action': 'CoreStatus'
}, callback);
};
/**
* Show PBX core settings information
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getCoreSettings = function( callback ) {
this.send({
'Action': 'CoreSettings'
}, callback);
}
/**
* Send an event to manager sessions
*
* @param string userEvent Event string to send
* @param function callback The callback function if any to execute when the command has finished
*
* @todo This might need something more. Header1-N handling
*/
Shift8.prototype.sendUserEvent = function( userEvent, callback ) {
this.send({
'Action': 'UserEvent',
'UserEvent': userEvent
}, callback);
};
/**
* Sends A Text Message while in a call
*
* @param string channel Channel to send message to
* @param string message Message to send
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.sendText = function( channel, message, callback ) {
this.send({
'Action': 'SendText',
'Channel': channel,
'Message': message
}, callback);
};
/**
* Returns the action name and synopsis for every action that is available to the use
*
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.listCommands = function( callback ) {
this.send({
'Action': 'ListCommands'
}, callback);
};
/**
* Checks a voicemail account for new messages.
*
* @param string mailbox Full mailbox ID <mailbox>@<vm-context>
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getMailboxCount = function( mailbox, callback ) {
this.send({
'Action': 'MailboxCount',
'Mailbox': mailbox
}, callback);
};
/**
* Checks a voicemail account for status
*
* @param string mailbox Full mailbox ID <mailbox>@<vm-context>
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.getMailboxStatus = function( mailbox, callback ) {
this.send({
'Action': 'MailboxStatus',
'Mailbox': mailbox
}, callback);
};
/**
* Hangup a channel after a certain time.
*
* @param string channel Channel name to hangup
* @param integer timeout Maximum duration of the call (sec)
* @param function callback The callback function if any to execute when the command has finished
*/
Shift8.prototype.setAbsoluteTimeout = function( channel, timeout, callback ) {
this.send({
'Action': 'AbsoluteTimeout'
}, callback);
};
/**
* Report the extension state for given extension. If the extension has a hint, will use devicestate to check