@gibme/asterisk-gateway-interface 4.0.4 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/channel.d.ts CHANGED
@@ -1,10 +1,32 @@
1
- import { Socket } from '@gibme/tcp-server';
2
1
  import { EventEmitter } from 'events';
3
- import { ChannelDriver, ChannelState, DialStatus, IResponse, PlaybackStatus } from './types';
2
+ import type { Socket } from '@gibme/tcp-server';
3
+ import { ResponseArguments } from './response_arguments';
4
+ export { ResponseArguments };
5
+ /**
6
+ * The current context state
7
+ */
8
+ export declare enum ContextState {
9
+ INIT = 0,
10
+ WAITING = 2
11
+ }
12
+ /**
13
+ * Represents the channel driver type
14
+ */
15
+ export declare enum Driver {
16
+ DHAHDI = "DHAHDI",
17
+ SIP = "SIP",
18
+ PJSIP = "PJSIP",
19
+ IAX2 = "IAX2",
20
+ LOCAL = "Local",
21
+ SCCP = "SCCP",
22
+ OSS = "OSS",
23
+ MOTIF = "Motif",
24
+ UNKNOWN = ""
25
+ }
4
26
  /**
5
27
  * Represents an AGI Channel
6
28
  */
7
- export default class Channel extends EventEmitter {
29
+ export declare class Channel extends EventEmitter {
8
30
  private readonly _connection;
9
31
  private _state;
10
32
  private _message;
@@ -14,6 +36,11 @@ export default class Channel extends EventEmitter {
14
36
  * @param connection the AGI socket connection
15
37
  */
16
38
  constructor(connection: Socket);
39
+ private _outgoingHeaders;
40
+ /**
41
+ * Headers that have been set for **outgoing** requests
42
+ */
43
+ get outgoingHeaders(): Record<string, string>;
17
44
  private _network;
18
45
  /**
19
46
  * Whether this AGI request is over the network
@@ -22,7 +49,7 @@ export default class Channel extends EventEmitter {
22
49
  private _network_script;
23
50
  /**
24
51
  * The network path included in the AGI request
25
- * ie. agi://127.0.0.1:3000/test
52
+ * e.g. agi://127.0.0.1:3000/test
26
53
  * This value would return 'test'
27
54
  */
28
55
  get network_script(): string;
@@ -46,7 +73,7 @@ export default class Channel extends EventEmitter {
46
73
  /**
47
74
  * The originating channel type (e.g. “SIP” or “ZAP”)
48
75
  */
49
- get type(): ChannelDriver;
76
+ get type(): Driver;
50
77
  private _uniqueid;
51
78
  /**
52
79
  * A unique ID for the call
@@ -182,7 +209,7 @@ export default class Channel extends EventEmitter {
182
209
  * @param event
183
210
  * @param listener
184
211
  */
185
- on(event: 'response', listener: (response: IResponse) => void): this;
212
+ on(event: 'response', listener: (response: Channel.Response) => void): this;
186
213
  /**
187
214
  * Event that is emitted when data is sent to the Asterisk server
188
215
  * @param event
@@ -202,7 +229,7 @@ export default class Channel extends EventEmitter {
202
229
  * Returns status of the connected channel.
203
230
  * @param channel
204
231
  */
205
- channelStatus(channel?: string): Promise<ChannelState>;
232
+ channelStatus(channel?: string): Promise<Channel.State>;
206
233
  /**
207
234
  * Sends audio file on channel and allows the listener to control the stream.
208
235
  * @param filename
@@ -214,7 +241,7 @@ export default class Channel extends EventEmitter {
214
241
  */
215
242
  controlStreamFile(filename: string, escapeDigits?: string, skipms?: number, fastForwardCharacter?: string, rewindCharacter?: string, pauseCharacter?: string): Promise<{
216
243
  digit: string;
217
- playbackStatus: PlaybackStatus;
244
+ playbackStatus: Channel.Playback.Status;
218
245
  playbackOffset: number;
219
246
  }>;
220
247
  /**
@@ -228,7 +255,7 @@ export default class Channel extends EventEmitter {
228
255
  params: string;
229
256
  hangupOnComplete: boolean;
230
257
  }>): Promise<{
231
- status: DialStatus;
258
+ status: Channel.Dial.Status;
232
259
  dialed_time: number;
233
260
  answered_time: number;
234
261
  peer_name: string;
@@ -263,7 +290,7 @@ export default class Channel extends EventEmitter {
263
290
  databasePut(family: string, key: string, value: string): Promise<string>;
264
291
  /**
265
292
  * Executes application with given options
266
- * @param application.
293
+ * @param application
267
294
  * @param args
268
295
  */
269
296
  exec(application: string, ...args: string[]): Promise<number>;
@@ -282,8 +309,9 @@ export default class Channel extends EventEmitter {
282
309
  * Understands complex variable names and builtin variables, unlike GET VARIABLE.
283
310
  * @param key
284
311
  * @param channel
312
+ * @param keyToUpper
285
313
  */
286
- getFullVariable(key: string, channel?: string): Promise<string>;
314
+ getFullVariable(key: string, channel?: string, keyToUpper?: boolean): Promise<string>;
287
315
  /**
288
316
  * Stream file, prompt for DTMF, with timeout.
289
317
  * Behaves similar to STREAM FILE but used with a timeout option.
@@ -298,8 +326,9 @@ export default class Channel extends EventEmitter {
298
326
  /**
299
327
  * Gets a channel variable.
300
328
  * @param key
329
+ * @param keyToUpper whether to force the key to uppercase
301
330
  */
302
- getVariable(key: string): Promise<string>;
331
+ getVariable(key: string, keyToUpper?: boolean): Promise<string>;
303
332
  /**
304
333
  * Cause the channel to execute the specified dialplan subroutine.
305
334
  * @param context
@@ -308,11 +337,33 @@ export default class Channel extends EventEmitter {
308
337
  * @param argument
309
338
  */
310
339
  goSub(context: string, extension: string, priority: number, argument?: string): Promise<void>;
340
+ /**
341
+ * Indicates busy to the calling channel
342
+ *
343
+ * @param timeout if specified, the calling channel will be hung up after the specified number of seconds.
344
+ * Otherwise, this application will wait until the calling channel hangs up
345
+ */
346
+ busy(timeout?: number): Promise<number>;
347
+ /**
348
+ * Indicates congestion to the calling channel
349
+ *
350
+ * @param timeout if specified, the calling channel will be hung up after the specified number of seconds.
351
+ * Otherwise, this application will wait until the calling channel hangs up
352
+ */
353
+ congestion(timeout?: number): Promise<number>;
311
354
  /**
312
355
  * Hangs up the specified channel. If no channel name is given, hangs up the current channel
313
356
  * @param channel
314
357
  */
315
358
  hangup(channel?: string): Promise<void>;
359
+ /**
360
+ * Requests that in-band progress information be provided to the calling channel
361
+ */
362
+ progress(): Promise<number>;
363
+ /**
364
+ * Requests that the channel indicate a ringing tone to the user
365
+ */
366
+ ringing(): Promise<number>;
316
367
  /**
317
368
  * Does nothing
318
369
  */
@@ -437,14 +488,14 @@ export default class Channel extends EventEmitter {
437
488
  * @param value
438
489
  */
439
490
  setVariable(key: string, value: string): Promise<void>;
440
- speechActivateGrammar(grammar: string): Promise<IResponse>;
441
- speechCreate(engine: string): Promise<IResponse>;
442
- speechDeactivateGrammar(grammar: string): Promise<IResponse>;
443
- speechDestroy(): Promise<IResponse>;
444
- speechLoadGrammar(grammar: string, path: string): Promise<IResponse>;
445
- speechRecognize(soundFile: string, timeout: number | undefined, offset: number): Promise<IResponse>;
446
- speechSet(key: string, value: string): Promise<IResponse>;
447
- speedUnloadGrammar(grammar: string): Promise<IResponse>;
491
+ speechActivateGrammar(grammar: string): Promise<Channel.Response>;
492
+ speechCreate(engine: string): Promise<Channel.Response>;
493
+ speechDeactivateGrammar(grammar: string): Promise<Channel.Response>;
494
+ speechDestroy(): Promise<Channel.Response>;
495
+ speechLoadGrammar(grammar: string, path: string): Promise<Channel.Response>;
496
+ speechRecognize(soundFile: string, timeout: number | undefined, offset: number): Promise<Channel.Response>;
497
+ speechSet(key: string, value: string): Promise<Channel.Response>;
498
+ speedUnloadGrammar(grammar: string): Promise<Channel.Response>;
448
499
  /**
449
500
  * Sends audio file on channel.
450
501
  * @param filename
@@ -472,21 +523,28 @@ export default class Channel extends EventEmitter {
472
523
  */
473
524
  waitForDigit(timeout?: number): Promise<string>;
474
525
  /**
475
- * Adds a SIP header to the outbound call
526
+ * Attempts to retrieve the inbound header specified from the channel
527
+ *
528
+ * Note: This method can only read headers on the **incoming** request. It can not
529
+ * read headers set on an **outbound** SIP request.
530
+ *
531
+ * @param key
532
+ */
533
+ getHeader(key: string): Promise<string | undefined>;
534
+ /**
535
+ * Adds a header to the **outgoing** request
476
536
  *
477
537
  * @param key
478
538
  * @param value
479
539
  */
480
540
  addHeader(key: string, value: string): Promise<void>;
481
541
  /**
482
- * Allows you to remove headers which were previously added with PJSIPAddHeader().
483
- * If no parameter is supplied, all previously added headers will be removed.
484
- * If a parameter is supplied, only the matching headers will be removed
542
+ * Allows you to remove a header from the **outgoing** request as long as you
543
+ * have added it via the `addHeader()` method.
485
544
  *
486
545
  * @param key
487
- * @param wildcard
488
546
  */
489
- removeHeader(key?: string, wildcard?: boolean): Promise<void>;
547
+ removeHeader(key: string): Promise<void>;
490
548
  /**
491
549
  * Evaluates a channel expression
492
550
  * Understands complex variable names and builtin variables, unlike GET VARIABLE.
@@ -506,7 +564,6 @@ export default class Channel extends EventEmitter {
506
564
  *
507
565
  * @param key
508
566
  * @param value
509
- * @constructor
510
567
  * @private
511
568
  */
512
569
  private IAX2AddHeader;
@@ -514,7 +571,6 @@ export default class Channel extends EventEmitter {
514
571
  * Removes an IAX2 'header' from the outbound call
515
572
  *
516
573
  * @param key
517
- * @constructor
518
574
  * @private
519
575
  */
520
576
  private IAX2RemoveHeader;
@@ -523,17 +579,13 @@ export default class Channel extends EventEmitter {
523
579
  *
524
580
  * @param key
525
581
  * @param value
526
- * @constructor
527
582
  * @private
528
583
  */
529
584
  private PJSIPAddHeader;
530
585
  /**
531
586
  * Allows you to remove headers which were previously added with PJSIPAddHeader().
532
- * If no parameter is supplied, all previously added headers will be removed.
533
- * If a parameter is supplied, only the matching headers will be removed
534
587
  *
535
588
  * @param key
536
- * @param wildcard
537
589
  * @private
538
590
  */
539
591
  private PJSIPRemoveHeader;
@@ -546,12 +598,8 @@ export default class Channel extends EventEmitter {
546
598
  private SIPAddHeader;
547
599
  /**
548
600
  * SIPRemoveHeader() allows you to remove headers which were previously added with SIPAddHeader().
549
- * If no parameter is supplied, all previously added headers will be removed.
550
- * If a parameter is supplied, only the matching headers will be removed.
551
601
  *
552
602
  * @param key
553
- * @param wildcard
554
- * @constructor
555
603
  */
556
604
  private SIPRemoveHeader;
557
605
  /**
@@ -611,3 +659,55 @@ export default class Channel extends EventEmitter {
611
659
  */
612
660
  private sendCommand;
613
661
  }
662
+ export declare namespace Channel {
663
+ /**
664
+ * The Current Channel State
665
+ */
666
+ enum State {
667
+ DOWN_AVAILABLE = 0,
668
+ DOWN_RESERVED = 1,
669
+ OFF_HOOK = 2,
670
+ DIGITS_DIALED = 3,
671
+ RINGING = 4,
672
+ REMOTE_RINGING = 5,
673
+ UP = 6,
674
+ BUSY = 7
675
+ }
676
+ namespace Dial {
677
+ /**
678
+ * Represents the result of a Dial() attempt
679
+ */
680
+ enum Status {
681
+ ANSWER = 0,
682
+ BUSY = 1,
683
+ NOANSWER = 2,
684
+ CANCEL = 3,
685
+ CONGESTION = 4,
686
+ CHANUNAVAIL = 5,
687
+ DONTCALL = 6,
688
+ TORTURE = 7,
689
+ INVALIDARGS = 8,
690
+ UNKNOWN = 9999
691
+ }
692
+ }
693
+ namespace Playback {
694
+ /**
695
+ * Represents the playback status
696
+ */
697
+ enum Status {
698
+ SUCCESS = 0,
699
+ USER_STOPPED = 1,
700
+ REMOTE_STOPPED = 2,
701
+ ERROR = 3
702
+ }
703
+ }
704
+ /**
705
+ * Responses a response to a channel command
706
+ */
707
+ type Response = {
708
+ code: number;
709
+ result: number;
710
+ arguments: ResponseArguments;
711
+ };
712
+ }
713
+ export default Channel;