NodeJS-AsteriskManager icon indicating copy to clipboard operation
NodeJS-AsteriskManager copied to clipboard

Asterisk Manager

Open prathibhacdac opened this issue 1 year ago • 3 comments

How to use asterisk manager?

prathibhacdac avatar Jul 20 '23 10:07 prathibhacdac

When tested from terminal through telnet it is working, But not working when tested using nodejs.

prathibhacdac avatar Jul 21 '23 11:07 prathibhacdac

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}`);
});

prathibhacdac avatar Jul 21 '23 11:07 prathibhacdac

I'm getting the msg Call Initiated but the PJSIP client has not received the call.

prathibhacdac avatar Jul 21 '23 11:07 prathibhacdac