Closed ednt closed 5 years ago
sendEvent takes an Event object, not a string.
Hi, thanks for your response, but ...
we run still into problems. First it is not easy to build an object with a dash inside the key. We tried now
data["Event-Name"] = "NOTIFY";
Second we still get the error event.getHeader is not a function
We would really appreciate it, if you can show us a working example.
First it is not easy to build an object with a dash inside the key.
Sure it is, JS supports it natively.
Second we still get the error event.getHeader is not a function
Probably because you aren't creating an Event object.
Example:
const eventCommand = new esl.Event({
'Event-Name': 'NOTIFY',
'profile': 'internal',
'event-string': 'check-sync;reboot=false',
'user': extNumber.
'host': domainName,
});
freeSwitchConn.sendEvent(eventCommand, (res) => {
if(res.body.substr(0,1) === "+")
callback(true);
else
callback(false);
});
Thank you for your help!
The full working example:
const eventCommand = new esl.Event({
"Event-Name": "NOTIFY",
"profile": "internal",
"event-string": "check-sync;reboot=false",
"content-type": "application/simple-message-summary",
"user": ext_number,
"host": tokenData.domainName
});
const resyncExt = (eventCommand, callback) => {
let success = false;
freeSwitchConn.sendEvent(eventCommand, (res) => {
for(let obj of res.headers){
if(obj.name === "Reply-Text")
if(obj.value.substr(0,1) === "+"){
success = true;
break;
}
}
if(success)
callback(true);
else
callback(false);
});
};
You can use getHeader("Reply-Text")
instead of looping through all headers. In v2, getHeaders is faster than looping as well.
Hi,
we use V1.2.1. and get: [error]: event.getHeader is not a function when we try to use
We found no example how to use it. So the above is only a guess. Can you tell us how to use it right?
Best regards