How to dial all registered contacts of an account from Lua

This page describes how to make all phones (contacts) registered on an Asterisk account ring at the same time from within a Lua dial plan.

Note: This only works with PJSIP (res_pjsip.so), not with chan_sip.so.

The pieces

Lua dial plan example

The PJSIP object is the global channel hash! This is how it works.
# extensions.lua
local contacts = channel.PJSIP_DIAL_CONTACTS(extension):get()
app.dial(contacts, timeout, options)
However, there's a problem. If a call to a provider runs through this, PJSIP returns something like
pjsip_acf_dial_contacts_read: Specified endpoint 'PJSIP/20000@sipgate_trunk' was not found.
This is my workaround
# extensions.lua
-- workaround for "WARNING: Specified endpoint 'PJSIP/20000@sipgate_trunk' was not found"
-- I hope there's a better way, but I don't know it.
local contacts
if not string.find(extension, "_trunk$") then
    local contacts = channel.PJSIP_DIAL_CONTACTS(extension):get() -- PJSIP-specific
end
if contacts == nil then contacts = extension end
app.dial(contacts, timeout, options)

Links

Licensed under the Creative Commons Attribution-Share Alike 3.0 License.
Created 2018-04