Open prathibhacdac opened 1 year ago
When tested from terminal through telnet it is working, But not working when tested using nodejs.
const manager = require('asterisk-manager');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const amiConfig = {
host: 'https://bp2.erss.in',
port: '5038', // Default AMI port is 5038
username: 'ami',
password: 'ami'
};
const ami = new manager(amiConfig);
//ami.keepConnected();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
app.post('/makeCall', (req, res) => {
const phoneNumber = req.body.phoneNumber;
//console.log(phoneNumber);
// You can validate the phone number here before proceeding
// Make the call when the form is submitted
makeCall(phoneNumber);
res.status(200).send('Call initiated.');
});
function makeCall(phoneNumber) {
const callParams = {
action: 'originate',
channel: 'PJSIP/' + phoneNumber,
exten: '100',
context: 'from-extensions',
priority: 1,
};
ami.action(callParams, (err, res) => {
if (err) {
console.error('Error making call:', err);
} else {
console.log('Call initiated:', res);
}
});
}
const port = 3000;
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
I'm getting the msg Call Initiated but the PJSIP client has not received the call.
How to use asterisk manager?