From 14dee133acca04c18ef4772661c8262313deb2ed Mon Sep 17 00:00:00 2001 From: Dioris Moreno Date: Mon, 20 Apr 2020 16:29:06 -0500 Subject: [PATCH] Add type definitions for ari-client (#43942) * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client * Add type definitions for ari-client --- types/ari-client/index.d.ts | 1835 +++++++++++++++++ types/ari-client/test/bridge.ts | 56 + types/ari-client/test/bridgeAsyncAwait.ts | 50 + types/ari-client/test/deviceState.ts | 56 + .../ari-client/test/deviceStateAsyncAwait.ts | 72 + types/ari-client/test/example.ts | 50 + types/ari-client/test/exampleAsyncAwait.ts | 52 + types/ari-client/test/mwi.ts | 101 + types/ari-client/test/mwiAsyncAwait.ts | 99 + types/ari-client/test/originate.ts | 55 + types/ari-client/test/originateAsyncAwait.ts | 55 + types/ari-client/test/playback.ts | 54 + types/ari-client/test/playbackAsyncAwait.ts | 52 + types/ari-client/tsconfig.json | 35 + types/ari-client/tslint.json | 3 + 15 files changed, 2625 insertions(+) create mode 100644 types/ari-client/index.d.ts create mode 100644 types/ari-client/test/bridge.ts create mode 100644 types/ari-client/test/bridgeAsyncAwait.ts create mode 100644 types/ari-client/test/deviceState.ts create mode 100644 types/ari-client/test/deviceStateAsyncAwait.ts create mode 100644 types/ari-client/test/example.ts create mode 100644 types/ari-client/test/exampleAsyncAwait.ts create mode 100644 types/ari-client/test/mwi.ts create mode 100644 types/ari-client/test/mwiAsyncAwait.ts create mode 100644 types/ari-client/test/originate.ts create mode 100644 types/ari-client/test/originateAsyncAwait.ts create mode 100644 types/ari-client/test/playback.ts create mode 100644 types/ari-client/test/playbackAsyncAwait.ts create mode 100644 types/ari-client/tsconfig.json create mode 100644 types/ari-client/tslint.json diff --git a/types/ari-client/index.d.ts b/types/ari-client/index.d.ts new file mode 100644 index 0000000000..bcd8adea4c --- /dev/null +++ b/types/ari-client/index.d.ts @@ -0,0 +1,1835 @@ +// Type definitions for ari-client 2.2 +// Project: https://github.com/asterisk/node-ari-client +// Definitions by: Dioris Moreno +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export function connect( + baseUrl: string, + user: string, + pass: string, + callback?: (err: Error, client: Client) => void, +): Promise; + +export interface Client extends Resource { + /* Start and Stop Method Overloads */ + start(apps: string | string[], subscribeAll: boolean, callback?: (err: Error, ...args: any[]) => void): void; + start(apps: string | string[], callback?: (err: Error, ...args: any[]) => void): void; + stop(): void; + /* Properties */ + applications: Applications; + asterisk: Asterisk; + channels: Channels; + bridges: Bridges; + deviceStates: DeviceStates; + endpoints: Endpoints; + recordings: Recordings; + mailboxes: Mailboxes; + playbacks: Playbacks; + sounds: Sounds; + events: Events; + /* Create Methods */ + Application(id?: string, objValues?: object): Application; + Asterisk(id?: string, objValues?: object): Asterisk; + Channel(id?: string, objValues?: object): Channel; + Bridge(id?: string, objValues?: object): Bridge; + DeviceState(id?: string, objValues?: object): DeviceState; + Endpoint(id?: string, objValues?: object): Endpoint; + LiveRecording(id?: string, objValues?: object): LiveRecording; + Mailbox(id?: string, objValues?: object): Mailbox; + Playback(id?: string, objValues?: object): Playback; + Sound(id?: string, objValues?: object): Sound; + StoredRecording(id?: string, objValues?: object): StoredRecording; +} + +export interface Containers { + [key: string]: any; +} +/* Event Types */ +export type APILoadErrorEventType = 'APILoadError'; +export type EventsEventType = 'Events'; +export type MessageEventType = 'Message'; +export type MissingParamsEventType = 'MissingParams'; +export type EventEventType = 'Event'; +export type ContactInfoEventType = 'ContactInfo'; +export type PeerEventType = 'Peer'; +export type DeviceStateChangedEventType = 'DeviceStateChanged'; +export type PlaybackStartedEventType = 'PlaybackStarted'; +export type PlaybackContinuingEventType = 'PlaybackContinuing'; +export type PlaybackFinishedEventType = 'PlaybackFinished'; +export type RecordingStartedEventType = 'RecordingStarted'; +export type RecordingFinishedEventType = 'RecordingFinished'; +export type RecordingFailedEventType = 'RecordingFailed'; +export type ApplicationMoveFailedEventType = 'ApplicationMoveFailed'; +export type ApplicationReplacedEventType = 'ApplicationReplaced'; +export type BridgeCreatedEventType = 'BridgeCreated'; +export type BridgeDestroyedEventType = 'BridgeDestroyed'; +export type BridgeMergedEventType = 'BridgeMerged'; +export type BridgeVideoSourceChangedEventType = 'BridgeVideoSourceChanged'; +export type BridgeBlindTransferEventType = 'BridgeBlindTransfer'; +export type BridgeAttendedTransferEventType = 'BridgeAttendedTransfer'; +export type ChannelCreatedEventType = 'ChannelCreated'; +export type ChannelDestroyedEventType = 'ChannelDestroyed'; +export type ChannelEnteredBridgeEventType = 'ChannelEnteredBridge'; +export type ChannelLeftBridgeEventType = 'ChannelLeftBridge'; +export type ChannelStateChangeEventType = 'ChannelStateChange'; +export type ChannelDtmfReceivedEventType = 'ChannelDtmfReceived'; +export type ChannelDialplanEventType = 'ChannelDialplan'; +export type ChannelCallerIdEventType = 'ChannelCallerId'; +export type ChannelUsereventEventType = 'ChannelUserevent'; +export type ChannelHangupRequestEventType = 'ChannelHangupRequest'; +export type ChannelVarsetEventType = 'ChannelVarset'; +export type ChannelHoldEventType = 'ChannelHold'; +export type ChannelUnholdEventType = 'ChannelUnhold'; +export type ChannelTalkingStartedEventType = 'ChannelTalkingStarted'; +export type ChannelTalkingFinishedEventType = 'ChannelTalkingFinished'; +export type ContactStatusChangeEventType = 'ContactStatusChange'; +export type PeerStatusChangeEventType = 'PeerStatusChange'; +export type EndpointStateChangeEventType = 'EndpointStateChange'; +export type DialEventType = 'Dial'; +export type StasisEndEventType = 'StasisEnd'; +export type StasisStartEventType = 'StasisStart'; +export type TextMessageReceivedEventType = 'TextMessageReceived'; +export type ChannelConnectedLineEventType = 'ChannelConnectedLine'; +export type AnyEventType = + | EventsEventType + | MessageEventType + | MissingParamsEventType + | EventEventType + | ContactInfoEventType + | PeerEventType + | DeviceStateChangedEventType + | PlaybackStartedEventType + | PlaybackContinuingEventType + | PlaybackFinishedEventType + | RecordingStartedEventType + | RecordingFinishedEventType + | RecordingFailedEventType + | ApplicationMoveFailedEventType + | ApplicationReplacedEventType + | BridgeCreatedEventType + | BridgeDestroyedEventType + | BridgeMergedEventType + | BridgeVideoSourceChangedEventType + | BridgeBlindTransferEventType + | BridgeAttendedTransferEventType + | ChannelCreatedEventType + | ChannelDestroyedEventType + | ChannelEnteredBridgeEventType + | ChannelLeftBridgeEventType + | ChannelStateChangeEventType + | ChannelDtmfReceivedEventType + | ChannelDialplanEventType + | ChannelCallerIdEventType + | ChannelUsereventEventType + | ChannelHangupRequestEventType + | ChannelVarsetEventType + | ChannelHoldEventType + | ChannelUnholdEventType + | ChannelTalkingStartedEventType + | ChannelTalkingFinishedEventType + | ContactStatusChangeEventType + | PeerStatusChangeEventType + | EndpointStateChangeEventType + | DialEventType + | StasisEndEventType + | StasisStartEventType + | TextMessageReceivedEventType + | ChannelConnectedLineEventType; +/* Event Classes */ +export interface Events { + /* Methods */ + eventWebsocket( + params: { app: string | string[]; subscribeAll?: boolean }, + callback: (err: Error, message: Message) => void, + ): void; + eventWebsocket(params: { app: string | string[]; subscribeAll?: boolean }): Promise; + userEvent( + params: { eventName: string; application: string; source?: string | string[]; variables?: Containers }, + callback: (err: Error) => void, + ): void; + userEvent(params: { + eventName: string; + application: string; + source?: string | string[]; + variables?: Containers; + }): Promise; +} +export interface Message { + /* Properties */ + type: string; + asterisk_id?: string; +} +export interface MissingParams extends Message { + /* Properties */ + params: string | string[]; +} +export interface Event extends Message { + /* Properties */ + application: string; + timestamp: Date; +} +export interface ContactInfo { + /* Properties */ + uri: string; + contact_status: string; + aor: string; + roundtrip_usec?: string; +} +export interface Peer { + /* Properties */ + peer_status: string; + cause?: string; + address?: string; + port?: string; + time?: string; +} +export interface DeviceStateChanged extends Event { + /* Properties */ + device_state: DeviceState; +} +export interface PlaybackStarted extends Event { + /* Properties */ + playback: Playback; +} +export interface PlaybackContinuing extends Event { + /* Properties */ + playback: Playback; +} +export interface PlaybackFinished extends Event { + /* Properties */ + playback: Playback; +} +export interface RecordingStarted extends Event { + /* Properties */ + recording: LiveRecording; +} +export interface RecordingFinished extends Event { + /* Properties */ + recording: LiveRecording; +} +export interface RecordingFailed extends Event { + /* Properties */ + recording: LiveRecording; +} +export interface ApplicationMoveFailed extends Event { + /* Properties */ + channel: Channel; + destination: string; + args: string | string[]; +} +export interface BridgeCreated extends Event { + /* Properties */ + bridge: Bridge; +} +export interface BridgeDestroyed extends Event { + /* Properties */ + bridge: Bridge; +} +export interface BridgeMerged extends Event { + /* Properties */ + bridge: Bridge; + bridge_from: Bridge; +} +export interface BridgeVideoSourceChanged extends Event { + /* Properties */ + bridge: Bridge; + old_video_source_id?: string; +} +export interface BridgeBlindTransfer extends Event { + /* Properties */ + channel: Channel; + replace_channel?: Channel; + transferee?: Channel; + exten: string; + context: string; + result: string; + is_external: boolean; + bridge: Bridge; +} +export interface BridgeAttendedTransfer extends Event { + /* Properties */ + transferer_first_leg: Channel; + transferer_second_leg: Channel; + replace_channel?: Channel; + transferee?: Channel; + transfer_target?: Channel; + result: string; + is_external: boolean; + transferer_first_leg_bridge: Bridge; + transferer_second_leg_bridge: Bridge; + destination_type: string; + destination_bridge: string; + destination_application: string; + destination_link_first_leg: Channel; + destination_link_second_leg: Channel; + destination_threeway_channel: Channel; + destination_threeway_bridge: Bridge; +} +export interface ChannelCreated extends Event { + /* Properties */ + channel: Channel; +} +export interface ChannelDestroyed extends Event { + /* Properties */ + cause: number; + cause_txt: string; + channel: Channel; +} +export interface ChannelEnteredBridge extends Event { + /* Properties */ + bridge: Bridge; + channel: Channel; +} +export interface ChannelLeftBridge extends Event { + /* Properties */ + bridge: Bridge; + channel: Channel; +} +export interface ChannelStateChange extends Event { + /* Properties */ + channel: Channel; +} +export interface ChannelDtmfReceived extends Event { + /* Properties */ + digit: string; + duration_ms: number; + channel: Channel; +} +export interface ChannelDialplan extends Event { + /* Properties */ + channel: Channel; + dialplan_app: string; + dialplan_app_data: string; +} +export interface ChannelCallerId extends Event { + /* Properties */ + caller_presentation: number; + caller_presentation_txt: string; + channel: Channel; +} +export interface ChannelUserevent extends Event { + /* Properties */ + eventname: string; + channel?: Channel; + bridge?: Bridge; + endpoint?: Endpoint; + userevent: object; +} +export interface ChannelHangupRequest extends Event { + /* Properties */ + cause: number; + soft: boolean; + channel: Channel; +} +export interface ChannelVarset extends Event { + /* Properties */ + variable: string; + value: string; + channel?: Channel; +} +export interface ChannelHold extends Event { + /* Properties */ + channel: Channel; + musicclass?: string; +} +export interface ChannelUnhold extends Event { + /* Properties */ + channel: Channel; +} +export interface ChannelTalkingStarted extends Event { + /* Properties */ + channel: Channel; +} +export interface ChannelTalkingFinished extends Event { + /* Properties */ + channel: Channel; + duration: number; +} +export interface ContactStatusChange extends Event { + /* Properties */ + endpoint: Endpoint; + contact_info: ContactInfo; +} +export interface PeerStatusChange extends Event { + /* Properties */ + endpoint: Endpoint; + peer: Peer; +} +export interface EndpointStateChange extends Event { + /* Properties */ + endpoint: Endpoint; +} +export interface Dial extends Event { + /* Properties */ + caller?: Channel; + peer: Channel; + forward?: string; + forwarded?: Channel; + dialstring?: string; + dialstatus: string; +} +export interface StasisEnd extends Event { + /* Properties */ + channel: Channel; +} +export interface StasisStart extends Event { + /* Properties */ + args: string | string[]; + channel: Channel; + replace_channel?: Channel; +} +export interface TextMessageReceived extends Event { + /* Properties */ + message: TextMessage; + endpoint?: Endpoint; +} +export interface ChannelConnectedLine extends Event { + /* Properties */ + channel: Channel; +} +export interface Resource { + on(event: MessageEventType, callback: (event: Message, instances: Message) => void): void; + on(event: MissingParamsEventType, callback: (event: MissingParams, instances: MissingParams) => void): void; + on(event: EventEventType, callback: (event: Event, instances: Event) => void): void; + on(event: ContactInfoEventType, callback: (event: ContactInfo, instances: ContactInfo) => void): void; + on(event: PeerEventType, callback: (event: Peer, instances: Peer) => void): void; + on( + event: DeviceStateChangedEventType, + callback: (event: DeviceStateChanged, devicestate: DeviceState) => void, + ): void; + on(event: PlaybackStartedEventType, callback: (event: PlaybackStarted, playback: Playback) => void): void; + on(event: PlaybackContinuingEventType, callback: (event: PlaybackContinuing, playback: Playback) => void): void; + on(event: PlaybackFinishedEventType, callback: (event: PlaybackFinished, playback: Playback) => void): void; + on( + event: RecordingStartedEventType, + callback: (event: RecordingStarted, liverecording: LiveRecording) => void, + ): void; + on( + event: RecordingFinishedEventType, + callback: (event: RecordingFinished, liverecording: LiveRecording) => void, + ): void; + on(event: RecordingFailedEventType, callback: (event: RecordingFailed, liverecording: LiveRecording) => void): void; + on(event: ApplicationMoveFailedEventType, callback: (event: ApplicationMoveFailed, channel: Channel) => void): void; + on(event: ApplicationReplacedEventType, callback: (event: Event) => void): void; + on(event: BridgeCreatedEventType, callback: (event: BridgeCreated, bridge: Bridge) => void): void; + on(event: BridgeDestroyedEventType, callback: (event: BridgeDestroyed, bridge: Bridge) => void): void; + on(event: BridgeMergedEventType, callback: (event: BridgeMerged, bridge: Bridge) => void): void; + on( + event: BridgeVideoSourceChangedEventType, + callback: (event: BridgeVideoSourceChanged, bridge: Bridge) => void, + ): void; + on( + event: BridgeBlindTransferEventType, + callback: (event: BridgeBlindTransfer, instances: BridgeBlindTransfer) => void, + ): void; + on( + event: BridgeAttendedTransferEventType, + callback: (event: BridgeAttendedTransfer, instances: BridgeAttendedTransfer) => void, + ): void; + on(event: ChannelCreatedEventType, callback: (event: ChannelCreated, channel: Channel) => void): void; + on(event: ChannelDestroyedEventType, callback: (event: ChannelDestroyed, channel: Channel) => void): void; + on( + event: ChannelEnteredBridgeEventType, + callback: (event: ChannelEnteredBridge, instances: ChannelEnteredBridge) => void, + ): void; + on( + event: ChannelLeftBridgeEventType, + callback: (event: ChannelLeftBridge, instances: ChannelLeftBridge) => void, + ): void; + on(event: ChannelStateChangeEventType, callback: (event: ChannelStateChange, channel: Channel) => void): void; + on(event: ChannelDtmfReceivedEventType, callback: (event: ChannelDtmfReceived, channel: Channel) => void): void; + on(event: ChannelDialplanEventType, callback: (event: ChannelDialplan, channel: Channel) => void): void; + on(event: ChannelCallerIdEventType, callback: (event: ChannelCallerId, channel: Channel) => void): void; + on( + event: ChannelUsereventEventType, + callback: (event: ChannelUserevent, instances: ChannelUserevent) => void, + ): void; + on(event: ChannelHangupRequestEventType, callback: (event: ChannelHangupRequest, channel: Channel) => void): void; + on(event: ChannelVarsetEventType, callback: (event: ChannelVarset, channel: Channel) => void): void; + on(event: ChannelHoldEventType, callback: (event: ChannelHold, channel: Channel) => void): void; + on(event: ChannelUnholdEventType, callback: (event: ChannelUnhold, channel: Channel) => void): void; + on(event: ChannelTalkingStartedEventType, callback: (event: ChannelTalkingStarted, channel: Channel) => void): void; + on( + event: ChannelTalkingFinishedEventType, + callback: (event: ChannelTalkingFinished, channel: Channel) => void, + ): void; + on(event: ContactStatusChangeEventType, callback: (event: ContactStatusChange, endpoint: Endpoint) => void): void; + on(event: PeerStatusChangeEventType, callback: (event: PeerStatusChange, endpoint: Endpoint) => void): void; + on(event: EndpointStateChangeEventType, callback: (event: EndpointStateChange, endpoint: Endpoint) => void): void; + on(event: DialEventType, callback: (event: Dial, channel: Channel) => void): void; + on(event: StasisEndEventType, callback: (event: StasisEnd, channel: Channel) => void): void; + on(event: StasisStartEventType, callback: (event: StasisStart, channel: Channel) => void): void; + on(event: TextMessageReceivedEventType, callback: (event: TextMessageReceived, endpoint: Endpoint) => void): void; + on(event: ChannelConnectedLineEventType, callback: (event: ChannelConnectedLine, channel: Channel) => void): void; + once(event: MessageEventType, callback: (event: Message, instances: Message) => void): void; + once(event: MissingParamsEventType, callback: (event: MissingParams, instances: MissingParams) => void): void; + once(event: EventEventType, callback: (event: Event, instances: Event) => void): void; + once(event: ContactInfoEventType, callback: (event: ContactInfo, instances: ContactInfo) => void): void; + once(event: PeerEventType, callback: (event: Peer, instances: Peer) => void): void; + once( + event: DeviceStateChangedEventType, + callback: (event: DeviceStateChanged, devicestate: DeviceState) => void, + ): void; + once(event: PlaybackStartedEventType, callback: (event: PlaybackStarted, playback: Playback) => void): void; + once(event: PlaybackContinuingEventType, callback: (event: PlaybackContinuing, playback: Playback) => void): void; + once(event: PlaybackFinishedEventType, callback: (event: PlaybackFinished, playback: Playback) => void): void; + once( + event: RecordingStartedEventType, + callback: (event: RecordingStarted, liverecording: LiveRecording) => void, + ): void; + once( + event: RecordingFinishedEventType, + callback: (event: RecordingFinished, liverecording: LiveRecording) => void, + ): void; + once( + event: RecordingFailedEventType, + callback: (event: RecordingFailed, liverecording: LiveRecording) => void, + ): void; + once( + event: ApplicationMoveFailedEventType, + callback: (event: ApplicationMoveFailed, channel: Channel) => void, + ): void; + once(event: ApplicationReplacedEventType, callback: (event: Event) => void): void; + once(event: BridgeCreatedEventType, callback: (event: BridgeCreated, bridge: Bridge) => void): void; + once(event: BridgeDestroyedEventType, callback: (event: BridgeDestroyed, bridge: Bridge) => void): void; + once(event: BridgeMergedEventType, callback: (event: BridgeMerged, bridge: Bridge) => void): void; + once( + event: BridgeVideoSourceChangedEventType, + callback: (event: BridgeVideoSourceChanged, bridge: Bridge) => void, + ): void; + once( + event: BridgeBlindTransferEventType, + callback: (event: BridgeBlindTransfer, instances: BridgeBlindTransfer) => void, + ): void; + once( + event: BridgeAttendedTransferEventType, + callback: (event: BridgeAttendedTransfer, instances: BridgeAttendedTransfer) => void, + ): void; + once(event: ChannelCreatedEventType, callback: (event: ChannelCreated, channel: Channel) => void): void; + once(event: ChannelDestroyedEventType, callback: (event: ChannelDestroyed, channel: Channel) => void): void; + once( + event: ChannelEnteredBridgeEventType, + callback: (event: ChannelEnteredBridge, instances: ChannelEnteredBridge) => void, + ): void; + once( + event: ChannelLeftBridgeEventType, + callback: (event: ChannelLeftBridge, instances: ChannelLeftBridge) => void, + ): void; + once(event: ChannelStateChangeEventType, callback: (event: ChannelStateChange, channel: Channel) => void): void; + once(event: ChannelDtmfReceivedEventType, callback: (event: ChannelDtmfReceived, channel: Channel) => void): void; + once(event: ChannelDialplanEventType, callback: (event: ChannelDialplan, channel: Channel) => void): void; + once(event: ChannelCallerIdEventType, callback: (event: ChannelCallerId, channel: Channel) => void): void; + once( + event: ChannelUsereventEventType, + callback: (event: ChannelUserevent, instances: ChannelUserevent) => void, + ): void; + once(event: ChannelHangupRequestEventType, callback: (event: ChannelHangupRequest, channel: Channel) => void): void; + once(event: ChannelVarsetEventType, callback: (event: ChannelVarset, channel: Channel) => void): void; + once(event: ChannelHoldEventType, callback: (event: ChannelHold, channel: Channel) => void): void; + once(event: ChannelUnholdEventType, callback: (event: ChannelUnhold, channel: Channel) => void): void; + once( + event: ChannelTalkingStartedEventType, + callback: (event: ChannelTalkingStarted, channel: Channel) => void, + ): void; + once( + event: ChannelTalkingFinishedEventType, + callback: (event: ChannelTalkingFinished, channel: Channel) => void, + ): void; + once(event: ContactStatusChangeEventType, callback: (event: ContactStatusChange, endpoint: Endpoint) => void): void; + once(event: PeerStatusChangeEventType, callback: (event: PeerStatusChange, endpoint: Endpoint) => void): void; + once(event: EndpointStateChangeEventType, callback: (event: EndpointStateChange, endpoint: Endpoint) => void): void; + once(event: DialEventType, callback: (event: Dial, channel: Channel) => void): void; + once(event: StasisEndEventType, callback: (event: StasisEnd, channel: Channel) => void): void; + once(event: StasisStartEventType, callback: (event: StasisStart, channel: Channel) => void): void; + once(event: TextMessageReceivedEventType, callback: (event: TextMessageReceived, endpoint: Endpoint) => void): void; + once(event: ChannelConnectedLineEventType, callback: (event: ChannelConnectedLine, channel: Channel) => void): void; + addListener(event: MessageEventType, callback: (event: Message, instances: Message) => void): void; + addListener( + event: MissingParamsEventType, + callback: (event: MissingParams, instances: MissingParams) => void, + ): void; + addListener(event: EventEventType, callback: (event: Event, instances: Event) => void): void; + addListener(event: ContactInfoEventType, callback: (event: ContactInfo, instances: ContactInfo) => void): void; + addListener(event: PeerEventType, callback: (event: Peer, instances: Peer) => void): void; + addListener( + event: DeviceStateChangedEventType, + callback: (event: DeviceStateChanged, devicestate: DeviceState) => void, + ): void; + addListener(event: PlaybackStartedEventType, callback: (event: PlaybackStarted, playback: Playback) => void): void; + addListener( + event: PlaybackContinuingEventType, + callback: (event: PlaybackContinuing, playback: Playback) => void, + ): void; + addListener( + event: PlaybackFinishedEventType, + callback: (event: PlaybackFinished, playback: Playback) => void, + ): void; + addListener( + event: RecordingStartedEventType, + callback: (event: RecordingStarted, liverecording: LiveRecording) => void, + ): void; + addListener( + event: RecordingFinishedEventType, + callback: (event: RecordingFinished, liverecording: LiveRecording) => void, + ): void; + addListener( + event: RecordingFailedEventType, + callback: (event: RecordingFailed, liverecording: LiveRecording) => void, + ): void; + addListener( + event: ApplicationMoveFailedEventType, + callback: (event: ApplicationMoveFailed, channel: Channel) => void, + ): void; + addListener(event: ApplicationReplacedEventType, callback: (event: Event) => void): void; + addListener(event: BridgeCreatedEventType, callback: (event: BridgeCreated, bridge: Bridge) => void): void; + addListener(event: BridgeDestroyedEventType, callback: (event: BridgeDestroyed, bridge: Bridge) => void): void; + addListener(event: BridgeMergedEventType, callback: (event: BridgeMerged, bridge: Bridge) => void): void; + addListener( + event: BridgeVideoSourceChangedEventType, + callback: (event: BridgeVideoSourceChanged, bridge: Bridge) => void, + ): void; + addListener( + event: BridgeBlindTransferEventType, + callback: (event: BridgeBlindTransfer, instances: BridgeBlindTransfer) => void, + ): void; + addListener( + event: BridgeAttendedTransferEventType, + callback: (event: BridgeAttendedTransfer, instances: BridgeAttendedTransfer) => void, + ): void; + addListener(event: ChannelCreatedEventType, callback: (event: ChannelCreated, channel: Channel) => void): void; + addListener(event: ChannelDestroyedEventType, callback: (event: ChannelDestroyed, channel: Channel) => void): void; + addListener( + event: ChannelEnteredBridgeEventType, + callback: (event: ChannelEnteredBridge, instances: ChannelEnteredBridge) => void, + ): void; + addListener( + event: ChannelLeftBridgeEventType, + callback: (event: ChannelLeftBridge, instances: ChannelLeftBridge) => void, + ): void; + addListener( + event: ChannelStateChangeEventType, + callback: (event: ChannelStateChange, channel: Channel) => void, + ): void; + addListener( + event: ChannelDtmfReceivedEventType, + callback: (event: ChannelDtmfReceived, channel: Channel) => void, + ): void; + addListener(event: ChannelDialplanEventType, callback: (event: ChannelDialplan, channel: Channel) => void): void; + addListener(event: ChannelCallerIdEventType, callback: (event: ChannelCallerId, channel: Channel) => void): void; + addListener( + event: ChannelUsereventEventType, + callback: (event: ChannelUserevent, instances: ChannelUserevent) => void, + ): void; + addListener( + event: ChannelHangupRequestEventType, + callback: (event: ChannelHangupRequest, channel: Channel) => void, + ): void; + addListener(event: ChannelVarsetEventType, callback: (event: ChannelVarset, channel: Channel) => void): void; + addListener(event: ChannelHoldEventType, callback: (event: ChannelHold, channel: Channel) => void): void; + addListener(event: ChannelUnholdEventType, callback: (event: ChannelUnhold, channel: Channel) => void): void; + addListener( + event: ChannelTalkingStartedEventType, + callback: (event: ChannelTalkingStarted, channel: Channel) => void, + ): void; + addListener( + event: ChannelTalkingFinishedEventType, + callback: (event: ChannelTalkingFinished, channel: Channel) => void, + ): void; + addListener( + event: ContactStatusChangeEventType, + callback: (event: ContactStatusChange, endpoint: Endpoint) => void, + ): void; + addListener( + event: PeerStatusChangeEventType, + callback: (event: PeerStatusChange, endpoint: Endpoint) => void, + ): void; + addListener( + event: EndpointStateChangeEventType, + callback: (event: EndpointStateChange, endpoint: Endpoint) => void, + ): void; + addListener(event: DialEventType, callback: (event: Dial, channel: Channel) => void): void; + addListener(event: StasisEndEventType, callback: (event: StasisEnd, channel: Channel) => void): void; + addListener(event: StasisStartEventType, callback: (event: StasisStart, channel: Channel) => void): void; + addListener( + event: TextMessageReceivedEventType, + callback: (event: TextMessageReceived, endpoint: Endpoint) => void, + ): void; + addListener( + event: ChannelConnectedLineEventType, + callback: (event: ChannelConnectedLine, channel: Channel) => void, + ): void; + removeListener(event: AnyEventType, handler: (...args: any[]) => void): void; + removeAllListeners(event?: AnyEventType): void; +} +export interface Applications { + /* Methods */ + list(callback: (err: Error, applications: Application[]) => void): void; + list(): Promise; + get(params: { applicationName: string }, callback: (err: Error, application: Application) => void): void; + get(params: { applicationName: string }): Promise; + subscribe( + params: { applicationName: string; eventSource: string | string[] }, + callback: (err: Error, application: Application) => void, + ): void; + subscribe(params: { applicationName: string; eventSource: string | string[] }): Promise; + unsubscribe( + params: { applicationName: string; eventSource: string | string[] }, + callback: (err: Error, application: Application) => void, + ): void; + unsubscribe(params: { applicationName: string; eventSource: string | string[] }): Promise; + filter( + params: { applicationName: string; filter?: object }, + callback: (err: Error, application: Application) => void, + ): void; + filter(params: { applicationName: string; filter?: object }): Promise; +} +export interface Application extends Resource { + /* Properties */ + name: string; + channel_ids: string | string[]; + bridge_ids: string | string[]; + endpoint_ids: string | string[]; + device_names: string | string[]; + events_allowed: object | object[]; + events_disallowed: object | object[]; + /* Methods */ + list(callback: (err: Error, applications: Application[]) => void): void; + list(): Promise; + get(callback: (err: Error, application: Application) => void): void; + get(): Promise; + subscribe( + params: { eventSource: string | string[] }, + callback: (err: Error, application: Application) => void, + ): void; + subscribe(params: { eventSource: string | string[] }): Promise; + unsubscribe( + params: { eventSource: string | string[] }, + callback: (err: Error, application: Application) => void, + ): void; + unsubscribe(params: { eventSource: string | string[] }): Promise; + filter(params: { filter?: object }, callback: (err: Error, application: Application) => void): void; + filter(callback: (err: Error, application: Application) => void): void; + filter(params?: { filter?: object }): Promise; +} +export interface Asterisk { + /* Methods */ + getObject( + params: { configClass: string; objectType: string; id: string }, + callback: (err: Error, configtuples: ConfigTuple[]) => void, + ): void; + getObject(params: { configClass: string; objectType: string; id: string }): Promise; + updateObject( + params: { configClass: string; objectType: string; id: string; fields?: Containers }, + callback: (err: Error, configtuples: ConfigTuple[]) => void, + ): void; + updateObject(params: { + configClass: string; + objectType: string; + id: string; + fields?: Containers; + }): Promise; + deleteObject(params: { configClass: string; objectType: string; id: string }, callback: (err: Error) => void): void; + deleteObject(params: { configClass: string; objectType: string; id: string }): Promise; + getInfo(params: { only?: string | string[] }, callback: (err: Error, asteriskinfo: AsteriskInfo) => void): void; + getInfo(callback: (err: Error, asteriskinfo: AsteriskInfo) => void): void; + getInfo(params?: { only?: string | string[] }): Promise; + ping(callback: (err: Error, asteriskping: AsteriskPing) => void): void; + ping(): Promise; + listModules(callback: (err: Error, modules: Module[]) => void): void; + listModules(): Promise; + getModule(params: { moduleName: string }, callback: (err: Error, module: Module) => void): void; + getModule(params: { moduleName: string }): Promise; + loadModule(params: { moduleName: string }, callback: (err: Error) => void): void; + loadModule(params: { moduleName: string }): Promise; + unloadModule(params: { moduleName: string }, callback: (err: Error) => void): void; + unloadModule(params: { moduleName: string }): Promise; + reloadModule(params: { moduleName: string }, callback: (err: Error) => void): void; + reloadModule(params: { moduleName: string }): Promise; + listLogChannels(callback: (err: Error, logchannels: LogChannel[]) => void): void; + listLogChannels(): Promise; + addLog(params: { logChannelName: string; configuration: string }, callback: (err: Error) => void): void; + addLog(params: { logChannelName: string; configuration: string }): Promise; + deleteLog(params: { logChannelName: string }, callback: (err: Error) => void): void; + deleteLog(params: { logChannelName: string }): Promise; + rotateLog(params: { logChannelName: string }, callback: (err: Error) => void): void; + rotateLog(params: { logChannelName: string }): Promise; + getGlobalVar(params: { variable: string }, callback: (err: Error, variable: Variable) => void): void; + getGlobalVar(params: { variable: string }): Promise; + setGlobalVar(params: { variable: string; value?: string }, callback: (err: Error) => void): void; + setGlobalVar(params: { variable: string; value?: string }): Promise; +} +export interface BuildInfo { + /* Properties */ + os: string; + kernel: string; + options: string; + machine: string; + date: string; + user: string; +} +export interface SystemInfo { + /* Properties */ + version: string; + entity_id: string; +} +export interface SetId { + /* Properties */ + user: string; + group: string; +} +export interface ConfigInfo { + /* Properties */ + name: string; + default_language: string; + max_channels?: number; + max_open_files?: number; + max_load?: number; + setid: SetId; +} +export interface StatusInfo { + /* Properties */ + startup_time: Date; + last_reload_time: Date; +} +export interface AsteriskInfo { + /* Properties */ + build?: BuildInfo; + system?: SystemInfo; + config?: ConfigInfo; + status?: StatusInfo; +} +export interface AsteriskPing { + /* Properties */ + asterisk_id: string; + ping: string; + timestamp: string; +} +export interface Module { + /* Properties */ + name: string; + description: string; + use_count: number; + status: string; + support_level: string; +} +export interface LogChannel { + /* Properties */ + channel: string; + type: string; + status: string; + configuration: string; +} +export interface Variable { + /* Properties */ + value: string; +} +export interface ConfigTuple { + /* Properties */ + attribute: string; + value: string; +} +export interface Bridges { + /* Methods */ + list(callback: (err: Error, bridges: Bridge[]) => void): void; + list(): Promise; + create( + params: { type?: string; bridgeId?: string; name?: string }, + callback: (err: Error, bridge: Bridge) => void, + ): void; + create(callback: (err: Error, bridge: Bridge) => void): void; + create(params?: { type?: string; bridgeId?: string; name?: string }): Promise; + createWithId( + params: { type?: string; bridgeId: string; name?: string }, + callback: (err: Error, bridge: Bridge) => void, + ): void; + createWithId(params: { type?: string; bridgeId: string; name?: string }): Promise; + get(params: { bridgeId: string }, callback: (err: Error, bridge: Bridge) => void): void; + get(params: { bridgeId: string }): Promise; + destroy(params: { bridgeId: string }, callback: (err: Error) => void): void; + destroy(params: { bridgeId: string }): Promise; + addChannel( + params: { bridgeId: string; channel: string | string[]; role?: string; absorbDTMF?: boolean; mute?: boolean }, + callback: (err: Error) => void, + ): void; + addChannel(params: { + bridgeId: string; + channel: string | string[]; + role?: string; + absorbDTMF?: boolean; + mute?: boolean; + }): Promise; + removeChannel(params: { bridgeId: string; channel: string | string[] }, callback: (err: Error) => void): void; + removeChannel(params: { bridgeId: string; channel: string | string[] }): Promise; + setVideoSource(params: { bridgeId: string; channelId: string }, callback: (err: Error) => void): void; + setVideoSource(params: { bridgeId: string; channelId: string }): Promise; + clearVideoSource(params: { bridgeId: string }, callback: (err: Error) => void): void; + clearVideoSource(params: { bridgeId: string }): Promise; + startMoh(params: { bridgeId: string; mohClass?: string }, callback: (err: Error) => void): void; + startMoh(params: { bridgeId: string; mohClass?: string }): Promise; + stopMoh(params: { bridgeId: string }, callback: (err: Error) => void): void; + stopMoh(params: { bridgeId: string }): Promise; + play( + params: { + bridgeId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + playbackId?: string; + }, + callback: (err: Error, playback: Playback) => void, + ): void; + play(params: { + bridgeId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + playbackId?: string; + }): Promise; + playWithId( + params: { + bridgeId: string; + playbackId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + }, + callback: (err: Error, playback: Playback) => void, + ): void; + playWithId(params: { + bridgeId: string; + playbackId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + }): Promise; + record( + params: { + bridgeId: string; + name: string; + format: string; + maxDurationSeconds?: number; + maxSilenceSeconds?: number; + ifExists?: string; + beep?: boolean; + terminateOn?: string; + }, + callback: (err: Error, liverecording: LiveRecording) => void, + ): void; + record(params: { + bridgeId: string; + name: string; + format: string; + maxDurationSeconds?: number; + maxSilenceSeconds?: number; + ifExists?: string; + beep?: boolean; + terminateOn?: string; + }): Promise; +} +export interface Bridge extends Resource { + /* Properties */ + id: string; + technology: string; + bridge_type: string; + bridge_class: string; + creator: string; + name: string; + channels: string | string[]; + video_mode?: string; + video_source_id?: string; + creationtime: Date; + /* Methods */ + list(callback: (err: Error, bridges: Bridge[]) => void): void; + list(): Promise; + create(params: { type?: string; name?: string }, callback: (err: Error, bridge: Bridge) => void): void; + create(callback: (err: Error, bridge: Bridge) => void): void; + create(params?: { type?: string; name?: string }): Promise; + createWithId(params: { type?: string; name?: string }, callback: (err: Error, bridge: Bridge) => void): void; + createWithId(callback: (err: Error, bridge: Bridge) => void): void; + createWithId(params?: { type?: string; name?: string }): Promise; + get(callback: (err: Error, bridge: Bridge) => void): void; + get(): Promise; + destroy(callback: (err: Error) => void): void; + destroy(): Promise; + addChannel( + params: { channel: string | string[]; role?: string; absorbDTMF?: boolean; mute?: boolean }, + callback: (err: Error) => void, + ): void; + addChannel(params: { + channel: string | string[]; + role?: string; + absorbDTMF?: boolean; + mute?: boolean; + }): Promise; + removeChannel(params: { channel: string | string[] }, callback: (err: Error) => void): void; + removeChannel(params: { channel: string | string[] }): Promise; + setVideoSource(params: { channelId: string }, callback: (err: Error) => void): void; + setVideoSource(params: { channelId: string }): Promise; + clearVideoSource(callback: (err: Error) => void): void; + clearVideoSource(): Promise; + startMoh(params: { mohClass?: string }, callback: (err: Error) => void): void; + startMoh(callback: (err: Error) => void): void; + startMoh(params?: { mohClass?: string }): Promise; + stopMoh(callback: (err: Error) => void): void; + stopMoh(): Promise; + play( + params: { media: string | string[]; lang?: string; offsetms?: number; skipms?: number; playbackId?: string }, + callback: (err: Error, playback: Playback) => void, + ): void; + play(params: { + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + playbackId?: string; + }): Promise; + playWithId( + params: { playbackId: string; media: string | string[]; lang?: string; offsetms?: number; skipms?: number }, + callback: (err: Error, playback: Playback) => void, + ): void; + playWithId(params: { + playbackId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + }): Promise; + record( + params: { + name: string; + format: string; + maxDurationSeconds?: number; + maxSilenceSeconds?: number; + ifExists?: string; + beep?: boolean; + terminateOn?: string; + }, + recording: LiveRecording, + callback: (err: Error, liverecording: LiveRecording) => void, + ): void; + record( + params: { + name: string; + format: string; + maxDurationSeconds?: number; + maxSilenceSeconds?: number; + ifExists?: string; + beep?: boolean; + terminateOn?: string; + }, + recording: LiveRecording, + ): Promise; +} +export interface Channels { + /* Methods */ + list(callback: (err: Error, channels: Channel[]) => void): void; + list(): Promise; + originate( + params: { + endpoint: string; + extension?: string; + context?: string; + priority?: number; + label?: string; + app?: string; + appArgs?: string; + callerId?: string; + timeout?: number; + variables?: Containers; + channelId?: string; + otherChannelId?: string; + originator?: string; + formats?: string; + }, + callback: (err: Error, channel: Channel) => void, + ): void; + originate(params: { + endpoint: string; + extension?: string; + context?: string; + priority?: number; + label?: string; + app?: string; + appArgs?: string; + callerId?: string; + timeout?: number; + variables?: Containers; + channelId?: string; + otherChannelId?: string; + originator?: string; + formats?: string; + }): Promise; + create( + params: { + endpoint: string; + app: string; + appArgs?: string; + channelId?: string; + otherChannelId?: string; + originator?: string; + formats?: string; + }, + callback: (err: Error, channel: Channel) => void, + ): void; + create(params: { + endpoint: string; + app: string; + appArgs?: string; + channelId?: string; + otherChannelId?: string; + originator?: string; + formats?: string; + }): Promise; + get(params: { channelId: string }, callback: (err: Error, channel: Channel) => void): void; + get(params: { channelId: string }): Promise; + originateWithId( + params: { + channelId: string; + endpoint: string; + extension?: string; + context?: string; + priority?: number; + label?: string; + app?: string; + appArgs?: string; + callerId?: string; + timeout?: number; + variables?: Containers; + otherChannelId?: string; + originator?: string; + formats?: string; + }, + callback: (err: Error, channel: Channel) => void, + ): void; + originateWithId(params: { + channelId: string; + endpoint: string; + extension?: string; + context?: string; + priority?: number; + label?: string; + app?: string; + appArgs?: string; + callerId?: string; + timeout?: number; + variables?: Containers; + otherChannelId?: string; + originator?: string; + formats?: string; + }): Promise; + hangup(params: { channelId: string; reason?: string }, callback: (err: Error) => void): void; + hangup(params: { channelId: string; reason?: string }): Promise; + continueInDialplan( + params: { channelId: string; context?: string; extension?: string; priority?: number; label?: string }, + callback: (err: Error) => void, + ): void; + continueInDialplan(params: { + channelId: string; + context?: string; + extension?: string; + priority?: number; + label?: string; + }): Promise; + move(params: { channelId: string; app: string; appArgs?: string }, callback: (err: Error) => void): void; + move(params: { channelId: string; app: string; appArgs?: string }): Promise; + redirect(params: { channelId: string; endpoint: string }, callback: (err: Error) => void): void; + redirect(params: { channelId: string; endpoint: string }): Promise; + answer(params: { channelId: string }, callback: (err: Error) => void): void; + answer(params: { channelId: string }): Promise; + ring(params: { channelId: string }, callback: (err: Error) => void): void; + ring(params: { channelId: string }): Promise; + ringStop(params: { channelId: string }, callback: (err: Error) => void): void; + ringStop(params: { channelId: string }): Promise; + sendDTMF( + params: { + channelId: string; + dtmf?: string; + before?: number; + between?: number; + duration?: number; + after?: number; + }, + callback: (err: Error) => void, + ): void; + sendDTMF(params: { + channelId: string; + dtmf?: string; + before?: number; + between?: number; + duration?: number; + after?: number; + }): Promise; + mute(params: { channelId: string; direction?: string }, callback: (err: Error) => void): void; + mute(params: { channelId: string; direction?: string }): Promise; + unmute(params: { channelId: string; direction?: string }, callback: (err: Error) => void): void; + unmute(params: { channelId: string; direction?: string }): Promise; + hold(params: { channelId: string }, callback: (err: Error) => void): void; + hold(params: { channelId: string }): Promise; + unhold(params: { channelId: string }, callback: (err: Error) => void): void; + unhold(params: { channelId: string }): Promise; + startMoh(params: { channelId: string; mohClass?: string }, callback: (err: Error) => void): void; + startMoh(params: { channelId: string; mohClass?: string }): Promise; + stopMoh(params: { channelId: string }, callback: (err: Error) => void): void; + stopMoh(params: { channelId: string }): Promise; + startSilence(params: { channelId: string }, callback: (err: Error) => void): void; + startSilence(params: { channelId: string }): Promise; + stopSilence(params: { channelId: string }, callback: (err: Error) => void): void; + stopSilence(params: { channelId: string }): Promise; + play( + params: { + channelId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + playbackId?: string; + }, + callback: (err: Error, playback: Playback) => void, + ): void; + play(params: { + channelId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + playbackId?: string; + }): Promise; + playWithId( + params: { + channelId: string; + playbackId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + }, + callback: (err: Error, playback: Playback) => void, + ): void; + playWithId(params: { + channelId: string; + playbackId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + }): Promise; + record( + params: { + channelId: string; + name: string; + format: string; + maxDurationSeconds?: number; + maxSilenceSeconds?: number; + ifExists?: string; + beep?: boolean; + terminateOn?: string; + }, + callback: (err: Error, liverecording: LiveRecording) => void, + ): void; + record(params: { + channelId: string; + name: string; + format: string; + maxDurationSeconds?: number; + maxSilenceSeconds?: number; + ifExists?: string; + beep?: boolean; + terminateOn?: string; + }): Promise; + getChannelVar( + params: { channelId: string; variable: string }, + callback: (err: Error, variable: Variable) => void, + ): void; + getChannelVar(params: { channelId: string; variable: string }): Promise; + setChannelVar( + params: { channelId: string; variable: string; value?: string }, + callback: (err: Error) => void, + ): void; + setChannelVar(params: { channelId: string; variable: string; value?: string }): Promise; + snoopChannel( + params: { channelId: string; spy?: string; whisper?: string; app: string; appArgs?: string; snoopId?: string }, + callback: (err: Error, channel: Channel) => void, + ): void; + snoopChannel(params: { + channelId: string; + spy?: string; + whisper?: string; + app: string; + appArgs?: string; + snoopId?: string; + }): Promise; + snoopChannelWithId( + params: { channelId: string; snoopId: string; spy?: string; whisper?: string; app: string; appArgs?: string }, + callback: (err: Error, channel: Channel) => void, + ): void; + snoopChannelWithId(params: { + channelId: string; + snoopId: string; + spy?: string; + whisper?: string; + app: string; + appArgs?: string; + }): Promise; + dial(params: { channelId: string; caller?: string; timeout?: number }, callback: (err: Error) => void): void; + dial(params: { channelId: string; caller?: string; timeout?: number }): Promise; + rtpstatistics(params: { channelId: string }, callback: (err: Error, rtpstat: RTPstat) => void): void; + rtpstatistics(params: { channelId: string }): Promise; +} +export interface DialplanCEP { + /* Properties */ + context: string; + exten: string; + priority: number; + app_name: string; + app_data: string; +} +export interface CallerID { + /* Properties */ + name: string; + number: string; +} +export interface RTPstat { + /* Properties */ + txcount: number; + rxcount: number; + txjitter?: number; + rxjitter?: number; + remote_maxjitter?: number; + remote_minjitter?: number; + remote_normdevjitter?: number; + remote_stdevjitter?: number; + local_maxjitter?: number; + local_minjitter?: number; + local_normdevjitter?: number; + local_stdevjitter?: number; + txploss: number; + rxploss: number; + remote_maxrxploss?: number; + remote_minrxploss?: number; + remote_normdevrxploss?: number; + remote_stdevrxploss?: number; + local_maxrxploss?: number; + local_minrxploss?: number; + local_normdevrxploss?: number; + local_stdevrxploss?: number; + rtt?: number; + maxrtt?: number; + minrtt?: number; + normdevrtt?: number; + stdevrtt?: number; + local_ssrc: number; + remote_ssrc: number; + txoctetcount: number; + rxoctetcount: number; + channel_uniqueid: string; +} +export interface Channel extends Resource { + /* Properties */ + id: string; + name: string; + state: string; + caller: CallerID; + connected: CallerID; + accountcode: string; + dialplan: DialplanCEP; + creationtime: Date; + language: string; + channelvars?: object; + /* Methods */ + list(callback: (err: Error, channels: Channel[]) => void): void; + list(): Promise; + originate( + params: { + endpoint: string; + extension?: string; + context?: string; + priority?: number; + label?: string; + app?: string; + appArgs?: string; + callerId?: string; + timeout?: number; + variables?: Containers; + otherChannelId?: string; + originator?: string; + formats?: string; + }, + callback: (err: Error, channel: Channel) => void, + ): void; + originate(params: { + endpoint: string; + extension?: string; + context?: string; + priority?: number; + label?: string; + app?: string; + appArgs?: string; + callerId?: string; + timeout?: number; + variables?: Containers; + otherChannelId?: string; + originator?: string; + formats?: string; + }): Promise; + create( + params: { + endpoint: string; + app: string; + appArgs?: string; + otherChannelId?: string; + originator?: string; + formats?: string; + }, + callback: (err: Error, channel: Channel) => void, + ): void; + create(params: { + endpoint: string; + app: string; + appArgs?: string; + otherChannelId?: string; + originator?: string; + formats?: string; + }): Promise; + get(callback: (err: Error, channel: Channel) => void): void; + get(): Promise; + originateWithId( + params: { + endpoint: string; + extension?: string; + context?: string; + priority?: number; + label?: string; + app?: string; + appArgs?: string; + callerId?: string; + timeout?: number; + variables?: Containers; + otherChannelId?: string; + originator?: string; + formats?: string; + }, + callback: (err: Error, channel: Channel) => void, + ): void; + originateWithId(params: { + endpoint: string; + extension?: string; + context?: string; + priority?: number; + label?: string; + app?: string; + appArgs?: string; + callerId?: string; + timeout?: number; + variables?: Containers; + otherChannelId?: string; + originator?: string; + formats?: string; + }): Promise; + hangup(params: { reason?: string }, callback: (err: Error) => void): void; + hangup(callback: (err: Error) => void): void; + hangup(params?: { reason?: string }): Promise; + continueInDialplan( + params: { context?: string; extension?: string; priority?: number; label?: string }, + callback: (err: Error) => void, + ): void; + continueInDialplan(callback: (err: Error) => void): void; + continueInDialplan(params?: { + context?: string; + extension?: string; + priority?: number; + label?: string; + }): Promise; + move(params: { app: string; appArgs?: string }, callback: (err: Error) => void): void; + move(params: { app: string; appArgs?: string }): Promise; + redirect(params: { endpoint: string }, callback: (err: Error) => void): void; + redirect(params: { endpoint: string }): Promise; + answer(callback: (err: Error) => void): void; + answer(): Promise; + ring(callback: (err: Error) => void): void; + ring(): Promise; + ringStop(callback: (err: Error) => void): void; + ringStop(): Promise; + sendDTMF( + params: { dtmf?: string; before?: number; between?: number; duration?: number; after?: number }, + callback: (err: Error) => void, + ): void; + sendDTMF(callback: (err: Error) => void): void; + sendDTMF(params?: { + dtmf?: string; + before?: number; + between?: number; + duration?: number; + after?: number; + }): Promise; + mute(params: { direction?: string }, callback: (err: Error) => void): void; + mute(callback: (err: Error) => void): void; + mute(params?: { direction?: string }): Promise; + unmute(params: { direction?: string }, callback: (err: Error) => void): void; + unmute(callback: (err: Error) => void): void; + unmute(params?: { direction?: string }): Promise; + hold(callback: (err: Error) => void): void; + hold(): Promise; + unhold(callback: (err: Error) => void): void; + unhold(): Promise; + startMoh(params: { mohClass?: string }, callback: (err: Error) => void): void; + startMoh(callback: (err: Error) => void): void; + startMoh(params?: { mohClass?: string }): Promise; + stopMoh(callback: (err: Error) => void): void; + stopMoh(): Promise; + startSilence(callback: (err: Error) => void): void; + startSilence(): Promise; + stopSilence(callback: (err: Error) => void): void; + stopSilence(): Promise; + play( + params: { media: string | string[]; lang?: string; offsetms?: number; skipms?: number; playbackId?: string }, + playback: Playback, + callback: (err: Error, playback: Playback) => void, + ): void; + play( + params: { media: string | string[]; lang?: string; offsetms?: number; skipms?: number; playbackId?: string }, + playback: Playback, + ): Promise; + playWithId( + params: { playbackId: string; media: string | string[]; lang?: string; offsetms?: number; skipms?: number }, + callback: (err: Error, playback: Playback) => void, + ): void; + playWithId(params: { + playbackId: string; + media: string | string[]; + lang?: string; + offsetms?: number; + skipms?: number; + }): Promise; + record( + params: { + name: string; + format: string; + maxDurationSeconds?: number; + maxSilenceSeconds?: number; + ifExists?: string; + beep?: boolean; + terminateOn?: string; + }, + recording: LiveRecording, + callback: (err: Error, liverecording: LiveRecording) => void, + ): void; + record( + params: { + name: string; + format: string; + maxDurationSeconds?: number; + maxSilenceSeconds?: number; + ifExists?: string; + beep?: boolean; + terminateOn?: string; + }, + recording: LiveRecording, + ): Promise; + getChannelVar(params: { variable: string }, callback: (err: Error, variable: Variable) => void): void; + getChannelVar(params: { variable: string }): Promise; + setChannelVar(params: { variable: string; value?: string }, callback: (err: Error) => void): void; + setChannelVar(params: { variable: string; value?: string }): Promise; + snoopChannel( + params: { spy?: string; whisper?: string; app: string; appArgs?: string; snoopId?: string }, + snoopChannel: Channel, + callback: (err: Error, channel: Channel) => void, + ): void; + snoopChannel( + params: { spy?: string; whisper?: string; app: string; appArgs?: string; snoopId?: string }, + snoopChannel: Channel, + ): Promise; + snoopChannelWithId( + params: { snoopId: string; spy?: string; whisper?: string; app: string; appArgs?: string }, + callback: (err: Error, channel: Channel) => void, + ): void; + snoopChannelWithId(params: { + snoopId: string; + spy?: string; + whisper?: string; + app: string; + appArgs?: string; + }): Promise; + dial(params: { caller?: string; timeout?: number }, callback: (err: Error) => void): void; + dial(callback: (err: Error) => void): void; + dial(params?: { caller?: string; timeout?: number }): Promise; + rtpstatistics(callback: (err: Error, rtpstat: RTPstat) => void): void; + rtpstatistics(): Promise; +} +export interface DeviceStates { + /* Methods */ + list(callback: (err: Error, devicestates: DeviceState[]) => void): void; + list(): Promise; + get(params: { deviceName: string }, callback: (err: Error, devicestate: DeviceState) => void): void; + get(params: { deviceName: string }): Promise; + update(params: { deviceName: string; deviceState: string }, callback: (err: Error) => void): void; + update(params: { deviceName: string; deviceState: string }): Promise; + delete(params: { deviceName: string }, callback: (err: Error) => void): void; + delete(params: { deviceName: string }): Promise; +} +export interface DeviceState extends Resource { + /* Properties */ + name: string; + state: string; + /* Methods */ + list(callback: (err: Error, devicestates: DeviceState[]) => void): void; + list(): Promise; + get(callback: (err: Error, devicestate: DeviceState) => void): void; + get(): Promise; + update(params: { deviceState: string }, callback: (err: Error) => void): void; + update(params: { deviceState: string }): Promise; + delete(callback: (err: Error) => void): void; + delete(): Promise; +} +export interface Endpoints { + /* Methods */ + list(callback: (err: Error, endpoints: Endpoint[]) => void): void; + list(): Promise; + sendMessage( + params: { to: string; from: string; body?: string; variables?: Containers }, + callback: (err: Error) => void, + ): void; + sendMessage(params: { to: string; from: string; body?: string; variables?: Containers }): Promise; + listByTech(params: { tech: string }, callback: (err: Error, endpoints: Endpoint[]) => void): void; + listByTech(callback: (err: Error, endpoints: Endpoint[]) => void): void; + listByTech(params?: { tech: string }): Promise; + get(params: { tech: string; resource: string }, callback: (err: Error, endpoint: Endpoint) => void): void; + get(callback: (err: Error, endpoint: Endpoint) => void): void; + get(params?: { tech: string; resource: string }): Promise; + sendMessageToEndpoint( + params: { tech: string; resource: string; from: string; body?: string; variables?: Containers }, + callback: (err: Error) => void, + ): void; + sendMessageToEndpoint(params: { + tech: string; + resource: string; + from: string; + body?: string; + variables?: Containers; + }): Promise; +} +export interface Endpoint extends Resource { + /* Properties */ + technology: string; + resource: string; + state?: string; + channel_ids: string | string[]; + /* Methods */ + list(callback: (err: Error, endpoints: Endpoint[]) => void): void; + list(): Promise; + sendMessage( + params: { to: string; from: string; body?: string; variables?: Containers }, + callback: (err: Error) => void, + ): void; + sendMessage(params: { to: string; from: string; body?: string; variables?: Containers }): Promise; + listByTech(callback: (err: Error, endpoints: Endpoint[]) => void): void; + listByTech(): Promise; + get(callback: (err: Error, endpoint: Endpoint) => void): void; + get(): Promise; + sendMessageToEndpoint( + params: { from: string; body?: string; variables?: Containers }, + callback: (err: Error) => void, + ): void; + sendMessageToEndpoint(params: { from: string; body?: string; variables?: Containers }): Promise; +} +export interface TextMessageVariable { + /* Properties */ + key: string; + value: string; +} +export interface TextMessage { + /* Properties */ + from: string; + to: string; + body: string; + variables?: TextMessageVariable | TextMessageVariable[]; +} +export interface Mailboxes { + /* Methods */ + list(callback: (err: Error, mailboxs: Mailbox[]) => void): void; + list(): Promise; + get(params: { mailboxName: string }, callback: (err: Error, mailbox: Mailbox) => void): void; + get(params: { mailboxName: string }): Promise; + update( + params: { mailboxName: string; oldMessages: number; newMessages: number }, + callback: (err: Error) => void, + ): void; + update(params: { mailboxName: string; oldMessages: number; newMessages: number }): Promise; + delete(params: { mailboxName: string }, callback: (err: Error) => void): void; + delete(params: { mailboxName: string }): Promise; +} +export interface Mailbox extends Resource { + /* Properties */ + name: string; + old_messages: number; + new_messages: number; + /* Methods */ + list(callback: (err: Error, mailboxs: Mailbox[]) => void): void; + list(): Promise; + get(callback: (err: Error, mailbox: Mailbox) => void): void; + get(): Promise; + update(params: { oldMessages: number; newMessages: number }, callback: (err: Error) => void): void; + update(params: { oldMessages: number; newMessages: number }): Promise; + delete(callback: (err: Error) => void): void; + delete(): Promise; +} +export interface Playbacks { + /* Methods */ + get(params: { playbackId: string }, callback: (err: Error, playback: Playback) => void): void; + get(params: { playbackId: string }): Promise; + stop(params: { playbackId: string }, callback: (err: Error) => void): void; + stop(params: { playbackId: string }): Promise; + control(params: { playbackId: string; operation: string }, callback: (err: Error) => void): void; + control(params: { playbackId: string; operation: string }): Promise; +} +export interface Playback extends Resource { + /* Properties */ + id: string; + media_uri: string; + next_media_uri?: string; + target_uri: string; + language: string; + state: string; + /* Methods */ + get(callback: (err: Error, playback: Playback) => void): void; + get(): Promise; + stop(callback: (err: Error) => void): void; + stop(): Promise; + control(params: { operation: string }, callback: (err: Error) => void): void; + control(params: { operation: string }): Promise; +} +export interface Recordings { + /* Methods */ + listStored(callback: (err: Error, storedrecordings: StoredRecording[]) => void): void; + listStored(): Promise; + getStored( + params: { recordingName: string }, + callback: (err: Error, storedrecording: StoredRecording) => void, + ): void; + getStored(params: { recordingName: string }): Promise; + deleteStored(params: { recordingName: string }, callback: (err: Error) => void): void; + deleteStored(params: { recordingName: string }): Promise; + getStoredFile(params: { recordingName: string }, callback: (err: Error, binary: Buffer) => void): void; + getStoredFile(params: { recordingName: string }): Promise; + copyStored( + params: { recordingName: string; destinationRecordingName: string }, + callback: (err: Error, storedrecording: StoredRecording) => void, + ): void; + copyStored(params: { recordingName: string; destinationRecordingName: string }): Promise; + getLive(params: { recordingName: string }, callback: (err: Error, liverecording: LiveRecording) => void): void; + getLive(params: { recordingName: string }): Promise; + cancel(params: { recordingName: string }, callback: (err: Error) => void): void; + cancel(params: { recordingName: string }): Promise; + stop(params: { recordingName: string }, callback: (err: Error) => void): void; + stop(params: { recordingName: string }): Promise; + pause(params: { recordingName: string }, callback: (err: Error) => void): void; + pause(params: { recordingName: string }): Promise; + unpause(params: { recordingName: string }, callback: (err: Error) => void): void; + unpause(params: { recordingName: string }): Promise; + mute(params: { recordingName: string }, callback: (err: Error) => void): void; + mute(params: { recordingName: string }): Promise; + unmute(params: { recordingName: string }, callback: (err: Error) => void): void; + unmute(params: { recordingName: string }): Promise; +} +export interface StoredRecording extends Resource { + /* Properties */ + name: string; + format: string; + /* Methods */ + listStored(callback: (err: Error, storedrecordings: StoredRecording[]) => void): void; + listStored(): Promise; + getStored(callback: (err: Error, storedrecording: StoredRecording) => void): void; + getStored(): Promise; + deleteStored(callback: (err: Error) => void): void; + deleteStored(): Promise; + getStoredFile(callback: (err: Error, binary: Buffer) => void): void; + getStoredFile(): Promise; + copyStored( + params: { destinationRecordingName: string }, + callback: (err: Error, storedrecording: StoredRecording) => void, + ): void; + copyStored(params: { destinationRecordingName: string }): Promise; + getLive(callback: (err: Error, liverecording: LiveRecording) => void): void; + getLive(): Promise; + cancel(callback: (err: Error) => void): void; + cancel(): Promise; + stop(callback: (err: Error) => void): void; + stop(): Promise; + pause(callback: (err: Error) => void): void; + pause(): Promise; + unpause(callback: (err: Error) => void): void; + unpause(): Promise; + mute(callback: (err: Error) => void): void; + mute(): Promise; + unmute(callback: (err: Error) => void): void; + unmute(): Promise; +} +export interface LiveRecording extends Resource { + /* Properties */ + name: string; + format: string; + target_uri: string; + state: string; + duration?: number; + talking_duration?: number; + silence_duration?: number; + cause?: string; + /* Methods */ + listStored(callback: (err: Error, storedrecordings: StoredRecording[]) => void): void; + listStored(): Promise; + getStored(callback: (err: Error, storedrecording: StoredRecording) => void): void; + getStored(): Promise; + deleteStored(callback: (err: Error) => void): void; + deleteStored(): Promise; + getStoredFile(callback: (err: Error, binary: Buffer) => void): void; + getStoredFile(): Promise; + copyStored( + params: { destinationRecordingName: string }, + callback: (err: Error, storedrecording: StoredRecording) => void, + ): void; + copyStored(params: { destinationRecordingName: string }): Promise; + getLive(callback: (err: Error, liverecording: LiveRecording) => void): void; + getLive(): Promise; + cancel(callback: (err: Error) => void): void; + cancel(): Promise; + stop(callback: (err: Error) => void): void; + stop(): Promise; + pause(callback: (err: Error) => void): void; + pause(): Promise; + unpause(callback: (err: Error) => void): void; + unpause(): Promise; + mute(callback: (err: Error) => void): void; + mute(): Promise; + unmute(callback: (err: Error) => void): void; + unmute(): Promise; +} +export interface Sounds { + /* Methods */ + list(params: { lang?: string; format?: string }, callback: (err: Error, sounds: Sound[]) => void): void; + list(callback: (err: Error, sounds: Sound[]) => void): void; + list(params?: { lang?: string; format?: string }): Promise; + get(params: { soundId: string }, callback: (err: Error, sound: Sound) => void): void; + get(params: { soundId: string }): Promise; +} +export interface FormatLangPair { + /* Properties */ + language: string; + format: string; +} +export interface Sound extends Resource { + /* Properties */ + id: string; + text?: string; + formats: FormatLangPair | FormatLangPair[]; + /* Methods */ + list(params: { lang?: string; format?: string }, callback: (err: Error, sounds: Sound[]) => void): void; + list(callback: (err: Error, sounds: Sound[]) => void): void; + list(params?: { lang?: string; format?: string }): Promise; + get(callback: (err: Error, sound: Sound) => void): void; + get(): Promise; +} diff --git a/types/ari-client/test/bridge.ts b/types/ari-client/test/bridge.ts new file mode 100644 index 0000000000..aebc722e67 --- /dev/null +++ b/types/ari-client/test/bridge.ts @@ -0,0 +1,56 @@ +import Ari, { Channel, Bridge, ChannelLeftBridge } from 'ari-client'; + +// TypeScript version of example published on project https://github.com/asterisk/node-ari-client. + +Ari.connect( + 'http://ari.js:8088', + 'user', + 'secret', + + (err, client) => { + // use once to start the application + client.on('StasisStart', (event, incoming) => { + incoming.answer(err => { + getOrCreateBridge(incoming); + }); + }); + + const getOrCreateBridge = (channel: Channel) => { + client.bridges.list((err: Error, bridges: Bridge[]) => { + let bridge = bridges.filter((candidate: Bridge) => { + return candidate['bridge_type'] === 'holding'; + })[0]; + + if (!bridge) { + bridge = client.Bridge(); + bridge.create({ type: 'holding' }, (err: Error, bridge: Bridge) => { + bridge.on('ChannelLeftBridge', (event, instances) => { + cleanupBridge(event, instances, bridge); + }); + joinHoldingBridgeAndPlayMoh(bridge, channel); + }); + } else { + // Add incoming channel to existing holding bridge and play + // music on hold + joinHoldingBridgeAndPlayMoh(bridge, channel); + } + }); + }; + + const cleanupBridge = (event: ChannelLeftBridge, instances: ChannelLeftBridge, bridge: Bridge) => { + const holdingBridge = instances.bridge; + if (holdingBridge.channels.length === 0 && holdingBridge.id === bridge.id) { + bridge.destroy(err => {}); + } + }; + + const joinHoldingBridgeAndPlayMoh = (bridge: Bridge, channel: Channel) => { + bridge.addChannel({ channel: channel.id }, err => { + channel.startMoh(err => {}); + }); + }; + + // can also use client.start(['app-name'...]) to start multiple applications + client.start('bridge-example'); + }, +); diff --git a/types/ari-client/test/bridgeAsyncAwait.ts b/types/ari-client/test/bridgeAsyncAwait.ts new file mode 100644 index 0000000000..2515d3490f --- /dev/null +++ b/types/ari-client/test/bridgeAsyncAwait.ts @@ -0,0 +1,50 @@ +import Ari, { Channel, Bridge } from 'ari-client'; + +// async/await version of the example published on project https://github.com/asterisk/node-ari-client. + +export default async () => { + try { + const client = await Ari.connect('http://ari.js:8088', 'user', 'secret'); + + client.on('StasisStart', async (event, incoming) => { + await incoming.answer(); + const bridge = await getOrCreateBridge(); + await joinHoldingBridgeAndPlayMoh(bridge, incoming); + }); + + const getOrCreateBridge = async () => { + const bridges = await client.bridges.list(); + let bridge = bridges.filter(candidate => { + return candidate['bridge_type'] === 'holding'; + })[0]; + + if (!bridge) { + bridge = client.Bridge(); + return bridge.create({ type: 'holding' }); + } else { + // Add incoming channel to existing holding bridge and play + // music on hold + return bridge; + } + }; + + const joinHoldingBridgeAndPlayMoh = async (bridge: Bridge, channel: Channel) => { + bridge.on('ChannelLeftBridge', async (event, instances) => { + const holdingBridge = instances.bridge; + if (holdingBridge.channels.length === 0 && holdingBridge.id === bridge.id) { + try { + await bridge.destroy(); + } catch (err) { + console.error(err); + } + } + }); + await bridge.addChannel({ channel: channel.id }); + await channel.startMoh(); + }; + + client.start('bridge-example'); + } catch (err) { + console.error(err); + } +}; diff --git a/types/ari-client/test/deviceState.ts b/types/ari-client/test/deviceState.ts new file mode 100644 index 0000000000..a4d6bdced1 --- /dev/null +++ b/types/ari-client/test/deviceState.ts @@ -0,0 +1,56 @@ +import Ari from 'ari-client'; +import util = require('util'); + +// TypeScript version of example published on project https://github.com/asterisk/node-ari-client. + +const BRIDGE_STATE = 'device-state-example'; + +// replace ari.js with your Asterisk instance +Ari.connect('http://ari.js:8088', 'user', 'secret', (err, client) => { + const bridge = client.Bridge(); + // Keep track of bridge state at the application level so we don't have to + // make extra calls to ARI + let currentBridgeState = 'NOT_INUSE'; + + bridge.create({ type: 'mixing' }, (err, instance) => { + // Mark this bridge as available + const opts = { + deviceName: util.format('Stasis:%s', BRIDGE_STATE), + deviceState: 'NOT_INUSE', + }; + client.deviceStates.update(opts, err => {}); + }); + + client.on('ChannelEnteredBridge', (event, objects) => { + if (objects.bridge.channels.length > 0 && currentBridgeState !== 'BUSY') { + // Mark this bridge as busy + const opts = { + deviceName: util.format('Stasis:%s', BRIDGE_STATE), + deviceState: 'BUSY', + }; + client.deviceStates.update(opts, err => {}); + currentBridgeState = 'BUSY'; + } + }); + + client.on('ChannelLeftBridge', (event, objects) => { + if (objects.bridge.channels.length === 0 && currentBridgeState !== 'NOT_INUSE') { + // Mark this bridge as available + const opts = { + deviceName: util.format('Stasis:%s', BRIDGE_STATE), + deviceState: 'NOT_INUSE', + }; + client.deviceStates.update(opts, err => {}); + currentBridgeState = 'NOT_INUSE'; + } + }); + + client.on('StasisStart', (event, incoming) => { + incoming.answer(err => { + bridge.addChannel({ channel: incoming.id }, err => {}); + }); + }); + + // can also use client.start(['app-name'...]) to start multiple applications + client.start('device-state-example'); +}); diff --git a/types/ari-client/test/deviceStateAsyncAwait.ts b/types/ari-client/test/deviceStateAsyncAwait.ts new file mode 100644 index 0000000000..2a9eebd326 --- /dev/null +++ b/types/ari-client/test/deviceStateAsyncAwait.ts @@ -0,0 +1,72 @@ +import Ari from 'ari-client'; +import util = require('util'); + +// async/await version of the example published on project https://github.com/asterisk/node-ari-client. + +export default async () => { + const BRIDGE_STATE = 'device-state-example'; + + try { + const client = await Ari.connect('http://ari.js:8088', 'user', 'secret'); + + const bridge = client.Bridge(); + // Keep track of bridge state at the application level so we don't have to + // make extra calls to ARI + let currentBridgeState = 'NOT_INUSE'; + + const instance = await bridge.create({ type: 'mixing' }); + + // Mark this bridge as available + const opts = { + deviceName: util.format('Stasis:%s', BRIDGE_STATE), + deviceState: 'NOT_INUSE', + }; + await client.deviceStates.update(opts); + + client.on('ChannelEnteredBridge', async (event, objects) => { + if (objects.bridge.channels.length > 0 && currentBridgeState !== 'BUSY') { + // Mark this bridge as busy + const opts = { + deviceName: util.format('Stasis:%s', BRIDGE_STATE), + deviceState: 'BUSY', + }; + try { + await client.deviceStates.update(opts); + currentBridgeState = 'BUSY'; + } catch (err) { + console.error(err); + } + } + }); + + client.on('ChannelLeftBridge', async (event, objects) => { + if (objects.bridge.channels.length === 0 && currentBridgeState !== 'NOT_INUSE') { + // Mark this bridge as available + const opts = { + deviceName: util.format('Stasis:%s', BRIDGE_STATE), + deviceState: 'NOT_INUSE', + }; + try { + await client.deviceStates.update(opts); + currentBridgeState = 'NOT_INUSE'; + } catch (err) { + console.error(err); + } + } + }); + + client.on('StasisStart', async (event, incoming) => { + try { + await incoming.answer(); + await bridge.addChannel({ channel: incoming.id }); + } catch (err) { + console.error(err); + } + }); + + // can also use client.start(['app-name'...]) to start multiple applications + client.start('device-state-example'); + } catch (err) { + console.error(err); + } +}; diff --git a/types/ari-client/test/example.ts b/types/ari-client/test/example.ts new file mode 100644 index 0000000000..f2658195dd --- /dev/null +++ b/types/ari-client/test/example.ts @@ -0,0 +1,50 @@ +import Ari, { Channel } from 'ari-client'; +import util = require('util'); + +// TypeScript version of example published on project https://github.com/asterisk/node-ari-client. + +// replace ari.js with your Asterisk instance +Ari.connect('http://ari.js:8088', 'user', 'secret', (err, client) => { + if (err) { + throw err; // program will crash if it fails to connect + } + + // Use once to start the application + client.on('StasisStart', (event, incoming) => { + // Handle DTMF events + incoming.on('ChannelDtmfReceived', (event, channel) => { + const digit = event.digit; + switch (digit) { + case '#': + play(channel, 'sound:vm-goodbye', err => { + channel.hangup(err => { + process.exit(0); + }); + }); + break; + case '*': + play(channel, 'sound:tt-monkeys'); + break; + default: + play(channel, util.format('sound:digits/%s', digit)); + } + }); + + incoming.answer(err => { + play(incoming, 'sound:hello-world'); + }); + }); + + const play = (channel: Channel, sound: string, callback?: (param: any) => void) => { + const playback = client.Playback(); + playback.once('PlaybackFinished', (event, instance) => { + if (callback) { + callback(null); + } + }); + channel.play({ media: sound }, playback, (err, playback) => {}); + }; + + // can also use client.start(['app-name'...]) to start multiple applications + client.start('example'); +}); diff --git a/types/ari-client/test/exampleAsyncAwait.ts b/types/ari-client/test/exampleAsyncAwait.ts new file mode 100644 index 0000000000..d32d5a3bbb --- /dev/null +++ b/types/ari-client/test/exampleAsyncAwait.ts @@ -0,0 +1,52 @@ +import Ari, { Channel } from 'ari-client'; +import util = require('util'); + +// async/await version of the example published on project https://github.com/asterisk/node-ari-client. + +export default async () => { + try { + const client = await Ari.connect('http://ari.js:8088', 'user', 'secret'); + + // Use once to start the application + client.on('StasisStart', async (event, incoming) => { + // Handle DTMF events + incoming.on('ChannelDtmfReceived', async (event, channel) => { + const digit = event.digit; + switch (digit) { + case '#': + await play(channel, 'sound:vm-goodbye'); + await channel.hangup(); + process.exit(0); + break; + case '*': + await play(channel, 'sound:tt-monkeys'); + break; + default: + await play(channel, util.format('sound:digits/%s', digit)); + } + }); + + await incoming.answer(); + await play(incoming, 'sound:hello-world'); + }); + + const play = (channel: Channel, sound: string) => { + const playback = client.Playback(); + + return new Promise((resolve, reject) => { + playback.once('PlaybackFinished', (event, playback) => { + resolve(playback); + }); + + channel.play({ media: sound }, playback).catch(err => { + reject(err); + }); + }); + }; + + // can also use client.start(['app-name'...]) to start multiple applications + client.start('example'); + } catch (err) { + console.error(err); + } +}; diff --git a/types/ari-client/test/mwi.ts b/types/ari-client/test/mwi.ts new file mode 100644 index 0000000000..5400a67c64 --- /dev/null +++ b/types/ari-client/test/mwi.ts @@ -0,0 +1,101 @@ +import Ari from 'ari-client'; +import util = require('util'); + +// TypeScript version of example published on project https://github.com/asterisk/node-ari-client. + +// replace ari.js with your Asterisk instance +Ari.connect('http://ari.js:8088', 'user', 'secret', (err, client) => { + // Create new mailbox + const mailbox = client.Mailbox('mwi-example'); + let messages = 0; + + client.on( + 'StasisStart', + + (event, channel) => { + channel.on('ChannelDtmfReceived', (event, channel) => { + const digit = event.digit; + switch (digit) { + case '5': + // Record message + const recording = client.LiveRecording(); + + recording.once('RecordingFinished', (event, newRecording) => { + const playback = client.Playback(); + playback.once('PlaybackFinished', (event, newPlayback) => { + // Update MWI + messages += 1; + const opts = { + oldMessages: 0, + newMessages: messages, + }; + mailbox.update(opts, err => {}); + + channel.hangup(err => {}); + }); + + channel.play({ media: 'sound:vm-msgsaved' }, playback, err => {}); + }); + + const opts = { + name: channel.id, // name parameter is required. See channels.json fixture file. + format: 'wav', + maxSilenceSeconds: 2, + beep: true, + }; + + // Record a message + channel.record(opts, recording, err => {}); + break; + case '6': + // Playback last message + client.recordings.listStored((err, recordings) => { + const playback = client.Playback(); + const recording = recordings[recordings.length - 1]; + + if (!recording) { + channel.play({ media: 'sound:vm-nomore' }, playback, err => {}); + } else { + playback.once('PlaybackFinished', (event, newPlayback) => { + recording.deleteStored(err => { + // Remove MWI + messages -= 1; + const opts = { + oldMessages: 0, + newMessages: messages, + }; + mailbox.update(opts, err => {}); + + const playback = client.Playback(); + channel.play({ media: 'sound:vm-next' }, playback, err => {}); + }); + }); + + const opts = { + media: util.format('recording:%s', recording.name), + }; + + // Play the latest message + channel.play(opts, playback, err => {}); + } + }); + break; + } + }); + + channel.answer(err => { + let playback = client.Playback(); + + playback.once('PlaybackFinished', (err, newPlayback) => { + playback = client.Playback(); + channel.play({ media: 'sound:vm-next' }, playback, err => {}); + }); + + channel.play({ media: 'sound:vm-leavemsg' }, playback, err => {}); + }); + }, + ); + + // can also use client.start(['app-name'...]) to start multiple applications + client.start('mwi-example'); +}); diff --git a/types/ari-client/test/mwiAsyncAwait.ts b/types/ari-client/test/mwiAsyncAwait.ts new file mode 100644 index 0000000000..c6b80bb842 --- /dev/null +++ b/types/ari-client/test/mwiAsyncAwait.ts @@ -0,0 +1,99 @@ +import Ari from 'ari-client'; +import util = require('util'); + +// async/await version of the example published on project https://github.com/asterisk/node-ari-client. + +export default async () => { + try { + const client = await Ari.connect('http://ari.js:8088', 'user', 'secret'); + + // Create new mailbox + const mailbox = client.Mailbox('mwi-example'); + let messages = 0; + + client.on('StasisStart', async (event, channel) => { + channel.on('ChannelDtmfReceived', async (event, channel) => { + const digit = event.digit; + switch (digit) { + case '5': + // Record message + const message = client.LiveRecording(); + + message.once('RecordingFinished', async (event, newRecording) => { + const playback = client.Playback(); + playback.once('PlaybackFinished', async (event, newPlayback) => { + // Update MWI + messages += 1; + const opts = { + oldMessages: 0, + newMessages: messages, + }; + await mailbox.update(opts); + await channel.hangup(); + }); + + await channel.play({ media: 'sound:vm-msgsaved' }, playback); + }); + + const messageOptions = { + name: channel.id, // name parameter is required. See channels.json fixture file. + format: 'wav', + maxSilenceSeconds: 2, + beep: true, + }; + + // Record a message + await channel.record(messageOptions, message); + break; + case '6': + // Playback last message + const recordings = await client.recordings.listStored(); + + const playback = client.Playback(); + const lastMessage = recordings[recordings.length - 1]; + + if (!lastMessage) return channel.play({ media: 'sound:vm-nomore' }, playback); + + playback.once('PlaybackFinished', async (event, newPlayback) => { + await lastMessage.deleteStored(); + + // Remove MWI + messages -= 1; + const opts = { + oldMessages: 0, + newMessages: messages, + }; + await mailbox.update(opts); + + const playback = client.Playback(); + await channel.play({ media: 'sound:vm-next' }, playback); + }); + + const lastMessageOptions = { + media: util.format('recording:%s', lastMessage.name), + }; + + // Play the latest message + await channel.play(lastMessageOptions, playback); + + break; + } + }); + + await channel.answer(); + let playback = client.Playback(); + + playback.once('PlaybackFinished', async (err, newPlayback) => { + playback = client.Playback(); + await channel.play({ media: 'sound:vm-next' }, playback); + }); + + await channel.play({ media: 'sound:vm-leavemsg' }, playback); + }); + + // can also use client.start(['app-name'...]) to start multiple applications + client.start('mwi-example'); + } catch (err) { + console.error(err); + } +}; diff --git a/types/ari-client/test/originate.ts b/types/ari-client/test/originate.ts new file mode 100644 index 0000000000..7e6c7b32b9 --- /dev/null +++ b/types/ari-client/test/originate.ts @@ -0,0 +1,55 @@ +import Ari, { Channel, Containers } from 'ari-client'; + +// TypeScript version of example published on project https://github.com/asterisk/node-ari-client. + +const ENDPOINT = 'PJSIP/sipphone'; + +// replace ari.js with your Asterisk instance +Ari.connect('http://ari.js:8088', 'user', 'secret', (err, client) => { + // Use once to start the application to ensure this listener will only run + // for the incoming channel + client.once('StasisStart', (event, incoming) => { + incoming.answer(err => { + originate(incoming); + }); + }); + + const originate = (incoming: Channel) => { + incoming.once('StasisEnd', (event, channel) => { + outgoing.hangup(err => {}); + }); + + const outgoing = client.Channel(); + + outgoing.once('ChannelDestroyed', (event, channel) => { + incoming.hangup(err => {}); + }); + + outgoing.once('StasisStart', (event, outgoing) => { + const bridge = client.Bridge(); + + outgoing.once('StasisEnd', (event, channel) => { + bridge.destroy(err => {}); + }); + + outgoing.answer(err => { + bridge.create({ type: 'mixing' }, (err, bridge) => { + bridge.addChannel({ channel: [incoming.id, outgoing.id] }, err => {}); + }); + }); + }); + + const playback = client.Playback(); + incoming.play({ media: 'sound:vm-dialout' }, playback, err => {}); + + // Originate call from incoming channel to endpoint + const variables: Containers = { 'CALLERID(name)': 'Alice', name: 'test' }; + outgoing.originate( + { endpoint: ENDPOINT, app: 'originate-example', appArgs: 'dialed', variables }, + (err, channel) => {}, + ); + }; + + // can also use client.start(['app-name'...]) to start multiple applications + client.start('originate-example'); +}); diff --git a/types/ari-client/test/originateAsyncAwait.ts b/types/ari-client/test/originateAsyncAwait.ts new file mode 100644 index 0000000000..3812493935 --- /dev/null +++ b/types/ari-client/test/originateAsyncAwait.ts @@ -0,0 +1,55 @@ +import Ari, { Channel } from 'ari-client'; + +// async/await version of the example published on project https://github.com/asterisk/node-ari-client. + +export default async () => { + try { + const client = await Ari.connect('http://ari.js:8088', 'user', 'secret'); + const ENDPOINT = 'PJSIP/sipphone'; + + // Use once to start the application to ensure this listener will only run + // for the incoming channel + client.once('StasisStart', async (event, incoming) => { + await incoming.answer(); + originate(incoming); + }); + + const originate = async (incoming: Channel) => { + incoming.once('StasisEnd', async (event, channel) => { + await outgoing.hangup(); + }); + + const outgoing = client.Channel(); + + outgoing.once('ChannelDestroyed', async (event, channel) => { + await incoming.hangup(); + }); + + outgoing.once('StasisStart', async (event, outgoing) => { + const bridge = client.Bridge(); + + outgoing.once('StasisEnd', async (event, channel) => { + await bridge.destroy(); + }); + + await outgoing.answer(); + const mixingBridge = await bridge.create({ type: 'mixing' }); + await mixingBridge.addChannel({ channel: [incoming.id, outgoing.id] }); + }); + + const playback = client.Playback(); + await incoming.play({ media: 'sound:vm-dialout' }, playback); + + // Originate call from incoming channel to endpoint + await outgoing.originate({ + endpoint: ENDPOINT, + app: 'originate-example', + appArgs: 'dialed', + }); + }; + + client.start('originate-example'); + } catch (err) { + console.error(err); + } +}; diff --git a/types/ari-client/test/playback.ts b/types/ari-client/test/playback.ts new file mode 100644 index 0000000000..e5e11a72a3 --- /dev/null +++ b/types/ari-client/test/playback.ts @@ -0,0 +1,54 @@ +import Ari, { Channel, Playback } from 'ari-client'; +import util = require('util'); + +// TypeScript version of example published on project https://github.com/asterisk/node-ari-client. + +// replace ari.js with your Asterisk instance +Ari.connect('http://ari.js:8088', 'user', 'secret', (err, client) => { + // Use once to start the application + client.once('StasisStart', (event, incoming) => { + incoming.answer(err => { + const playback = client.Playback(); + + // Play demo greeting and register dtmf event listeners + incoming.play({ media: 'sound:demo-congrats' }, playback, (err, playback) => { + registerDtmfListeners(err, playback, incoming); + }); + }); + }); + + const registerDtmfListeners = (err: Error, playback: Playback, incoming: Channel) => { + incoming.on('ChannelDtmfReceived', (event, channel) => { + const digit = event.digit; + + switch (digit) { + case '5': + playback.control({ operation: 'pause' }, err => {}); + break; + case '8': + playback.control({ operation: 'unpause' }, err => {}); + break; + case '4': + playback.control({ operation: 'reverse' }, err => {}); + break; + case '6': + playback.control({ operation: 'forward' }, err => {}); + break; + case '2': + playback.control({ operation: 'restart' }, err => {}); + break; + case '#': + playback.control({ operation: 'stop' }, err => {}); + incoming.hangup(err => { + process.exit(0); + }); + break; + default: + console.error(util.format('Unknown DTMF %s', digit)); + } + }); + }; + + // can also use client.start(['app-name'...]) to start multiple applications + client.start('playback-example'); +}); diff --git a/types/ari-client/test/playbackAsyncAwait.ts b/types/ari-client/test/playbackAsyncAwait.ts new file mode 100644 index 0000000000..9185773b9f --- /dev/null +++ b/types/ari-client/test/playbackAsyncAwait.ts @@ -0,0 +1,52 @@ +import Ari, { Channel, Playback } from 'ari-client'; +import util = require('util'); + +// async/await version of the example published on project https://github.com/asterisk/node-ari-client. + +export default async () => { + try { + const client = await Ari.connect('http://ari.js:8088', 'user', 'secret'); + + // Use once to start the application + client.once('StasisStart', async (event, incoming) => { + await incoming.answer(); + const playback = client.Playback(); + // Play demo greeting and register dtmf event listeners + const newPlayback = await incoming.play({ media: 'sound:demo-congrats' }, playback); + registerDtmfListeners(newPlayback, incoming); + }); + + const registerDtmfListeners = (playback: Playback, incoming: Channel) => { + incoming.on('ChannelDtmfReceived', async (event, channel) => { + const digit = event.digit; + switch (digit) { + case '5': + await playback.control({ operation: 'pause' }); + break; + case '8': + await playback.control({ operation: 'unpause' }); + break; + case '4': + await playback.control({ operation: 'reverse' }); + break; + case '6': + await playback.control({ operation: 'forward' }); + break; + case '2': + await playback.control({ operation: 'restart' }); + break; + case '#': + await playback.control({ operation: 'stop' }); + await incoming.hangup(); + process.exit(0); + default: + console.error(util.format('Unknown DTMF %s', digit)); + } + }); + }; + + client.start('playback-example'); + } catch (err) { + console.error(err); + } +}; diff --git a/types/ari-client/tsconfig.json b/types/ari-client/tsconfig.json new file mode 100644 index 0000000000..448c454b08 --- /dev/null +++ b/types/ari-client/tsconfig.json @@ -0,0 +1,35 @@ +{ + "files": [ + "index.d.ts", + "test/bridge.ts", + "test/bridgeAsyncAwait.ts", + "test/deviceState.ts", + "test/deviceStateAsyncAwait.ts", + "test/example.ts", + "test/exampleAsyncAwait.ts", + "test/mwi.ts", + "test/mwiAsyncAwait.ts", + "test/originate.ts", + "test/originateAsyncAwait.ts", + "test/playback.ts", + "test/playbackAsyncAwait.ts" + ], + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "esModuleInterop": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + } +} diff --git a/types/ari-client/tslint.json b/types/ari-client/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/ari-client/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}