Chapter 2. Call Control

Introduction

The recipes in this chapter focus on making and controlling phone calls in Asterisk. The rich set of possibilities for controlling calls is part of what makes Asterisk a telephony applications platform and not just another PBX.

Creating Call Limits Using Groups

Problem

You would like to implement custom call limits in the Asterisk dialplan.

Solution

Use the GROUP() and GROUP_COUNT() dialplan functions:

exten => _1NXXNXXXXXX,1,Set(GROUP(outbound)=myprovider)
    same => n,Set(COUNT=${GROUP_COUNT(myprovider@outbound)})
    same => n,NoOp(There are ${COUNT} calls for myprovider.)
    same => n,GotoIf($[${COUNT} > 2]?denied:continue)
    same => n(denied),NoOp(There are too many calls up already.  Hang up.)
    same => n,HangUp()
    same => n(continue),GoSub(callmyprovider,${EXTEN},1})

Discussion

In this example solution, we have shown how you could use the GROUP() and GROUP_COUNT() functions to limit the number of calls sent to a provider to no more than two calls at a time. You can think of using the GROUP() function as a way to apply a marker to a channel. GROUP_COUNT() is the method of getting a count of how many active channels are up with a given mark on them.

The argument provided to the GROUP() function is a category. In our example, the category used is outbound. The first line sets the channel’s outbound group value to myprovider. On the next line, we set the COUNT variable to the number of channels that are marked as being in the myprovider group within the outbound

Get Asterisk Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.