I'm not touching Asterisk SIP-related things a lot, but when I do, it can be frustrating from time to time. Or maybe I don't know the "correct way" of doing things.
Task is simple - after invoking Dial() get something more granular than ${DIALSTATUS}. Especially in a case of failed call.
But we also have a ${HANGUPCAUSE} variable here. And turns out, it integer value is coming directly from SIP responce, Reason header. Which we can modify on Kamailio.
So, if we have an answer something like
SIP/2.0 604 Does not exist anywhere
...
from upstream, we can add/modify custom reason with something like:
kamailio.conf
onreply_route{
...
if ($rs == 604) {
remove_hf("Reason");
append_hf("Reason: Q.850;cause=3;text=\"No route to destination\"\n");
}
}
And in Asterisk we will have 3 in a ${HANGUPCAUSE} after Dial(). Point, there is a limitation on possible numbers here.
Other option to get it purely on Asterisk could be using ${HANGUPCAUSE(chan,tech)} function, but this required knowing of an outgoing channel name. Which we can also get in a parent channel via Pre-Dial Handler (see example here) and passing this name via AstDB for example using parent ${CHANNEL} as a key, as I'm not sure we can propagate variable up to stack.
As an example:
extensions.conf
...
same => n,Set(__PARENT_CHANNEL=${CHANNEL})
same => n,Dial(PJSIP/${EXTEN}@${TRUNK},,b(save_child_channel^s^1))
same => n,Set(CHILD_CHANNEL=${DB_DELETE(chan_save/${CHANNEL})})
same => n,NoOp(SIP Reply: ${HANGUPCAUSE(${CHILD_CHANNEL},tech)}
[save_child_channel]
exten => s,1,Set(DB(chan_save/${PARENT_CHANNEL})=${CHANNEL})
same => n,Return()
A bit overcomplicated as for me, but maybe I miss some "built-in function".
No comments:
Post a Comment