AstTapi

Trying a new install os AstTapi

Anyone know how or where I could add these changes to freepbx

[quote]uses the event LINE_CALLSTATE LINECALLSTATE_IDLE to remove this call from its list of calls to track. If you do not enter this into the dial plan, then not only is your application not going to now when the line is idle again, but also you will have a slow memory leak in the TSP as it will not know when to free memory allocated to a call initiated earlier.

A word about LINE_CALLSTATE LINECALLSTATE_CONNECTED

This event tells the TAPI application that the call is connected. But from a dial plan point of view is quite tricky to get in a place when the call is truly connected. We also have to manage calls which are one to many, that is 1 call comes in and 2 phones ring. For example we may have in our dial plan

exten => 100,1,dial(sip/bob&sip/bobbett)

First off we handle sending the LINECALLSTATE_CONNECTED event in this fashion:

exten => 100,1,dial(sip/bob&sip/bobbett||M(tapi^${UNIQUEID}))

We have to pass the unique ID across to the macro which is called when the call is connected, as the macro is run as the second leg of the call which has a new unique id.

[macro-tapi]

exten => s,1,UserEvent(TAPI|TAPIEVENT: [~${ARG1}&sip/bob] LINE_CALLSTATE LINECALLSTATE_CONNECTED)

exten => s,1,UserEvent(TAPI|TAPIEVENT: [~${ARG1}&!sip/bob] LINE_CALLSTATE LINECALLSTATE_HANGUP)

You will note a few things here:

Our TAPI events are sent by way of a specially formatted UserEvent
We can simply send the TAPI command, and AstTapi will track the call for you
Or we can signal AstTapi which call it is referring to
We can also describe which line we intend the call for if the call is being tracked by a number of lines.

After the TAPI|TAPIEVENT string we can optionally place a [] which the contents take on the format:

If the character ‘~’ is used the string following it is the Asterisk unique ID we intend the signal for (by default AstTapi traces the Asterisk unique ID generated when the NEWCALL is signalled).

Any string which is a line identifier means that this TAPI event is specifically for that line.

Any string proceeded by a ‘!’ means that this event is specifically excluded for that line (and by default intended for all others if a line is not specified – see the previous comment).

We can have multiple definitions here which are separated by the ‘&’ character.

Putting it all together

For inbound calls we will extend the standard extension macro to include our TAPI events

[code:1][macro-tapi]
exten => s,1,UserEvent(TAPI|TAPIEVENT [~${ARG1}&sip/bob] LINE_CALLSTATE LINECALLSTATE_CONNECTED)
exten => s,1,UserEvent(TAPI|TAPIEVENT [~${ARG1}&!sip/bob] LINE_CALLSTATE LINECALLSTATE_HANGUP)

[macro-stdexten]
;Our TAPI events
exten => s,1,UserEvent(TAPI|TAPIEVENT: LINE_NEWCALL ${ARG3})
exten => s,n,UserEvent(TAPI|TAPIEVENT: LINE_CALLSTATE LINECALLSTATE_OFFERING)
exten => s,n,UserEvent(TAPI|TAPIEVENT: SET CALLERID ${CALLERID})
exten => s,n,UserEvent(TAPI|TAPIEVENT: LINE_CALLINFO LINECALLINFOSTATE_CALLERID)
;The normal macro
exten => s,n,Dial(${ARG1},20,TM(tapi^${UNIQUEID}))
exten => s,2,Goto(s-${DIALSTATUS},1) ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)
exten => s-NOANSWER,1,Voicemail(u${ARG1}) ; If unavailable, send to voicemail w/ unavail announce
exten => s-NOANSWER,2,Goto(default,s,1) ; If they press #, return to start
exten => s-BUSY,1,Voicemail(b${ARG1}) ; If busy, send to voicemail w/ busy announce
exten => s-BUSY,2,Goto(default,s,1) ; If they press #, return to start
exten => _s-.,1,Goto(s-NOANSWER,1) ; Treat anything else as no answer
exten => a,1,VoicemailMain(${ARG1}) ; If they press *, send the user into VoicemailMain[/code:1]
We also have to remember to have the ‘h’ extension in the context the call came in on:

[code:1]exten => h,1,UserEvent(TAPI|TAPIEVENT: LINE_CALLSTATE LINECALLSTATE_IDLE)[/code:1]
We also have to remember that Outlook and other diallers expect to see events to know about the progress of the call they have requested. Here we have to modify the way outgoing calls are made:

[code:1][trunklocal]
;
; Local seven digit dialling accessed through the trunk interface
;
exten => _9NXXXXXX,1,UserEvent(TAPI|TAPIEVENT: LINE_NEWCALL line_1)
exten => _9NXXXXXX,n,UserEvent(TAPI|TAPIEVENT: LINE_CALLSTATE LINECALLSTATE_DIALTONE)
exten => _9NXXXXXX,n,UserEvent(TAPI|TAPIEVENT: LINE_CALLSTATE LINECALLSTATE_DIALING)
exten => _9NXXXXXX,n,UserEvent(TAPI|TAPIEVENT: LINE_CALLSTATE LINECALLSTATE_PROCEEDING)
exten => _9NXXXXXX,1,Dial(${TRUNK}/${EXTEN:${TRUNKMSD}}||M(tapi^${UNIQUEID}))[/code:1]
Notes:

Because the TSP filters the LINE_NEWCALL event, this means this can be used in the situation where either the TAPI application initiates the call, or if it is a call which is initiated by the actual phone
Remember this must also pick up on the ‘h’ extension to signal when the call is idle again
[/quote]