Skip to main content
Asterisk’s AGI (Asterisk Gateway Interface) lets you run an external script — here, a Python script — mid-dialplan to control call flow. This guide shows how to open a Humain Kiosk voice session when a call arrives, bridge audio through the SIP gateway, and close the session on hang-up. Requires: Asterisk 18+, Python 3.9+.
Store your credential as an environment variable. Never hard-code hk_live_… tokens in source files, dialplans, or configuration files committed to version control. Use an environment variable (HUMAIN_CREDENTIAL) or a secrets manager and inject the value at runtime.

1

Install the PJSIP trunk

Configure the Humain SIP trunk in PJSIP. Add the following to /etc/asterisk/pjsip.conf:
Then reload:
2

Install the Python AGI library

pyst2 provides the asterisk.agi module for reading channel variables and controlling call flow from Python. requests is used to call the Humain REST API.
3

Create the AGI script

Create /usr/share/asterisk/agi-bin/humain_kiosk.py and make it executable:
Paste the following:
4

Add the dialplan extension

In /etc/asterisk/extensions.conf, add a context that routes inbound calls through the AGI script:
Point your inbound SIP trunk (or DID routing) at the [humain-kiosk] context.Reload the dialplan:
5

Test the call

Dial the DID number routed to [humain-kiosk]. Watch the Asterisk console and your log file:
You should see:
  • humain_kiosk: session hk_sess_… opened
  • The Humain AI greeting playing to the caller
  • humain_kiosk: session hk_sess_… closed on hang-up

Handling DTMF before connecting

Use Asterisk’s Read() application to collect a DTMF digit, then branch to the AI only if the caller chooses it:
The AGI script has access to all Asterisk channel variables. You can pass caller ID and DID information to the session by extending open_session() with a metadata payload:
Then in main():
The metadata is available in your kiosk’s action endpoints as session.metadata.

ARI alternative

If you prefer a more programmatic approach — handling multiple calls in a single process, reacting to mid-call events, or dynamically building bridges — see the Asterisk ARI integration guide.