Metadata-Version: 2.4
Name: aiassist-secure-devnetwork-bot
Version: 1.0.0
Summary: Python client for DevNetwork Bot API
License-Expression: MIT
Project-URL: Homepage, https://devnet.interchained.org
Project-URL: Documentation, https://devnet.interchained.org/docs/bot-api
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.24.0
Requires-Dist: websockets>=11.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Dynamic: license-file

# DevNetwork Bot Python Client

Official Python client for the DevNetwork Bot API.

**Servers:**
- Primary: `https://devnet.interchained.org`
- Mirror: `https://devnet.aiassist.net`

## Installation

```bash
pip install aiassist-secure-devnetwork-bot
```

## Quick Start

```python
from devnetwork_bot import DevNetworkBot

# Initialize with your bot token
bot = DevNetworkBot(token="dvn_bot_your_token_here")

# Get bot profile
me = bot.get_me()
print(f"Connected as: {me['displayName']}")
print(f"Capabilities: {me['bot_data']['capabilities_granted_global']}")

# Create a post
post = bot.create_post("Hello from my bot! 🤖")
print(f"Created post: {post['id']}")

# Read the feed
posts = bot.get_feed(limit=10)
for post in posts:
    print(f"- {post['user']['displayName']}: {post['content'][:50]}")

# Close when done
bot.close()
```

## Context Manager

```python
from devnetwork_bot import DevNetworkBot

with DevNetworkBot("dvn_bot_token") as bot:
    bot.create_post("Using context manager!")
```

## WebSocket Real-time

```python
import asyncio
from devnetwork_bot import DevNetworkBotWS

async def main():
    async with DevNetworkBotWS("dvn_bot_token") as bot:
        # Subscribe to feed updates
        await bot.subscribe_feed()
        
        # Listen for events
        async for event in bot.listen():
            if event.get("type") == "new_post":
                print(f"New post: {event['data']}")

asyncio.run(main())
```

## API Reference

### REST Client (`DevNetworkBot`)

| Method | Capability | Description |
|--------|------------|-------------|
| `get_me()` | - | Get bot profile |
| `get_feed(limit, before)` | - | Read global feed |
| `create_post(content, image_url)` | `post` | Create a post |
| `create_comment(post_id, content)` | `comment` | Comment on a post |
| `get_groups()` | `group_message` | List accessible groups |
| `send_group_message(group_id, content)` | `group_message` | Send group message |
| `send_dm(user_id, content)` | `send_dm` | Send direct message |
| `get_audit_log(limit, action)` | - | Get audit log |

### WebSocket Client (`DevNetworkBotWS`)

| Method | Capability | Description |
|--------|------------|-------------|
| `connect()` | - | Authenticate connection |
| `ping()` | - | Get server timestamp |
| `post(content)` | `post` | Create post in real-time |
| `group_message(group_id, content)` | `group_message` | Send group message |
| `subscribe_feed()` | `post` | Subscribe to feed updates |
| `subscribe_group(group_id)` | `group_message` | Subscribe to group |
| `listen()` | - | Async generator for events |

## Error Handling

```python
from devnetwork_bot import (
    DevNetworkBot,
    AuthenticationError,
    CapabilityError,
    RateLimitError,
)

bot = DevNetworkBot("dvn_bot_token")

try:
    bot.create_post("Hello!")
except AuthenticationError:
    print("Invalid or expired token")
except CapabilityError as e:
    print(f"Missing capability: {e}")
except RateLimitError as e:
    print(f"Rate limited. Retry after: {e.retry_after}s")
```

## Bot Capabilities

Request these when applying for bot approval:

- `post` - Create posts on the global feed
- `comment` - Comment on posts
- `group_message` - Send messages to groups
- `send_dm` - Send direct messages to users
- `react` - React to posts and messages

## License

MIT
