Skip to content

mod_callcenter: Add agent-originate-check pre-originate hook#2990

Open
shaunjstokes wants to merge 2 commits intosignalwire:masterfrom
shaunjstokes:mod_callcenter_agent_lua
Open

mod_callcenter: Add agent-originate-check pre-originate hook#2990
shaunjstokes wants to merge 2 commits intosignalwire:masterfrom
shaunjstokes:mod_callcenter_agent_lua

Conversation

@shaunjstokes
Copy link
Copy Markdown
Contributor

Closes #2989

Summary

  • Add optional per-agent agent-originate-check attribute that executes a FreeSWITCH API command before originating
  • If the command returns "false", originate is skipped — no SIP INVITE, no call leg
  • Fail-open: any other return value (including errors) proceeds normally
  • Fully backward-compatible — no behaviour change when the attribute is unset

Changes

src/mod/applications/mod_callcenter/mod_callcenter.c:

  • Add agent_originate_check VARCHAR(1024) to agents table schema
  • Add reactive migration via switch_cache_db_test_reactive() for existing databases
  • Add agent_originate_check field to cc_agent_update() for runtime agent set commands
  • Load agent-originate-check XML attribute in load_agent()
  • Add agent_originate_check to all three SQL SELECT queries (position argv[19])
  • Add pre-originate check block using switch_api_execute() before switch_ivr_originate()
  • Add SUBSCRIBER_ABSENT cause handling with configurable delay (no_answer_delay_time, 5s floor)
  • Update help syntax and console autocomplete

How It Works

  1. mod_callcenter selects an agent and checks if agent_originate_check is set
  2. If set, the value is split on the first space into api_cmd and api_args
  3. The command is executed via switch_api_execute(api_cmd, api_args, NULL, &stream)
  4. If stream.data equals "false" (case-insensitive), a skip_originate flag is set
  5. When skipped, cause is set to SUBSCRIBER_ABSENT and the normal failure path runs (setting delay_next_agent_call)
  6. When not skipped, switch_ivr_originate() proceeds as normal

Design Decisions

  • Generic API execution — not tied to any specific language or backend. Works with lua, curl, python, or any registered FreeSWITCH API command
  • Fail-open — errors, empty responses, or missing attributes all result in normal origination. No risk of silently breaking existing setups
  • No goto done — the skip flows through the existing failure handling block so delay_next_agent_call is set correctly, preventing tight agent loops
  • Local skip_originate flag — avoids altering the existing status variable which is initialised to SWITCH_STATUS_FALSE
  • Configurable delay — uses the agent's existing no_answer_delay_time with a 5-second minimum floor to prevent rapid cycling

Testing

  • Configured agent-originate-check with a Lua script that queries a SIP registrar database
  • Verified registered agents receive calls normally
  • Verified unregistered agents are skipped with no SIP INVITE and no CDR
  • Verified skipped agents receive a delay before being retried
  • Verified the feature is inactive when the attribute is empty or unset
  • Verified fail-open behaviour when the API command errors

Example Usage

XML config:

<agent name="1001@example.com"
       agent-originate-check="lua agent_handler.lua 1001 example.com" />

Runtime via fs_cli:

callcenter_config agent set agent_originate_check 1001@example.com lua agent_handler.lua 1001 example.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mod_callcenter: Add pre-originate check hook (agent-originate-check)

1 participant