Metadata-Version: 2.3
Name: aips-chatwork
Version: 0.1.1
Summary: Lightweight Python client for the Chatwork API
Author: looreypun
Author-email: looreypun <looreyhunks@gmail.com>
Requires-Dist: httpx>=0.28.1
Requires-Python: >=3.12
Description-Content-Type: text/markdown

# AIPS Chatwork

A lightweight Python client for sending messages and formatted alerts to the Chatwork API.

## Requirements

- Python 3.12+

## Installation

Using `uv`:

```bash
uv add aips-chatwork
```

Using `pip`:

```bash
pip install aips-chatwork
```

## Usage

### Send a Message

```python
from aips_chatwork import ChatworkClient

with ChatworkClient(
    api_token="your-api-token",
) as client:
    client.send_message(
        room_id="123456789",
        message="Hello from Chatwork",
    )
```

### Send a Formatted Alert

Formatted alerts can include a server or application name and IP address.

```python
from aips_chatwork import ChatworkClient

with ChatworkClient(
    api_token="your-api-token",
    server_name="app-server-01",
    server_ip="10.0.1.25",
) as client:
    client.send_alert(
        room_id="123456789",
        title="Service Error",
        message=("Service: background-worker\nError: Connection timeout"),
    )
```

The message is formatted in Chatwork similar to:

```text
APP-SERVER-01 | 10.0.1.25

【Service Error】

Service: background-worker
Error: Connection timeout
```

## Environment Variables

API tokens and room IDs should not be hard-coded in application source code.

For example:

```dotenv
CHATWORK_API_TOKEN=your-api-token
CHATWORK_ROOM_ID=123456789
```

Then:

```python
import os

from aips_chatwork import ChatworkClient

with ChatworkClient(
    api_token=os.environ["CHATWORK_API_TOKEN"],
    server_name="app-server-01",
    server_ip="10.0.1.25",
) as client:
    client.send_alert(
        room_id=os.environ["CHATWORK_ROOM_ID"],
        title="Service Error",
        message="An unexpected error occurred.",
    )
```

## Development

Install dependencies:

```bash
uv sync
```

Run Ruff:

```bash
uv run ruff check .
uv run ruff format .
```