Skip to main content

Call event scripts

NethVoice can execute custom scripts when a call is received and when it ends. This feature can be used to integrate NethVoice with CRM platforms, ticketing systems, business applications, or external HTTP services.

warning

Scripts run in the freepbx container. They must terminate quickly, handle errors without blocking the process, and treat all received data as untrusted input.

Prerequisites

Before proceeding:

  • identify the NethVoice instance identifier, for example nethvoice1
  • copy the script to the /tmp directory on the node
  • access the instance environment:
runagent -m nethvoice1
  • copy the script into the application, for example SCRIPT.name:
podman cp /tmp/SCRIPT.name freepbx:/var/lib/asterisk/agi-bin/SCRIPT.name
  • change the owner and group:
podman exec freepbx chown asterisk.asterisk /var/lib/asterisk/agi-bin/SCRIPT.name
  • make the script executable inside the container:
podman exec freepbx chmod 750 /var/lib/asterisk/agi-bin/SCRIPT.name

Run a script when a call ends

Open ~/.config/state/environment in the instance environment and add:

NETHCTI_CDR_SCRIPT=/var/lib/asterisk/agi-bin/SCRIPT.name

Restart the service to apply the environment variables. This restarts Asterisk and therefore terminates all active calls:

systemctl --user restart freepbx

To disable the hook, set an empty value and restart the service:

NETHCTI_CDR_SCRIPT=

NethVoice passes the following arguments to the script, in the same order:

PositionParameterDescription
1sourceSource number
2channelSource channel
3endtimeEnd date and time
4durationTotal duration in seconds
5amaflagsCDR AMA flags
6uniqueidUnique channel identifier
7calleridFull caller ID
8starttimeStart date and time
9answertimeAnswer date and time, if available
10destinationDestination
11dispositionCDR result, for example ANSWERED, NO ANSWER, BUSY, or FAILED
12lastapplicationLast Asterisk application executed
13billablesecondsDuration from when the call was answered until it ended
14destinationcontextDestination context
15destinationchannelDestination channel
16accountcodeChannel account code

Run a script for an incoming external call

Open ~/.config/state/environment in the instance environment and add:

NETHCTI_CDR_SCRIPT_CALL_IN=/var/lib/asterisk/agi-bin/SCRIPT.name

Restart the service to apply the environment variables. This restarts Asterisk and therefore terminates all active calls:

systemctl --user restart freepbx

To disable the hook, set an empty value and restart the service:

NETHCTI_CDR_SCRIPT_CALL_IN=

NethVoice passes the following arguments to the script, in the same order:

PositionParameterDescription
1callerNumCaller number
2uniqueIdUnique call or channel identifier
:::
NethVoice 8.0