AGIDemo/index.js
2026-06-21 23:05:54 -06:00

27 lines
982 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,,1,,10000");
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"