简体   繁体   中英

How to get Answered number / answered CLID in case of simultaneous calls forwarding in Asterisk?

I have a problem, already 20 hours on the topic, but can't solve it. The case that I can't bill the call because I can't get an exact CLID of an answered number in case of simultaneous call forwarding in Asterisk. ${CDR(src)}, ${CDR(dst)} do not help here.

I call from PSTN +79000000000 to DID +78120000000 and call is landed to our Asterisk. On asterisk, via the same trunk the call is being forwarded to another PSTN +74950000000 and answered there. On call completion in CDR we can see:

src: 79000000000
dst: 78120000000

and no info about the last 78120000000 -> 74950000000 call

I can use CDR variable to store 74950000000 in before calling Dial application:

Set(CDR(fwd)=74950000000);
Dial(SIP/78120000000/74950000000);

then in CDR on call completion we can see:

src: 79000000000
dst: 78120000000
fwd: 74950000000

and that's okay, because I can limit max call duration before Dial and bill the call after Hangup. All thanks to known fwd.

sip.conf

[78120000000]
name=78120000000
type=peer
host=sip.provider.com

extensions.ael

context sequential {
   _.=> {
       Set(CDR(fwd)=74950000000);
       Dial(SIP/78120000000/74950000000);
       Hangup();
    }
    h => {
       Set(BILL_THE_CALL=${ODBC_BILL_THE_CALL()});
       // billing is easily executed thanks to logged fwd in CDR
    }
  }

But in case of simultaneous call forwarding this is impossible:

  context simultaneous {
   _.=> {
       // can't set fwd before call completion, because don't know 
       // if my_cell_phone or softphone will answer
       // my_cell_phone costs 5 cents/min, softfone is free of charge
       Dial(SIP/78120000000/74950000000&SIP/softphone);
       Hangup();
   }
   h => {
       Set(BILL_THE_CALL=${ODBC_BILL_THE_CALL()});
       // billing is impossible because fwd is not logged to CDR
   }
 }

On call completion in CDR we can see the same, as for sequential case, without fwd:

src: 79000000000
dst: 78120000000

and no info about the last 78120000000 -> 74950000000 or to softphone

So, do you know any way to get that Answered username, answered number, answered CLID, whatsoever in order to be able to bill the call?

http://www.voip-info.org/wiki/view/Asterisk+variables

http://www.voip-info.org/wiki/view/Asterisk+func+channel

etc. links contain nothing helpful for me.

On the call I can also apply

sip show channel faf7767642

and see channel Username, Origination uri, etc that contain my fwd number, but I can't get them from there with dialplan. But when I call:

NoOp(${CHANNEL(username)});

it just shows nothing. Have any ideas? Can't believe I missed something obvious. Thank you!

Yes, it worked thanks to M(x) execution during Dial() command with Set(GLOBAL(var)=${CHANNEL(peername)}) inside that macro-x context.

context macro-give-me-answered-clid {
    _. => {
        Set(GLOBAL(simultaneous_call_answered_peer)=${CHANNEL(peername)});
    }
}

context simultaneous {
   _.=> {
     // can't set fwd before call completion, because don't know 
     // if my_cell_phone or softphone will answer
     // my_cell_phone costs 5 cents/min, softfone is free of charge
     Dial(SIP/78120000000/74950000000&SIP/softphone,,M(give-me-answered-clid));
     Hangup();
   }

   h => {
     Set(CDR(fwd)=${simultaneous_call_answered_peer})
     Set(BILL_THE_CALL=${ODBC_BILL_THE_CALL()});
     // billing is ok because fwd is now logged to CDR
   }
} 

Maybe not nice, maybe yet stupid, but works and I am happy with that for now. Thank you so much for your help, artheops!

As to developing complex solutions without expert skills, that's a perfect Guy Ritchie's answer on that:

The only way to get smarter is by playing smarter opponent.

(c) Revolver, 2005. That's THE ONLY way to get expert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM