Open fabiotheo opened 5 years ago
i Have a problem, this code generates duplicate responses when I run twice, and tripled responses when I run three times... why?
`const express = require('express'); const server = express(); server.use(express.json());
const porta = '1000'; const host = 'mypbx.pbx.com'; const login = 'pbx'; const password = 'pbx123';
server.use((req, res, next) => { console.time('Request'); console.log(Metodo: ${req.method}; URL: ${req.url}); next(); console.timeEnd('Request'); });
Metodo: ${req.method}; URL: ${req.url}
server.get('/clicktocall', (req, res) => { const { key,from, to, deal_id, person_id } = req.query;
const ami = new require('asterisk-manager')(porta,host,login,password, true); ami.keepConnected(); ami.on('managerevent', function (evt) { if (evt.event === 'OriginateResponse') { console.log(evt); } }); ami.action({ 'action':'originate', 'WaitTime':'300', 'channel':'SIP/9007', 'context':'default', 'exten':'45991086495', 'Callerid':'9007', 'priority':'1', 'timeout':'30000', 'Async':'true', }, function(err, res) { console.log('action callback: ', err, res); }); return res.json({ key: key, from: from, to: to, deal_id: deal_id, person_id: person_id});
});`
This is the response received: Metodo: GET; URL: /clicktocall?key=1476b041-321b-4b8e-b0bf-b5c79f3c5779&from=827247&to=045991086495&deal_id=524&person_id=489 Request: 15.032ms action callback: undefined { response: 'Success', actionid: '1567165899292', message: 'Originate successfully queued' } { event: 'OriginateResponse', privilege: 'call,all', actionid: '1567165899292', response: 'Success', channel: 'SIP/9007-00000e33', context: 'default', exten: '45991086495', reason: '4', uniqueid: '1567165899.3805', calleridnum: '9007', calleridname: '' } Metodo: GET; URL: /clicktocall?key=1476b041-321b-4b8e-b0bf-b5c79f3c5779&from=827247&to=045991086495&deal_id=524&person_id=489 Request: 1.156ms action callback: undefined { response: 'Success', actionid: '1567165914049', message: 'Originate successfully queued' } { event: 'OriginateResponse', privilege: 'call,all', actionid: '1567165914049', response: 'Success', channel: 'SIP/9007-00000e35', context: 'default', exten: '45991086495', reason: '4', uniqueid: '1567165914.3807', calleridnum: '9007', calleridname: '' } { event: 'OriginateResponse', privilege: 'call,all', actionid: '1567165914049', response: 'Success', channel: 'SIP/9007-00000e35', context: 'default', exten: '45991086495', reason: '4', uniqueid: '1567165914.3807', calleridnum: '9007', calleridname: '' }
i Have a problem, this code generates duplicate responses when I run twice, and tripled responses when I run three times... why?
`const express = require('express'); const server = express(); server.use(express.json());
const porta = '1000'; const host = 'mypbx.pbx.com'; const login = 'pbx'; const password = 'pbx123';
server.use((req, res, next) => { console.time('Request'); console.log(
Metodo: ${req.method}; URL: ${req.url}
); next(); console.timeEnd('Request'); });server.get('/clicktocall', (req, res) => { const { key,from, to, deal_id, person_id } = req.query;
});`
This is the response received: Metodo: GET; URL: /clicktocall?key=1476b041-321b-4b8e-b0bf-b5c79f3c5779&from=827247&to=045991086495&deal_id=524&person_id=489 Request: 15.032ms action callback: undefined { response: 'Success', actionid: '1567165899292', message: 'Originate successfully queued' } { event: 'OriginateResponse', privilege: 'call,all', actionid: '1567165899292', response: 'Success', channel: 'SIP/9007-00000e33', context: 'default', exten: '45991086495', reason: '4', uniqueid: '1567165899.3805', calleridnum: '9007', calleridname: '' }
Metodo: GET; URL: /clicktocall?key=1476b041-321b-4b8e-b0bf-b5c79f3c5779&from=827247&to=045991086495&deal_id=524&person_id=489
Request: 1.156ms
action callback: undefined { response: 'Success',
actionid: '1567165914049',
message: 'Originate successfully queued' }
{ event: 'OriginateResponse',
privilege: 'call,all',
actionid: '1567165914049',
response: 'Success',
channel: 'SIP/9007-00000e35',
context: 'default',
exten: '45991086495',
reason: '4',
uniqueid: '1567165914.3807',
calleridnum: '9007',
calleridname: '' }
{ event: 'OriginateResponse',
privilege: 'call,all',
actionid: '1567165914049',
response: 'Success',
channel: 'SIP/9007-00000e35',
context: 'default',
exten: '45991086495',
reason: '4',
uniqueid: '1567165914.3807',
calleridnum: '9007',
calleridname: '' }