Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asterisk Manager #75

Open
prathibhacdac opened this issue Jul 20, 2023 · 3 comments
Open

Asterisk Manager #75

prathibhacdac opened this issue Jul 20, 2023 · 3 comments

Comments

@prathibhacdac
Copy link

How to use asterisk manager?

@prathibhacdac
Copy link
Author

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

@prathibhacdac
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant