Working Toggle Pause Button With BLF

Discussion in 'General' started by shaks, Feb 24, 2011.

  1. shaks

    Joined:
    Feb 13, 2011
    Messages:
    29
    Likes Received:
    0
    Hi Guys

    I'm abit of a newbie to asterisk/pbx's. I've been working with them for just over a week now. In this time I've been lurking around lots of forums for tips and tricks and feel I need to feed put something back which may help others.

    I've created a dialplan for an feature code to pause or unpause a user in a queue.

    I looked everywhere for this but most of the solutions didn't a. have BLF or b, needed a seperate code to unpause a member of all queues.

    The code does the following:
    *450XXX (XXX=extension) - pauses or unpauses the specified member in all queues.
    *450 - requests for input of a member to be paused/unpaused then carries out this action.
    *460 - pauses/unpauses the calling member.

    Both *450 codes can be used in conjunction with DISA so logouts can be performed externally.

    Let me know if I need to make any improvements. Testing so far has identified no issues with working BLF (only tested on X-Lite, will test on Cisco SPA504g/SPA942 from tomorrow)

    I do think something like this should be integrated with FreePBX. I originally planned to use login/logout but as this doesn't do all the queues in one go (unless specified in the dialplan) I went with PauseQueueMember instead.

    If you change the feature codes to 2 digits instead of 3 then you will need to change EXTEN:4 to EXTEN:3.
    Also you will need to change the lines under the [ext-pause-hints] section to match your extensions. I am using extensions 200-216 (some are spare though).


    My Code:
    -------

    [from-internal-additional-custom]
    include => ext-pause-hints
    include => app-pause
    include => app-pause-current

    ; end of [from-internal-additional-custom]

    [ext-pause-hints]
    exten => *450200,hint,Custom:pAUSE200
    exten => *450201,hint,Custom:pAUSE201
    exten => *450202,hint,Custom:pAUSE202
    exten => *450203,hint,Custom:pAUSE203
    exten => *450204,hint,Custom:pAUSE204
    exten => *450205,hint,Custom:pAUSE205
    exten => *450206,hint,Custom:pAUSE206
    exten => *450207,hint,Custom:pAUSE207
    exten => *450208,hint,Custom:pAUSE208
    exten => *450209,hint,Custom:pAUSE209
    exten => *450210,hint,Custom:pAUSE210
    exten => *450211,hint,Custom:pAUSE211
    exten => *450212,hint,Custom:pAUSE212
    exten => *450213,hint,Custom:pAUSE213
    exten => *450214,hint,Custom:pAUSE214
    exten => *450215,hint,Custom:pAUSE215
    exten => *450216,hint,Custom:pAUSE216

    ; end of [ext-pause-hints]

    [app-pause]
    exten => *450,1,Answer
    exten => *450,n,Wait(1)
    exten => *450,n,Macro(user-callerid,SKIPTTL,)
    exten => *450,n,Read(uext,please-enter-your&extension&then-press-pound,,,,)
    exten => *450,n,Set(uext=${IF($["foo${uext}"="foo"]?${AMPUSER}:${uext})})
    exten => *450,n,Wait(1)
    exten => *450,n,Goto(app-pause-toggle,s,1)
    exten => _*450.,1,Answer
    exten => _*450.,n,Wait(1)
    exten => _*450.,n,Set(uext=${EXTEN:4})
    exten => _*450.,n,Noop(STATUS ON EXTENSION: ${EXTEN:4})
    exten => _*450.,n,Goto(app-pause-toggle,s,1)

    ;end of [app-pause]

    [app-pause-current]
    exten => *460,1,Answer
    exten => *460,n,Wait(1)
    exten => *460,n,Macro(user-callerid,SKIPTTL,)
    exten => *460,n,Set(uext=${AMPUSER})
    exten => *460,n,Goto(app-pause-toggle,s,1)

    ;end of [app-pause-current]

    [app-pause-toggle]
    exten => s,1,Gotoif($["${DB(AMPUSER/${uext}/pauses)}" = "1"]?unpause)
    exten => s,n,PauseQueueMember(,Local/${uext}@from-queue/n)
    exten => s,n,Set(DB(AMPUSER/${uext}/pauses)=1)
    exten => s,n,Set(STATE=BUSY)
    exten => s,n,UserEvent(RefreshQueue)
    exten => s,n,Gosub(app-pause-toggle,sstate,1)
    exten => s,n,Wait(1)
    exten => s,n,Playback(extension)
    exten => s,n,SayDigits(${uext})
    exten => s,n,Playback(dictate/paused)
    exten => s,n,Wait(1)
    exten => s,n,Hangup
    exten => s,n(unpause),UnpauseQueueMember(,Local/${uext}@from-queue/n)
    exten => s,n,Set(DB(AMPUSER/${uext}/pauses)=0)
    exten => s,n,Set(STATE=NOT_INUSE)
    exten => s,n,UserEvent(RefreshQueue)
    exten => s,n,Gosub(app-pause-toggle,sstate,1)
    exten => s,n,Wait(1)
    exten => s,n,Playback(extension)
    exten => s,n,SayDigits(${uext})
    exten => s,n,Playback(available)
    exten => s,n,Wait(1)
    exten => s,n,Hangup
    exten => sstate,1,Set(DEVICE_STATE(Custom:pAUSE${uext})=${STATE})
    exten => sstate,n,Set(DEVICES=${DB(AMPUSER/${uext}/device)})
    exten => sstate,n,GotoIf($["${DEVICES}" = "" ]?return)
    exten => sstate,n,Set(LOOPCNT=${FIELDQTY(DEVICES,&)})
    exten => sstate,n,Set(ITER=1)
    exten => sstate,n(begin),Set(DEVICE_STATE(Custom:pAUSE${CUT(DEVICES,&,${ITER})})=${STATE})
    exten => sstate,n,Set(ITER=$[${ITER} + 1])
    exten => sstate,n,GotoIf($[${ITER} <= ${LOOPCNT}]?begin)
    exten => sstate,n(return),Return()

    ;end of [app-pause-toggle]

    ------------------------------

    This code could be extended to include custom aux/pause codes as per this example: http://danielaliaman.com/blog///index.p ... hon?blog=2 (Website currently unavailable but was working earlier today)
     
  2. shaks

    Joined:
    Feb 13, 2011
    Messages:
    29
    Likes Received:
    0
    I've also placed a file in /etc/cron.daily to pause 2 queue members every night to ensure at 9am when the system switches to day mode, these extensions are paused as they are unlikely to be manned. The user then has to place themselves available by pressing the blf button *450200

    The code below ties in with the button to ensure the button/speeddial knows the correct state.

    -----------
    #!/bin/sh
    #autopauses selected queue members

    asterisk -rx "queue pause member Local/200@from-queue/n"
    asterisk -rx "database put AMPUSER 200/pauses 1"
    asterisk -rx "devstate change CUSTOM:pAUSE200 BUSY"
     
  3. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    Thank you shaks, you are truly welcome here . . .

    At last a giver who RTFM, ++karma to you!!
     
  4. shaks

    Joined:
    Feb 13, 2011
    Messages:
    29
    Likes Received:
    0
    Thanks Dicko, really appreciate the work you and the rest of the community do. I have no issues with giving back when I find something that maybe useful for others. Even if this code helps one person it's enough!
     

Share This Page