Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * port: port server
- * host: host server
- * username: username for authentication
- * password: username's password for authentication
- * events: this parameter determines whether events are emited.
- **/
- import { HOST, PASSWORD, PORT, USERNAME } from "./config";
- const ami = require('asterisk-manager')(PORT, HOST, USERNAME, PASSWORD, true);
- // In case of any connectiviy problems we got you coverd.
- ami.keepConnected();
- let gettingQueueStatuResponse = false;
- function getQueueStatus() {
- gettingQueueStatuResponse = true;
- ami.action({
- 'action': 'queues',
- // 'channel':'SIP/myphone',
- // 'context':'default',
- // 'exten': '',
- // 'priority': '1',
- // 'variable':{
- // 'name1':'value1',
- // 'name2':'value2'
- // }
- }, (err, res) => {
- console.log(err);
- console.log(res);
- });
- }
- const queueMembers = [] as any[];
- async function main() {
- // Listen for any/all AMI events.
- ami.on('managerevent', (event) => {
- console.log('managerevent', event.event);
- if (event.event.includes('Agent')) {
- console.log(event);
- }
- if (event.event === 'QueueParams') {
- gettingQueueStatuResponse = true;
- }
- if (event.event === 'QueueMember' && gettingQueueStatuResponse) {
- return queueMembers.push(event);
- }
- if (event.event === 'QueueStatusComplete') {
- gettingQueueStatuResponse = false;
- return console.log(queueMembers);
- }
- });
- // Listen for specific AMI events. A list of event names can be found at
- // https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+AMI+Events
- ami.on('hangup', (event) => {
- console.log('hangup', event);
- });
- ami.on('confbridgejoin', (event) => {
- console.log('confbridgejoin', event);
- });
- // Listen for Action responses.
- ami.on('response', (event) => {
- console.log('response', event);
- });
- await new Promise(resolve => setTimeout(resolve, 2000));
- // getQueueStatus();
- ami.action({
- 'action': 'queuestatus',
- // 'channel':'SIP/myphone',
- // 'context':'default',
- // 'exten': '',
- // 'priority': '1',
- // 'variable':{
- // 'name1':'value1',
- // 'name2':'value2'
- // }
- }, (err, res) => {
- console.log(err);
- console.log(res);
- });
- // await new Promise(resolve => setTimeout(resolve, 2000));
- // ami.action({
- // 'action':'queuestatus',
- // // 'channel':'SIP/myphone',
- // // 'context':'default',
- // // 'exten': '',
- // // 'priority': '1',
- // // 'variable':{
- // // 'name1':'value1',
- // // 'name2':'value2'
- // // }
- // }, (err, res) => {
- // console.log(err);
- // console.log(res);
- // });
- return;
- }
- main();
- // Perform an AMI Action. A list of actions can be found at
- // https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+AMI+Actions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement