Skip to main content

Zammad CTI client

Project description

Zammad CTI Client (Python)

A lightweight, typed Python client for interacting with Zammad’s Generic CTI API. This module allows telephony systems (PBX, SIP servers, dialers, etc.) to notify Zammad about call lifecycle events such as new calls, answers, and hangups.

📖 Official Zammad CTI documentation: https://docs.zammad.org/en/latest/api/generic-cti/index.html


Features

  • Simple and clean API for Zammad CTI events
  • Fully typed (using typing and custom type aliases)
  • Automatic environment-based configuration via ENVMod
  • Structured logging via logwrap
  • Minimal dependencies
  • Explicit control over SSL verification
  • Designed for backend / PBX integrations

Installation

pip install py-zammad-cti

This module also depends on:

  • classmods
  • requests
  • python-dotenv (Optional)

Make sure those are available in your environment.


Basic Usage

from zammad_cti import CTIClient

client = CTIClient(
    url="https://zammad.example.com/api/v1/cti/<TOKEN>",
    verify_ssl=False,
)

Once initialized, you can send CTI events to Zammad.


Environment Configuration (ENVMod)

The CTIClient constructor is registered with ENVMod:

@ENVMod.register(section_name='ZammadCTI')

This allows configuration via environment variables or .env files (depending on your ENVMod setup), for example:

ZammadCTI_URL=https://zammad.example.com/api/v1/cti/<TOKEN>
ZammadCTI_VERIFY_SSL=false

This makes the client easy to configure in containerized or production environments.

Later you can load env with python-dotenv and classmod easily:

from zammad_cti import CTIClient
from classmods import ENVMod

client = CTIClient(**ENVmod.load_args(CTIClient.__init__))

Read classmods documentations for more info and usage:

📖 Official classmods documentation: https://github.com/hmohammad2520-org/classmods


Call Lifecycle Methods

1. New Call

Notify Zammad that a new call has started.

client.new_call(
    _from="+491234567",
    to="+498765432",
    direction='in',
    call_id="call-uuid-123",
    user="John Doe",
    queue="Support",
)

Parameters

Name Type Description
_from str Caller number
to str Destination number
direction CallDirection Call direction (in / out)
call_id str Unique call identifier
user `Optional[str List[str]]` Related user(s)
queue Optional[str] Queue name

2. Answer Call

Notify Zammad that a call has been answered.

client.answer(
    _from="+491234567",
    to="+498765432",
    direction='in',
    call_id="call-uuid-123",
    answering_number="+498765432",
    user="Agent Smith",
)

Parameters

Name Type Description
_from str Caller number
to str Destination number
direction CallDirection Call direction
call_id str Unique call ID
answering_number Optional[str] Number used to identify the answering user
user `Optional[str List[str]]` User(s) involved

3. Hangup Call

Notify Zammad that a call has ended.

client.hangup(
    _from="+491234567",
    to="+498765432",
    direction='in',
    call_id="call-uuid-123",
    cause='normalClearing',
    answering_number="+498765432",
)

Parameters

Name Type Description
_from str Caller number
to str Destination number
direction CallDirection Call direction
call_id str Unique call ID
cause HangupCause Reason for hangup
answering_number Optional[str] User lookup hint

Zammad uses the hangup cause to determine missed calls, answered calls, etc.


Logging

This module uses logwrap decorators to automatically log:

  • Outgoing HTTP requests
  • Call lifecycle transitions
  • Returned results

Example logged message:

Changed call state to hangup: {...}, result: {...}

Logging behavior can be controlled centrally via logwrap.


HTTP Behavior

  • Uses a persistent requests.Session
  • Sends data as application/json
  • Automatically removes None values from payloads
  • Raises exceptions on HTTP errors (response.raise_for_status())

Most CTI responses are empty unless the call is rejected or blocked in Zammad. Read Zammad CTI system documentation for more info.


Type Safety

The client relies on explicit type aliases:

  • CallDirection
  • HangupCause

This helps prevent invalid CTI payloads and improves IDE autocomplete and static analysis.


Typical Use Case

This client is ideal for:

  • PBX → Zammad integrations
  • SIP servers (Asterisk, FreeSWITCH, Kamailio)
  • Custom softphones
  • Call monitoring services
  • Telephony middleware

Error Handling

  • All HTTP errors raise requests.HTTPError
  • Validation is delegated to Zammad
  • Invalid payloads will be rejected server-side

You should wrap calls in your own retry / error-handling logic if required.


License

MIT (or your preferred license)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_zammad_cti-0.0.2.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_zammad_cti-0.0.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file py_zammad_cti-0.0.2.tar.gz.

File metadata

  • Download URL: py_zammad_cti-0.0.2.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py_zammad_cti-0.0.2.tar.gz
Algorithm Hash digest
SHA256 04ad9161fb3166ae95252876c630d7bd92a5ca4dc10d116eb828583de7ed0dd3
MD5 853634968c1567adaa754db2be9ab332
BLAKE2b-256 902ff660123a16e805a977412b65e39df7827d6a19d881f7b0899b81dc3f8272

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_zammad_cti-0.0.2.tar.gz:

Publisher: python-publish.yml on hmohammad2520-org/py-zammad-cti

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_zammad_cti-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_zammad_cti-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py_zammad_cti-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3994349942f13540c1fdedd2d7699f273747bc84368b62522ae6446b02b18290
MD5 6779d25d8997fe9e4de0f943364b7164
BLAKE2b-256 9db298e311dcf15847ec58095df98938c271d4e1aae7eeabfad9a9bbf062374a

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_zammad_cti-0.0.2-py3-none-any.whl:

Publisher: python-publish.yml on hmohammad2520-org/py-zammad-cti

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page