In an Asterisk $[]
expression, undefined variables do not return an implicit empty string or zero. They expand as "nothing" prior to evaluation of the expression, so after the variable is expanded (to nothing), it isn't visible to the expression parser. This causes the error already noted by Pablo Alsina:
GotoIf("IAX2/AtlantaTeliax-10086", "?CLOSED,1")
There are two ways to avoid this:
- Always give your variables reasonable defaults before you use them (as Pablo suggested).
- In any
$[]
expression, enclose your variables and literals with double-quotes. This will cause an undefined variable to be handled as an empty string, which can still be used for comparison purposes.
Personally, I try to do both. For example:
exten => START,n,Set(FORCE_CLOSED=FALSE)
exten => START,n,GotoIf($["${FORCE_CLOSED}"="TRUE"]?CLOSED,1)
Note the double-quotes around ${FORCE_CLOSED}
and the comparison value. Even if the variable is undefined, the expression will have ""
(an empty string) to compare against "TRUE"
.
Really, you can use any character you like, because it will just be tacked onto the variable expansion. It just gives you a literal value that is guaranteed to be there in case the variable is undefined. I like quotes because it makes the code resemble other programming languages. You could just as easily use something like $[x${FORCE_CLOSED}=xTRUE]
, which is commonly seen in Bourne shell scripting. The end result is the same.
Ok I finally fixed it thanks to Skype Tech support and an Asterisk Ninja :)
This is what must be in sip.conf in order for Skype connect to work:
register => SKYPE_CONNECT_ID:SKYPE_CONNECT_PASS@sip.skype.com/SKYPE_CONNECT_ID
That Register line MUST be near the begining of the file, where the "register =>" examples are.
Skype Trunk details (near the end of sip.conf or at the end):
[skype]
type=friend
context=from-skype
username=SKYPE_CONNECT_ID
secret=SKYPE_CONNECT_PASS
canreinvite=no
insecure=port,invite
dtmfmode=rfc2833
host=sip.skype.com
nat=no
qualify=yes
fromuser=SKYPE_CONNECT_ID
fromdomain=sip.skype.com
disallow=all
allow=g729
allow=ulaw
allow=alaw
Note: If you are using Asterisk-gui, you can do all of this through the gui.
When setting up the SIP trunk, you need to go back and edit it, because edit reveals more options for you to put in.
Fill out:
Hostname: sip.skype.com
Username: SKYPE_CONNECT_ID
Password: SKYPE_CONNECT_PASSWORD
Codecs: G729, Ulaw, Alaw
Fromdomain: sip.skype.com
Fromuser: SKYPE_CONNECT_ID
There is one more hidden option that you must set in order for INCOMING call
Options/Advanced/Show hidden options
With this setup, outgoing calls should work. Remeber to make the outgoing rule so that you get an international number out. My example in asterisk-gui.
US office calls only US numbers.
Outgoing rule: _XXXXXXXXXX
Prepend: +
Same thing with bare-bones asterisk: (extensions.conf)
exten => _X.,n,Dial(SIP/skype/+1${EXTEN},90)
In the example above, there is a skype trunk defined in sip.conf
After this. Everything worked fine. Now I seem to have some other problems :)
Best Answer
I've done something similar and like the other submitter, I used a database. Instead of using the built int DB functionality, I used cmd MySQL. This was so I could write a web page that interacts with the same DB AND my DBA could do cross DB selects between this "Directory" table and the MySQL CDR.
In my example, I setup a table with 4 fields.
id
(auto_increment int),number
(the phone number),name
(The name of user),ban
(an int that defaults to 0). The example does 2 things, 1- it looks up name from the DB and sets that as the caller id (Since our POTS line doesn't communicate that) 2- It looks up to see ifban
is set to 1, and blocks the call.After this you'd have your [mainmenu] and [wedontlikeyou]. The later is your ban, it could be a simple hangup, error message, what ever you want. My preference is Congestion() since that tends to make people think the phone number is out of service.