Need help with the dial plan

I have below statements in the dialplan:

exten => s,1,Background,welcome;
exten => s,2,agi,checkcid.agi //script to check if caller id exists
exten => s,3,Goto(planusers,${CALLERIDNUM},1);
exten => s,102,playback,goodbye

how can I modify exten => s,3,Goto(planusers,${CALLERIDNUM},1);

So if the context does not exist it will hang up.


to clarify, I dont want to use the hang up context.
I want to have some if or goto function that will go to specific context if the callerid context does not exist.


Once you have the AGI running set the caller ID to what ever the number + say *. In the next line have a gotoif that if the first character is a * to go to context else other wise go to the proper context. Another idea would be set in the agi a variable as to which context to go to (sort of the same as the first idea).

the agi script that calls the context looks like below:
it uses php

Else {
write (“SET CONTEXT planusers”);

write (“EXEC GoTO $out|1”);


$out is the caller id

depending on the caller id the context exist or not, how would the programing look like to go to the context if exist and go to different if does not,