> ## Documentation Index
> Fetch the complete documentation index at: https://docs.archetypeai.app/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Start with /introduction/getting-started. Use the Direct Query API (POST /query) with the Newton Fusion model (text, image, and video reasoning) or the Newton Omega encoder (time-series embeddings). ATAI_API_ENDPOINT must include the version path: /v0.5 for most APIs, /v0.6 for the Fine-Tuning Service. Pages whose descriptions are marked (Archived) document the legacy Lens runtime — do not use them for new projects.

# Real-time Camera Alerts

> (Archived) Legacy Lens-based example: smart video monitoring with alerts delivered to Telegram.

## Diagram

```mermaid theme={"system"}
graph LR
    A[RTSP Camera] --> B[Lens]
    C[Terminal/Telegram] --> B
    B --> D[Response Filtering]
    D --> E[Telegram Alerts]
    
    style B fill:#9EBBFF,stroke:none,color:#000000
    style D fill:#9EBBFF,stroke:none,color:#000000
```

## How it works

* **Activity Monitor Lens** running in Archetype platform
* **Real time camera analysis**. To set up your own camera, follow the [RTSP setup guide](/code-examples/telegram-alerts/setup/rtsp-setup)
* **Curated prompting.** The model is prompted in a way that it tries to minimize hallucination, and to respond following a format that we can search after. It follows a 3 step process:

  1. Analyze exactly what it sees in the video
  2. Summarize observations related to the focus area
  3. Decide whether to send an alert using the word **Alert** at the beginning.

  <Accordion title="View the instruction we use">
    ```python theme={"system"}
    "STOP. FOLLOW THIS EXACT FORMAT: Step 1: Write <scan> I see in this video: "
    "then list ALL detected objects, vehicles, people, animals, buildings, and their "
    "visual or behavioral attributes (colors, shapes, positions, actions). Then close "
    "with </scan>. Step 2: Write Search result: and analyze if the item or event being "
    "searched for is present in your scan. Step 3: If the searched-for item is not found, "
    "write: No alerts: short description of what was detected, max 15 words. "
    "If the searched-for item is present, it is VERY IMPORTANT THAT YOU WRITE THIS: "
    "**Alert**: short description of what was detected, max 15 words ONLY return one of the above. "
    "Do not describe anything else."
    ```
  </Accordion>
* **Response filtering.** This format allows us to expect the trigger word **"Alert"** whenever what's in focus is detected, so we watch for that trigger word to send alerts. That trigger word could be anything, but would need to match in both prompt and response filter.

## Run the demos

## Prerequisites

The instructions below assume you are following best practices and have downloaded this git repo into a parent directory at: \~/atai.

If you have already installed the [ATAI Python Library](https://github.com/archetypeai/python-client) and cloned the [cookbook repository](https://github.com/archetypeai/archetypeai-cookbook), proceed directly to [Quickstart](/code-examples/command-line-demos/activity-monitor/activity-monitor#quick-start).

#### Install Conda

```
wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
bash Anaconda3-2022.05-Linux-x86_64.sh
source ~/.bashrc
```

#### Setup dev environment

```
conda create -n dev_env python=3.10
conda activate dev_env
```

#### Install [ATAI Python Library](https://github.com/archetypeai/python-client)

```bash theme={"system"}
git clone git@github.com:archetypeai/python-client.git
cd python-client
python -m pip install .
```

#### Clone the [Cookbook Repository](https://github.com/archetypeai/archetypeai-cookbook.git)

```bash theme={"system"}
git clone git@github.com:archetypeai/newton-demos.git
```

#### Configure RTSP Stream and Telegram Bot

* **RTSP Stream**: Set up your camera's RTSP stream using the [RTSP Setup Guide](/code-examples/telegram-alerts/setup/rtsp-setup)
* **Telegram Bot**: Create and configure your bot following the [Bot Configuration Guide](/code-examples/telegram-alerts/setup/bot-setup) - you'll need the bot token and chat ID

## Run Demos

### Demo 1: Command Line + Telegram

* Open a terminal and activate the conda environment where python\_client is installed
* Navigate to `telegram-alerts/terminal_bot`

```jsx theme={"system"}
    $ cd telegram-alerts/terminal_bot
```

* Open the file `app.py`
  * Add your bot token to BOT\_TOKEN
  * Add your chat ID to CHAT\_ID
* In the terminal:

  * Run the following commands and follow the instructions:

  ```jsx theme={"system"}
  $ python app.py
  ```

When prompted, enter your API key, select rtsp/video and specify the focus area. The system will start monitoring and send notifications when alerts are triggered.

Note that this script doesn't terminate sessions automatically. To stop sessions, use either the console or visit: [http://3.101.191.195:6011/lensapitools](http://3.101.191.195:6011/lensapitools)

With this version, you can run multiple sessions simultaneously in different terminal windows.

### Demo 2: Only Telegram demo

* Open a terminal and activate the conda environment where python\_client is installed.
* Navigate to `telegram-alerts/bot_only`.

```jsx theme={"system"}
    $ cd telegram-alerts/bot_only
    $ pip install -r requirements.txt
```

* Open the file `app.py`
  * Add your bot token to BOT\_TOKEN
  * Add your chat ID to CHAT\_ID
* In the terminal:

  * Run the following commands:

  ```jsx theme={"system"}
  $ python app.py
  ```
* When you run the script, you'll receive a message in Telegram. Follow the instructions to configure your smart monitor.

Note: This version only supports running the script in **one terminal window**.
