27 lines
994 B
JavaScript
27 lines
994 B
JavaScript
const agi = require("asteriskagi")
|
|
const x = new agi({port: 4578})
|
|
|
|
x.on('call', async (call) => {
|
|
const { remoteServer, uniqueid, context, extension, priority, calleridname, callerid, channel } = call;
|
|
call.on("hangup", () => {
|
|
console.log(`Hangup ${remoteServer}/${channel}`);
|
|
});
|
|
|
|
call.on("error", (err) => {
|
|
console.error(`ERROR: ${remoteServer}/${channel}: ${err}`);
|
|
});
|
|
|
|
console.log(`Call from ${callerid} (${calleridname}) to ${extension} in context ${context} on channel ${channel} with uniqueid ${uniqueid}`);
|
|
|
|
await call.Playback("beep");
|
|
while (true) {
|
|
await call.Read("EXTEN_INPUT", "beep", "", "", 3, 0);
|
|
const exten = await call.getVariable("EXTEN_INPUT");
|
|
console.log(`Got ${exten}`);
|
|
if (!exten) break;
|
|
}
|
|
await call.Playback("goodbye");
|
|
await call.Hangup();
|
|
})
|
|
|
|
// Originate outbound with asterisk -x "originate Local/15809197945@from-internal application AGI agi://127.0.0.1:4578"
|