Getting started

System Requirements

  • pip package manager
  • Python 3.7+
  • A Telegram bot project set up with Python

Installation

Install Telemetree Python SDK using pip

This will add the Telemetree Python SDK to your current developer environment and you’re ready to proceed to the next steps of configuration and event tracking.

Initialization

To being using the Telemetree Python SDK in your application, you’ll need to initialize it with your project’s specific configuration. Initialization is a crucial step that allows the SDK to start capturing and sending analytics data.

Step-by-Step Initialization

  1. Import the Telemetree SDK:
  2. Initialize the SDK with your project ID and API key.
  3. Connect the client to your webhook.

After wrapping your root component with TwaAnalyticsProvider, the SDK will automatically start capturing data based on your configuration.

Event Tracking

Alternatively, you can pass on the Telegram Update dictionary directly

event = {
    "update_id": 123456789,
    "message": {
        "message_id": 1,
        "from": {
            "id": 987654321,
            "is_bot": False,
            "first_name": "John",
            "last_name": "Doe",
            "username": "johndoe",
            "language_code": "en"
        },
        "chat": {
            "id": 987654321,
            "first_name": "John",
            "last_name": "Doe",
            "username": "johndoe",
            "type": "private"
        },
        "date": 1621234567,
        "text": "Hello, world!"
    }
}

response_status_code = client.track(event)
print(response_status_code)

Configuration

The Telemetree Python SDK provides some configuration options that you can customize:

  • auto_capture_telegram: Enables or disables automatic capturing of Telegram events (default: True)
  • auto_capture_telegram_events: Specifies the types of Telegram events to capture automatically (default: ["message"])
  • auto_capture_commands: Specifies the Telegram commands to capture automatically (default: ["/start", "/help"])

Other configuration options include the Telemetree API endpoint, encryption keys, and logging settings. You can modify these options either within the Telemetree dashboard or by updating the config.py file in the SDK.