From 1de9a8ba91da4f556ce445f4c03de5fc525adc21 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Tue, 7 Apr 2026 23:17:31 +0200 Subject: [PATCH] feat: add json based phonebook --- hosts/telefonmann/default.nix | 1 + modules/voip/asterisk/default.nix | 6 +++--- modules/voip/dashboard.nix | 4 +++- modules/voip/options.nix | 7 ++++--- modules/voip/provisioning/directory-json.nix | 12 +++++++----- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/hosts/telefonmann/default.nix b/hosts/telefonmann/default.nix index 4e1eb72..338d6cc 100644 --- a/hosts/telefonmann/default.nix +++ b/hosts/telefonmann/default.nix @@ -147,6 +147,7 @@ in { extensions = { "*99" = { mode = "page"; displayName = "Durchsage an alle"; }; + "*100" = { mode = "all"; displayName = "Alle rufen"; }; # custom app extension example: # "*00" = { mode = "app"; displayName = "Echo test"; app = "Echo()"; }; }; diff --git a/modules/voip/asterisk/default.nix b/modules/voip/asterisk/default.nix index f92c232..661d6b3 100644 --- a/modules/voip/asterisk/default.nix +++ b/modules/voip/asterisk/default.nix @@ -281,9 +281,9 @@ let # Page and app extensions from cfg.extensions + "\n" + lib.concatStringsSep "\n" (lib.mapAttrsToList (ext: extCfg: - if extCfg.mode == "page" - then "exten => ${ext},1,Page(${allPageEndpoints},i,120)" - else "exten => ${ext},1,${extCfg.app}" + if extCfg.mode == "page" then "exten => ${ext},1,Page(${allPageEndpoints},i,120)" + else if extCfg.mode == "all" then "exten => ${ext},1,Dial(${allL2Endpoints},30)" + else "exten => ${ext},1,${extCfg.app}" ) cfg.extensions) # Auto-generated intercom extensions diff --git a/modules/voip/dashboard.nix b/modules/voip/dashboard.nix index 5b7d43a..94b6fd5 100644 --- a/modules/voip/dashboard.nix +++ b/modules/voip/dashboard.nix @@ -331,7 +331,9 @@ let ${lib.concatStringsSep "\n" (lib.mapAttrsToList (ext: extCfg: - let detail = if extCfg.mode == "page" then "all phones" else extCfg.app; in + let detail = if extCfg.mode == "page" then "all phones" + else if extCfg.mode == "all" then "all shared-line phones" + else extCfg.app; in '''' ) cfg.extensions)} ${lib.concatStringsSep "\n" (map (ic: diff --git a/modules/voip/options.nix b/modules/voip/options.nix index 68c6245..644c08a 100644 --- a/modules/voip/options.nix +++ b/modules/voip/options.nix @@ -315,12 +315,13 @@ in { type = lib.types.attrsOf (lib.types.submodule { options = { mode = lib.mkOption { - type = lib.types.enum [ "page" "app" ]; + type = lib.types.enum [ "page" "all" "app" ]; default = "page"; description = '' Extension mode: - - "page": one-way announcement to all phones - - "app": custom Asterisk dialplan application + - "page": one-way announcement to all intercom-capable phones + - "all": two-way call ringing all shared-line phones (allL2Endpoints) + - "app": custom Asterisk dialplan application ''; }; displayName = lib.mkOption { diff --git a/modules/voip/provisioning/directory-json.nix b/modules/voip/provisioning/directory-json.nix index 6b899bd..9f99fd8 100644 --- a/modules/voip/provisioning/directory-json.nix +++ b/modules/voip/provisioning/directory-json.nix @@ -8,8 +8,9 @@ let personContacts = lib.mapAttrsToList (_key: person: lib.filterAttrs (_: v: v != null) { - displayName = person.displayName; - extension = person.extension; + displayName = person.displayName; + extension = person.extension; + sipUsernames = lib.attrNames person.phones; intercomExtension = if cfg.intercomPrefix != null && extensionHasIntercom person.extension then "${cfg.intercomPrefix}${person.extension}" @@ -19,10 +20,11 @@ let } ) cfg.persons; - sharedPhoneContacts = lib.mapAttrsToList (_key: phone: + sharedPhoneContacts = lib.mapAttrsToList (key: phone: lib.filterAttrs (_: v: v != null) { - displayName = phone.displayName; - extension = phone.extension; + displayName = phone.displayName; + extension = phone.extension; + sipUsernames = [ key ]; intercomExtension = if cfg.intercomPrefix != null && models.${phone.model}.hasIntercom then "${cfg.intercomPrefix}${phone.extension}"
ExtensionNameTypeDetail
${ext}${extCfg.displayName}${extCfg.mode}${detail}