Playing with numbers

Hi,
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

1234567890

to this:

2143658709

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

1234567

to this:

214365F7

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

${NUMBER:1:1}+${NUMBER:0:1}+${NUMBER:3:1}+${NUMBER:2:1}

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.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+Function_LEN
exten => s,n,GotoIf($[${LEN(${CALLERID(num)})}=10]?even:odd)

AGI:
https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=32375589
https://wiki.asterisk.org/wiki/display/AST/AGI+Commands

Another:

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:

[autoanswer]
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://127.0.0.1/uui05.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:

[custom-page-headers]
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

[custom-page-headers]
exten => s,1,Noop(Entering user defined context custom-page-headers in extensions_custom.conf)
exten => s,n,AGI(agi://127.0.0.1/uui05.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.