Search code examples
asteriskbookmarks

Bookmarking feature in a dialplan


I am writing a dialplan in Asterisk where I am required to implement a bookmarking feature. If a user calls in and the call gets disconnected, on redial the user must be taken to the exact same clip on which the call was dropped or disconnected last. The dialplan (with bookmarking feature) currently looks something like so:

[some-context]
exten => 0,n,System(progressmarker.sh ${CALLERID(num)} ${CONTEXT})
exten => 0,1,Background(wav1)
exten => 0,n,Background(wav2)

There are hundreds of such commands. progressmarker takes the context and puts it into a file. When the user wants to continue the old session, it starts from the last context the user was in. If the call gets dropped after wav1 or wav2, the user should start from wav1 or wav2 and not from the last context.

There is one way of doing this:

exten => 0,n(wav1),Background(wav1)&System(progressmarker.sh ${CALLERID(num)} ${CONTEXT} wav1)  

But you can see this way is inelegant and cumbersome especially since there are hundreds of such commands. Is there a better way of implementing the bookmarking feature?


Solution

  • One way to do this is to employ the h extension. This is the extension that gets called when the channel encounters a hangup. The solution would look like so:

    1. Keep saving the priority in a global variable.
    2. Implement the hangup extension for each context. The channel variables such as last context, extension and priority are all accessible (contrary to what the documentation says). The extension will look something like so:

    exten => h,1,System(<Execute a script here that saves the last context, extension and priority to a file that can be read later and control returned here.>)