Execute a script when SIP extension answers a call?

Get help with installing, upgrading and running Asterisk.

Moderators: muppetmaster, Moderator, Support

Execute a script when SIP extension answers a call?

Postby monotek » Wed Sep 09, 2009 2:24 am

Hi.

Im running Asterisk 1.4 and FreePBX 2.5 on a Ubuntu Server.

I want that asterisk executes a perl or php script, when an incoming call is answered by one of my sip devices.

The script should get the caller phone number, the called number and the extension number which takes the call via variables.

This is what i tried until now. Of cause this is not the final script. I only want to use /bin/echo to test functionality:

Code: Select all
[from-internal-custom]
exten => _X.,1,Answer()
exten => _X.,n,Dial(SIP/${EXTEN}||M(test^${CALLERID(num)^${EXTEN}^${CHANNEL}))
exten => _X.,n,Hangup()

[macro-test]
exten => s,1,NoOp(Macro test)
exten => s,n,System(/bin/echo "caller=${ARG1} exten=${ARG2} called=${ARG3}" >> /tmp/test)


Unfortunately it does not work. If i make a call its automaticly canceled.
There is no new file created in /tmp.

This is my log:

Code: Select all
-- Executing [2003@from-internal:1] Answer("SIP/2000-082fd8b8", "") in new stack
-- Executing [2003@from-internal:2] Dial("SIP/2000-082fd8b8", "SIP/2003||M(test^2000") in new stack
== Spawn extension (from-internal, 2003, 2) exited non-zero on 'SIP/2000-082fd8b8'
-- Executing [h@from-internal:1] Macro("SIP/2000-082fd8b8", "hangupcall") in new stack
-- Executing [s@macro-hangupcall:1] GotoIf("SIP/2000-082fd8b8", "1?skiprg") in new stack
-- Goto (macro-hangupcall,s,4)
-- Executing [s@macro-hangupcall:4] GotoIf("SIP/2000-082fd8b8", "1?skipblkvm") in new stack
-- Goto (macro-hangupcall,s,7)
-- Executing [s@macro-hangupcall:7] GotoIf("SIP/2000-082fd8b8", "1?theend") in new stack
-- Goto (macro-hangupcall,s,9)
-- Executing [s@macro-hangupcall:9] Hangup("SIP/2000-082fd8b8", "") in new stack
== Spawn extension (macro-hangupcall, s, 9) exited non-zero on 'SIP/2000-082fd8b8' in macro 'hangupcall'
== Spawn extension (macro-hangupcall, s, 9) exited non-zero on 'SIP/2000-082fd8b8'


What is wrong?

Thanks in advance.

Greetz
André
monotek
Newsterisk
 
Posts: 14
Joined: Wed Sep 09, 2009 2:11 am

Postby Dovid » Wed Sep 09, 2009 6:12 am

Anything in /var/log/asterisk/full ? Can it be a permissions issue ?
Dovid
Salt of the Asterisk
 
Posts: 1452
Joined: Sun Oct 23, 2005 5:28 am
Location: Lakewood, NJ, USA

Postby monotek » Wed Sep 09, 2009 6:26 am

Thanks for the hint.

"app.c: Missing closing parenthesis for argument 'M' in string... "

Now it works :-)
monotek
Newsterisk
 
Posts: 14
Joined: Wed Sep 09, 2009 2:11 am

Postby monotek » Wed Sep 09, 2009 7:53 am

I have a new problem now.

To get it work for external calls i had to change the context. Thats how it looks now.

Code: Select all
[from-pstn-custom]
exten => _XXXX.,1,Answer()
exten => _XXXX.,n,Dial(SIP/${EXTEN}||M(test^${CALLERID(num)}^${EXTEN}^${CHANNEL}))
exten => _XXXX.,n,Hangup()

[macro-test]
exten => s,1,NoOp(Macro TEST)
exten => s,n,System(/bin/echo "caller=${ARG1} exten=${ARG2} called=${ARG3}" >> /tmp/test)


Unfortunately SIP/${EXTEN} becomes now SIP/03514123456 and not SIP/2003 like before.

But i need the number of the sip device which answers the call.

How can i reach this?
monotek
Newsterisk
 
Posts: 14
Joined: Wed Sep 09, 2009 2:11 am

Postby Dovid » Wed Sep 09, 2009 11:29 am

That is something that you have to decide. In place of ${EXTEN} you need to decide which sip account it should call.
Dovid
Salt of the Asterisk
 
Posts: 1452
Joined: Sun Oct 23, 2005 5:28 am
Location: Lakewood, NJ, USA

Postby monotek » Thu Sep 10, 2009 2:01 am

But this decission should be done by my ring group.

No way to get this solved?

Can i set ${Exten} to be the answering device somehow?

Even better i could replace SIP/${EXTEN} with my TimeCondition which is configured in FreePBX...
monotek
Newsterisk
 
Posts: 14
Joined: Wed Sep 09, 2009 2:11 am

Postby Dovid » Thu Sep 10, 2009 1:02 pm

You can replace it with what ever you want. All SIP/${EXTEN} says is to call SIP device X. X Is the extension that the call went to.
Dovid
Salt of the Asterisk
 
Posts: 1452
Joined: Sun Oct 23, 2005 5:28 am
Location: Lakewood, NJ, USA

Postby monotek » Fri Sep 11, 2009 2:04 am

I know.

My Problem is, that the extension is the phoned number.

What i need as variable is the number of the sip device (e.g. my ata286 which as 2003) which answers the call.

I need to replace ${Exten} with this devices number.
monotek
Newsterisk
 
Posts: 14
Joined: Wed Sep 09, 2009 2:11 am

Postby Dovid » Thu Oct 08, 2009 3:08 am

I don't understand the issue. Just put in what you want to call.
Dovid
Salt of the Asterisk
 
Posts: 1452
Joined: Sun Oct 23, 2005 5:28 am
Location: Lakewood, NJ, USA


Return to Asterisk Support

Who is online

Users browsing this forum: MSN [Bot] and 1 guest