F
F
foxhole2016-03-29 16:45:34
Asterisk
foxhole, 2016-03-29 16:45:34

How to get channel variable in agi hangup event?

There is Asterisk, an AGI server on Node js and the asterisk-io library. Cannot get channel variable DIALSTATUS in body of hangup event. The library is synchronous, but the main file that interacts with it has been rewritten using Promise into asynchronous code.
Below is an asynchronous call to the Asterisk command:

agiHandler.asyncExec=function (_cmd,_params) {
        return new Promise(function(resolve, reject) {
            _cmd='exec "'+_cmd+'"'+(_params!=undefined?' "'+_params+'"':'');
            agiHandler.doLog(L_INFO,'asyncExec() -> start -> '+_cmd);
            agiHandler.command(_cmd,function(code,result,value) {
                var res={code:code,result:result,value:value};
                agiHandler.doLog(L_INFO,'asyncExec() ->   end -> '+_cmd+' -> result -> '+JSON.stringify(res));
                resolve(res);
            });
        });
    };

It is necessary that a variable be pulled out in the body of the hangup event:
agiHandler.on('hangup', function(){

    new Promise(function(resolve, reject){
        agiHandler.doLog(L_INFO,'hangup event');
        console.log();


        //============================================ get vars 

        //console.log("========================== handler command: ",_cmd)

        agiHandler.asyncExec('get variable', 'DIALSTATUS').then(function(res){
            console.log("========================== getting var in ast-io hangup event: ", res);
            resolve(res);
        })
        
        //============================================ end get
    });

The code inside the call to the get variable command does not work, but if you insert a call to the command that receives the channel variable into the body of the asynchronous function, then the code works.
How to avoid redundant code in the general purpose asyncExec function and force the variable to be grabbed in the hangup event?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
foxhole, 2016-03-31
@foxhole

The best solution to this issue was a return to synchronous code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question