Playing with numbers

I’m trying to convert my CID numbers for sending them in an additional header I created in extensions_custom.conf. They need to be changed from “normal” like


to this:


Every group of 2 digits has to switch positions. If the number of digits is odd, a F is added in penultimate place:


to this:


My first thought was, to count the length an then work with


and so on, but maybe there is a more elegant way of doing this?
Thank you very much!

That’s what I would do with a gotoif & LEN

Could you answer in a little more detail please?
How do I find out if LEN is odd?

This may be technically possible to do with dialplan, but will be tedious. I would do it with an AGI script.
exten => s,n,GotoIf($[${LEN(${CALLERID(num)})}=10]?even:odd)



exten => s,n,GotoIf(system(/bin/echo [[ $( ${LEN(${CALLERID(num)})} % 2 ) -eq 0 ]] && echo "even" || echo "odd")?even:odd)

Thank you very much for your advice. So far I have not dealt with AGI or PHP, this would be my first project.

So I set up an AGI to recreate my CID number, but ran into another problem:
Is there any chance to get a custom header with info of the dialed number into a pagegroup?
I managed to change [autoanswer] by coping it into extensions_override_freepbx.conf:

include => autoanswer-custom

exten => s,1,GosubIf($[“${ARG1}” != “”]?func-set-sipheader,s,1(Alert-Info,${ARG1}))
exten => s,n,GosubIf($[“${ARG2}” != “”]?func-set-sipheader,s,1(Call-Info,${ARG2}))
exten => s,n,AGI(agi://,${ARG3})
exten => s,n,NoOp(UUI:${UUI})
exten => s,n,GoSub(func-set-sipheader,s,1(X-UserToUser,${UUI};encoding=hex))
exten => s,n,GoSub(func-set-sipheader,s,1(X-Resource,${EXTEN}))
exten => s,n,Gosub(func-apply-sipheaders,s,1())
exten => s,n,Return()

;–== end of [autoanswer] ==–;

I thought this would be a good place, beause it deals already with headers, but there I cannot get the original called number by originator of the call.
Do you also have a little advice for this problem?

You can do this without modifying existing dialplan. Set it up as

Misc Application → Custom Destination (Return) → Page Group

For the custom Destination, write your own block of dialplan like:

exten => s,1,Noop(Entering user defined context custom-page-headers in extensions_custom.conf)
exten => s,n,DumpChan
exten => s,n,Return()

The DumpChan will give you a list of call details and defined variables at the asterisk console you can reference, one of them will be the dialed digits. Define the headers in this block with Gosub func-set-sipheader, but don’t run the func-apply-sipheaders, that will be done for you later in the call.

1 Like

Just to make shure I got it right:

Misc Application (Feature Code = number to dial) → Custom Destination (Destination custom-page-headers,s,1) (Return yes) → Page Group

exten => s,1,Noop(Entering user defined context custom-page-headers in extensions_custom.conf)
exten => s,n,AGI(agi://,${CallerIDNum})
exten => s,n,NoOp(UUI:${UUI})
exten => s,n,GoSub(func-set-sipheader,s,1(X-UserToUser,${UUI}\;encoding=hex))
exten => s,n,GoSub(func-set-sipheader,s,1(X-Resource,${CALLERID(dnid)}))
exten => s,n,Return()

unfortunately my headers are not added. Where is my mistake?

We would need to see a full call trace beginning to end. Share via pastebin.

I hope, this suits for you…

So now is when I admit that I’ve never attempted to add custom SIP headers to a paging call before. It appears that somewhere late in the call flow, the SIPHEADERS hash gets reset, probably to accommodate the auto answer feature. I think you’ll have to go back to your initial plan, but this time remove the gosub to func-set-sipheaders.

That’s all right. But it would have been a really nice solution using Custom Destination.

Do you mean removing Gosub from my override dialplan or from [custom-page-headers]?

Yes. The headers can be set wherever you want in the call flow, but the apply gosub only gets called once as part of the dial application at the very end.

I removed them and put them back to my override plan.
Thanks again until here.

One problem remains unsolved: the originally dialed number is missing in [autoanswer]…

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.