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 Zammad CTI 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=CallDirection.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=CallDirection.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=CallDirection.IN,
    call_id="call-uuid-123",
    cause=HangupCause.NORMAL_CLEARING,
    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.1.tar.gz (6.9 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.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_zammad_cti-0.0.1.tar.gz
  • Upload date:
  • Size: 6.9 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.1.tar.gz
Algorithm Hash digest
SHA256 20c68109b3a0135a42fe70173dfef55ff1de1f650f96a882459304f44faec508
MD5 6297da931d6e50d31c441b9aad795c58
BLAKE2b-256 a64466627f5a332cc0ff4ff4541fbb1bd1c994d9576c16714bce9edcba7384e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_zammad_cti-0.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: py_zammad_cti-0.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b474b4eab060ce2db0febbf237d0cc4c9c2f659c1883bf83826a14954bc68736
MD5 62edb1007d5a45a57f320f28a26df78f
BLAKE2b-256 5de9430254949fea1b7fa9c8b90d1c8226be60473e4da1c7e216a7263e83fe7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_zammad_cti-0.0.1-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