Skip to content

Commit 2d64261

Browse files
committed
Added continueDialplan() method to ChannelInstance for dialplan continuation
Implemented snoop() and snoopWithId() methods for call interaction Improved compatibility with CommonJS projects Fixed import errors in projects with different moduleResolution settings Created a package.json file in the dist/cjs folder to ensure CommonJS compatibility
1 parent 5cc6619 commit 2d64261

File tree

9 files changed

+278
-10
lines changed

9 files changed

+278
-10
lines changed

build.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { execSync } from "node:child_process";
22
import * as esbuild from "esbuild";
3+
import fs from "node:fs";
4+
import path from "node:path";
35

46
// Caminhos principais
57
const entryFile = "src/index.ts"; // Entrada principal
@@ -50,6 +52,16 @@ try {
5052
external: ["util", "stream", "axios", "ws", "form-data"],
5153
});
5254

55+
// 4. Certifique-se de que o arquivo package.json do CJS tem type=commonjs
56+
const cjsDir = path.dirname(cjsOutputFile);
57+
const cjsPackageJson = path.join(cjsDir, 'package.json');
58+
59+
console.log("Criando package.json para compatibilidade CommonJS...");
60+
fs.writeFileSync(
61+
cjsPackageJson,
62+
JSON.stringify({ type: "commonjs" }, null, 2)
63+
);
64+
5365
console.log("Build concluído com sucesso!");
5466
} catch (error) {
5567
console.error("Erro durante o processo de build:", error);

dist/cjs/index.cjs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,78 @@ var ChannelInstance = class {
18971897
throw new Error(`Failed to originate channel: ${message}`);
18981898
}
18991899
}
1900+
/**
1901+
* Continues the execution of a dialplan for the current channel.
1902+
*
1903+
* @param {string} [context] - The dialplan context to continue execution in, if specified.
1904+
* @param {string} [extension] - The dialplan extension to proceed with, if provided.
1905+
* @param {number} [priority] - The priority within the dialplan extension to resume at, if specified.
1906+
* @param {string} [label] - The label to start from within the dialplan, if given.
1907+
* @return {Promise<void>} Resolves when the dialplan is successfully continued.
1908+
*/
1909+
async continueDialplan(context, extension, priority, label) {
1910+
try {
1911+
if (!this.channelData) {
1912+
this.channelData = await this.getDetails();
1913+
}
1914+
await this.baseClient.post(`/channels/${this.id}/continue`, {
1915+
context,
1916+
extension,
1917+
priority,
1918+
label
1919+
});
1920+
} catch (error) {
1921+
const message = getErrorMessage2(error);
1922+
console.error(`Error continuing dialplan for channel ${this.id}:`, message);
1923+
throw new Error(`Failed to continue dialplan: ${message}`);
1924+
}
1925+
}
1926+
/**
1927+
* Initiates a snoop operation on this channel with the provided options.
1928+
* Snooping allows you to listen in or interact with an existing call.
1929+
*
1930+
* @param {SnoopOptions} options - Configuration options for the snooping operation.
1931+
* @return {Promise<Channel>} A promise that resolves to the snooped channel data.
1932+
* @throws {Error} If the channel is not initialized or if snooping fails.
1933+
*/
1934+
async snoop(options) {
1935+
try {
1936+
if (!this.channelData) {
1937+
this.channelData = await this.getDetails();
1938+
}
1939+
const queryParams = toQueryParams2(options);
1940+
return await this.baseClient.post(
1941+
`/channels/${this.id}/snoop?${queryParams}`
1942+
);
1943+
} catch (error) {
1944+
const message = getErrorMessage2(error);
1945+
console.error(`Error snooping on channel ${this.id}:`, message);
1946+
throw new Error(`Failed to snoop channel: ${message}`);
1947+
}
1948+
}
1949+
/**
1950+
* Initiates a snoop operation on this channel with a specific snoop ID.
1951+
*
1952+
* @param {string} snoopId - The unique identifier for the snoop operation.
1953+
* @param {SnoopOptions} options - Configuration options for the snooping operation.
1954+
* @return {Promise<Channel>} A promise that resolves to the snooped channel data.
1955+
* @throws {Error} If the channel is not initialized or if snooping fails.
1956+
*/
1957+
async snoopWithId(snoopId, options) {
1958+
try {
1959+
if (!this.channelData) {
1960+
this.channelData = await this.getDetails();
1961+
}
1962+
const queryParams = toQueryParams2(options);
1963+
return await this.baseClient.post(
1964+
`/channels/${this.id}/snoop/${snoopId}?${queryParams}`
1965+
);
1966+
} catch (error) {
1967+
const message = getErrorMessage2(error);
1968+
console.error(`Error snooping with ID on channel ${this.id}:`, message);
1969+
throw new Error(`Failed to snoop channel with ID: ${message}`);
1970+
}
1971+
}
19001972
/**
19011973
* Plays media on the channel
19021974
*/

dist/cjs/index.cjs.map

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

dist/esm/index.js

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/esm/index.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types/ari-client/resources/channels.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ export declare class ChannelInstance {
6464
* @throws Error if channel already exists or origination fails
6565
*/
6666
originate(data: OriginateRequest): Promise<Channel>;
67+
/**
68+
* Continues the execution of a dialplan for the current channel.
69+
*
70+
* @param {string} [context] - The dialplan context to continue execution in, if specified.
71+
* @param {string} [extension] - The dialplan extension to proceed with, if provided.
72+
* @param {number} [priority] - The priority within the dialplan extension to resume at, if specified.
73+
* @param {string} [label] - The label to start from within the dialplan, if given.
74+
* @return {Promise<void>} Resolves when the dialplan is successfully continued.
75+
*/
76+
continueDialplan(context?: string, extension?: string, priority?: number, label?: string): Promise<void>;
77+
/**
78+
* Initiates a snoop operation on this channel with the provided options.
79+
* Snooping allows you to listen in or interact with an existing call.
80+
*
81+
* @param {SnoopOptions} options - Configuration options for the snooping operation.
82+
* @return {Promise<Channel>} A promise that resolves to the snooped channel data.
83+
* @throws {Error} If the channel is not initialized or if snooping fails.
84+
*/
85+
snoop(options: SnoopOptions): Promise<Channel>;
86+
/**
87+
* Initiates a snoop operation on this channel with a specific snoop ID.
88+
*
89+
* @param {string} snoopId - The unique identifier for the snoop operation.
90+
* @param {SnoopOptions} options - Configuration options for the snooping operation.
91+
* @return {Promise<Channel>} A promise that resolves to the snooped channel data.
92+
* @throws {Error} If the channel is not initialized or if snooping fails.
93+
*/
94+
snoopWithId(snoopId: string, options: SnoopOptions): Promise<Channel>;
6795
/**
6896
* Plays media on the channel
6997
*/

0 commit comments

Comments
 (0)