Telecom

Asterisk Dialplan: Single Exten For member removal using database (Latest Versions)

MYLINEHUB Team • 2026-02-10 • 10 min

Updated guide for modern Asterisk (PJSIP era): single exten for member removal using database with real configs, common mistakes, and troubleshooting steps.

Asterisk Dialplan: Single Exten For member removal using database (Latest Versions)

In real call centers, agents must be able to quickly log out of queues, get removed during shift changes, or be disabled automatically if their device goes offline.

Many deployments implement removal using multiple dialplan lines or manual CLI commands. But a cleaner approach is: use a single dialplan extension that removes a member based on database state.

This article shows a practical pattern using the Asterisk internal database (AstDB) to store queue membership information, and then remove the correct member using one universal extension.

All examples are compatible with modern Asterisk + PJSIP.

The Problem This Solves

Common operational pain:

  • Agent changes phone/device but old device still stays in queue
  • Agent forgets to log out at end of shift
  • Supervisor wants a quick way to remove any agent
  • Queue gets “stuck” because offline members remain registered

The goal: remove the correct queue member reliably using one feature code.

Core Idea: Store Membership in AstDB

Store mapping:

DB(queue_members/<agentid>) = PJSIP/<endpoint>

Example:

DB(queue_members/1001) = PJSIP/1001

Then a single extension can read that value and remove the member correctly.

Step 1 — Agent Login: Add Member and Store in AstDB

Agent dials *45 to log into queue.

[from-internal]
exten => *45,1,Answer()
 same => n,Set(AGENT=${CALLERID(num)})
 same => n,Set(MEMBER=PJSIP/${AGENT})

 ; Add member to queue
 same => n,AddQueueMember(support,${MEMBER})

 ; Store mapping in AstDB so we can remove later
 same => n,Set(DB(queue_members/${AGENT})=${MEMBER})

 same => n,Playback(agent-loginok)
 same => n,Hangup()

Result:

  • Agent is added to queue
  • AstDB remembers what member string was used

Step 2 — Single Extension to Remove Member Using Database

Agent dials *46 to log out. The dialplan fetches the member string from AstDB.

[from-internal]
exten => *46,1,Answer()
 same => n,Set(AGENT=${CALLERID(num)})

 ; Read member string from DB
 same => n,Set(MEMBER=${DB(queue_members/${AGENT})})

 ; Safety check
 same => n,GotoIf($["${MEMBER}"=""]?notfound)

 ; Remove member using exact stored member string
 same => n,RemoveQueueMember(support,${MEMBER})

 ; Cleanup DB
 same => n,DBDel(queue_members/${AGENT})

 same => n,Playback(agent-loggedoff)
 same => n,Hangup()

 same => n(notfound),Playback(vm-nobodyavail)
 same => n,Playback(agent-loggedoff)
 same => n,Hangup()

This works even if your membership string is more complex, because you remove exactly what you stored.

Why This Pattern Is More Reliable

  • Prevents mismatch errors (removing wrong member string)
  • Works when agent uses different devices over time
  • Allows supervisors to remove agents centrally
  • Creates consistent cleanup of queue state

Supervisor Removal (Remove Any Agent with One Code)

Example: supervisor dials *47 then enters agent ID.

[from-internal]
exten => *47,1,Answer()
 same => n,Read(AGENT,enter-ext-of-agent,4)

 same => n,Set(MEMBER=${DB(queue_members/${AGENT})})
 same => n,GotoIf($["${MEMBER}"=""]?notfound)

 same => n,RemoveQueueMember(support,${MEMBER})
 same => n,DBDel(queue_members/${AGENT})

 same => n,Playback(agent-loggedoff)
 same => n,Hangup()

 same => n(notfound),Playback(invalid)
 same => n,Hangup()

This gives supervisors operational control without CLI access.

How to Verify Members from CLI

asterisk -rvvv
queue show support

Check database values:

database show queue_members

Common Problems and Fixes

RemoveQueueMember Does Nothing

  • The member string stored does not match actual queue member string
  • Fix by always storing the exact member string used in AddQueueMember

DB Has Old Values

  • Agent logged in, but system crashed before logout
  • Fix by building a cleanup routine or supervisor removal code

Agents Still Receive Calls After Removal

  • Agent is registered multiple times from multiple devices
  • Fix by controlling multi-registration policy

Best Practices for Production

  • Use AstDB only for small runtime state (like membership strings)
  • Always clean DB keys during logout/removal
  • Provide supervisor removal feature codes
  • Consider periodic health checks to remove unreachable members

This pattern is a simple step toward self-healing call center operations.

Key Takeaway

By storing queue member strings in AstDB, you can create a single universal dialplan extension that removes the correct member every time.

This improves reliability, reduces operational mistakes, and makes Asterisk queue management scalable for real businesses.

Try it

Want to see API-driven CRM + Telecom workflows in action? Try the WhatsApp bot or explore the demos.

💬 Try WhatsApp Bot ▶️ Watch CRM YouTube Demos
Tip: Comment “Try the bot” on our YouTube videos to see automation in action.
M
MYLINEHUB Team
Published: 2026-02-10
Quick feedback
Was this helpful? (Yes 0 • No 0)
Reaction

Comments (0)

Be the first to comment.