How to make a callback system?

Hi,

I am trying to put a dialplan together that would check if the caller id of an incoming call matches 5551234 or 5554321. If it does, then hangup, call it back and provide it with a dialtone, otherwise just hangup.

The purpose of this is to be able to call internationally on my mobile using my voip account without using up my outgoing minutes on my mobile.

I’m guessing I have to use something else along with the dialplan but I’m afraid I don’t know enough about Asterisk to work it out and the following doesn’t work:

[code][macro-ParseIncoming]
exten => s,1,GotoIf($[$[${CALLERID(number)} = “5551234”]|$[${CALLERID(number)} = “5554321”]?callback:isplcid)
same => n(callback),Hangup()
same => n,Dial(${CALLERID(number)@myprovider)
same => n,Wait(1)
same => n,agi(googletts.agi,“Asterisk calling back”,en)
same => n(isplcid),Verbose(“ISPLCID”)
same => Hangup()

[incoming]
exten => 5145556789,1,Macro(ParseIncoming)
[/code]

"'s are included in string comparisons. Your GotiIf will always take the false path.

You shouldn’t nest $[].

Ok, I modified as follows.

sip.conf

[general]

register => user:pass@montreal.voip.ms

context = unauthenticated
allowguest = yes
allowoverlap = no
udpbindaddr = 0.0.0.0
tcpenable = no
transport = udp
srvlookup = yes
defaultexpiry = 120
disallow = all
allow = ulaw
allow = alaw
;allow = gsm
language = en
useragent = Asterisk PBX
registerattempts = 50
sdpsession = Asterisk PBX
ignoreregexpire = no

[voipms]
type = friend
user = user
host = montreal.voip.ms
fromuser = user
fromdomain = montreal.voip.ms
secret = pass
insecure = invite
disallow = all
allow = ulaw
allow = alaw
context = incoming
trustrpid = yes
sendrpid = yes
nat = comedia

extensions.conf

[general]
static = yes
writeprotect = yes
clearglobalvars = no

; default context
[unauthenticated]
exten => s,1,Answer()
    same => n,AGI(googletts.agi,"Unauthenticated user, hanging up.",en)
    same => n,Hangup()

[macro-ParseIncoming]
exten => s,1,GotoIf($[${CALLERID(number)} = 55512345]?callback:isplcid)
    same => n(callback),Verbose(CID=${CALLERID(number)})
    same => n,Set(CallBackNumber=${CALLERID(number)})
    same => n,system(echo -e "Channel: SIP/voipms/${CallBackNumber}\\nMaxRetries: 2\\nRetryTime: 10\\nWaitTime: 20\\nConte
xt: callback\\nExtension: CallbackExt\\nPriority: 1" > /tmp/callback.call)
    same => n,System(chmod 755 /tmp/callback.call)
    same => n,System(mv /tmp/callback.call /var/spool/asterisk/outgoing)
    same => n,Hangup(16)

    same => n(isplcid),Verbose("ISPLCID")
    same => Hangup()

[incoming]
exten => 5556789,1,Macro(ParseIncoming)

[callback]
exten => CallbackExt,1,Answer()
    same => n,AGI(googletts.agi,"Asterisk calling back",en)

Now here is what happens in Asterisk’s console when I call my DID 5556789 from my cellphone 5551234:

    -- Executing [5556789@incoming:1] Macro("SIP/voipms-00000000", "ParseIncoming") in new stack
    -- Executing [s@macro-ParseIncoming:1] GotoIf("SIP/voipms-00000000", "1?callback:isplcid") in new stack
    -- Goto (macro-ParseIncoming,s,2)
    -- Executing [s@macro-ParseIncoming:2] Verbose("SIP/voipms-00000000", "CID=5551234") in new stack
CID=5551234
    -- Executing [s@macro-ParseIncoming:3] Set("SIP/voipms-00000000", "CallBackNumber=5551234") in new stack
    -- Executing [s@macro-ParseIncoming:4] System("SIP/voipms-00000000", "echo -e "Channel: SIP/voipms/5551234\\nMaxRetries: 2\\nRetryTime: 10\\nWaitTime: 20\\nContext: callback\\nExtension: CallbackExt\\nPriority: 1" > /tmp/callback.call") in new stack
    -- Executing [s@macro-ParseIncoming:5] System("SIP/voipms-00000000", "chmod 755 /tmp/callback.call") in new stack
    -- Executing [s@macro-ParseIncoming:6] System("SIP/voipms-00000000", "mv /tmp/callback.call /var/spool/asterisk/outgoing") in new stack
    -- Attempting call on SIP/voipms/5551234 for CallbackExt@callback:1 (Retry 1)
  == Using SIP RTP CoS mark 5
    -- Executing [s@macro-ParseIncoming:7] Hangup("SIP/voipms-00000000", "16") in new stack
  == Spawn extension (macro-ParseIncoming, s, 7) exited non-zero on 'SIP/voipms-00000000' in macro 'ParseIncoming'
  == Spawn extension (incoming, 5556789, 1) exited non-zero on 'SIP/voipms-00000000'
[Dec 29 12:53:08] NOTICE[24614][C-00000001]: chan_sip.c:22629 handle_response_invite: Failed to authenticate on INVITE to '"asterisk" <sip:user@montreal.voip.ms>;tag=as157f2ef7'
       > Channel SIP/voipms-00000001 was never answered.
[Dec 29 12:53:08] NOTICE[24637]: pbx_spool.c:389 attempt_thread: Call failed to go through, reason (8) Congestion (circuits busy)
    -- Attempting call on SIP/voipms/5551234 for CallbackExt@callback:1 (Retry 2)
  == Using SIP RTP CoS mark 5
[Dec 29 12:53:18] NOTICE[24614][C-00000002]: chan_sip.c:22629 handle_response_invite: Failed to authenticate on INVITE to '"asterisk" <sip:user@montreal.voip.ms>;tag=as3e745b7f'
       > Channel SIP/voipms-00000002 was never answered.
[Dec 29 12:53:18] NOTICE[24638]: pbx_spool.c:389 attempt_thread: Call failed to go through, reason (8) Congestion (circuits busy)
    -- Attempting call on SIP/voipms/5551234 for CallbackExt@callback:1 (Retry 3)
  == Using SIP RTP CoS mark 5
[Dec 29 12:53:28] NOTICE[24614][C-00000003]: chan_sip.c:22629 handle_response_invite: Failed to authenticate on INVITE to '"asterisk" <sip:user@montreal.voip.ms>;tag=as1660e46f'
       > Channel SIP/voipms-00000003 was never answered.
[Dec 29 12:53:28] NOTICE[24639]: pbx_spool.c:389 attempt_thread: Call failed to go through, reason (8) Congestion (circuits busy)
[Dec 29 12:53:28] NOTICE[24639]: pbx_spool.c:392 attempt_thread: Queued call to SIP/voipms/5551234 expired without completion after 2 attempts

I can’t understand why it is failing to authenticate user@montreal.voip.ms.
I tried with type = peer and type = friend, I tried with insecure = invite or insecure = no and while the errors will vary, it will never place the call.

I’m at my wits end. Any pointer appreciated.

Neither insecure, nor the peer/friend distinction have any effect on outgoing calls.

Can you make simple outgoing calls?

Please note that allowguest = yes is a serious security liability.

Thanks, I removed allowguest = yes

I cannot make a simple call, this is what I am getting:

[Dec 29 17:58:50] NOTICE[24614][C-0000000b]: chan_sip.c:22629 handle_response_invite: Failed to authenticate on INVITE to '"softphone" <sip:user@montreal.voip.ms>;tag=as0f94c6b2'
    -- SIP/voipms-0000000e is circuit-busy
  == Everyone is busy/congested at this time (1:0/1/0)
    -- Auto fallthrough, channel 'SIP/user1-0000000d' status is 'CONGESTION'

I added this to sip.conf to create user1 for the softphone

[user1]
type = friend
context = LocalSets
host = dynamic
nat = comedia
secret = password

The required configuration will depend on your ITSP. Any good ITSP will have standard configurations for Asterisk, although, unfortunately, some of those are out of date and they are usually less secure than they need to be.

ugggggh I put

rather than

So frustrating, a day lost on this… Well that solves my issue anyway