← Back to Plugins
Channels

Telegram Sessions

hakonhagland By hakonhagland 👁 24 views ▲ 0 votes

Multi-chat session management plugin for OpenClaw — adds /resume, /newchat, /folder, /rename to Telegram and other chat channels

GitHub

Configuration Example

{
     "plugins": {
       "load": {
         "paths": ["/path/to/openclaw-telegram-sessions"]
       }
     }
   }

README

# openclaw-telegram-sessions

A session management plugin for [OpenClaw](https://github.com/openclaw/openclaw) that adds ChatGPT-style multi-chat support to Telegram and other chat channels.

> **Requires:** OpenClaw with the plugin session API ([PR #26096](https://github.com/openclaw/openclaw/pull/26096)) — not yet merged into main.

## Features

- **`/resume [name|number]`** — List and switch between named sessions
- **`/newchat <path>`** — Create a new session with hierarchical paths (e.g., `/newchat work/opm/research`)
- **`/folder <path>`** — Move current session to a folder
- **`/rename <name>`** — Rename current session
- **`/tag [tags...]`** — View/set tags on current session

Sessions are organized as paths (like folders) and sorted by most recently used.

## How It Works

Chat channels like Telegram can't switch sessions client-side (unlike the TUI or WebChat which control their own `sessionKey`). This plugin uses the OpenClaw plugin session API (`api.sessions.getEntry()` / `updateEntry()`) to swap the `sessionId` inside a fixed session key — a server-side approach that works for all webhook-based channels.

Each channel (Telegram, dashboard, etc.) maintains its own active session independently. Session data is stored in `~/.openclaw/plugins/telegram-sessions/profiles.json`.

## Installation

1. Clone this repo:
   ```bash
   git clone https://github.com/hakonhagland/openclaw-telegram-sessions.git
   ```

2. Add the plugin path to your OpenClaw config (`~/.openclaw/openclaw.json`):
   ```json
   {
     "plugins": {
       "load": {
         "paths": ["/path/to/openclaw-telegram-sessions"]
       }
     }
   }
   ```

3. Restart the gateway:
   ```bash
   openclaw gateway restart
   ```

4. Verify the plugin loaded:
   ```bash
   openclaw plugins list
   ```

## Usage

### List sessions
```
/resume
```
```
📁 Named sessions:
→ main (2h ago)

1. work/opm/research (1d ago)
2. personal/taxes (3d ago)
```

### Switch session
```
/resume 1
```
or
```
/resume work/opm/research
```

### Create new session
```
/newchat work/new-project
```

### Organize
```
/folder work/archive     # Move current session to folder
/rename better-name      # Rename current session
/tag python opm          # Set tags (for future search)
```

## Gateway Methods

The plugin also registers gateway RPC methods for dashboard/UI integration:

- `tg-sessions.list` — List all sessions with metadata
- `tg-sessions.switch` — Switch active session for a channel
- `tg-sessions.create` — Create a new named session
- `tg-sessions.update` — Rename/move/update tags
- `tg-sessions.delete` — Delete a session

## Session Data Model (v3)

```json
{
  "version": 3,
  "sessions": {
    "main": { "sessionId": "uuid-1", "tags": [], "lastUsedAt": 1708790400000 },
    "work/opm/research": { "sessionId": "uuid-2", "tags": ["opm"], "lastUsedAt": 1708704000000 }
  },
  "channels": {
    "agent:main:main": { "activeAlias": "main" },
    "agent:main:dashboard": { "activeAlias": "work/opm/research" }
  },
  "folders": {}
}
```

## Plugin API Used

This plugin demonstrates the session API from [PR #26096](https://github.com/openclaw/openclaw/pull/26096):

```typescript
// Read current session entry
const entry = api.sessions.getEntry(ctx.sessionKey);

// Swap to a different conversation context
await api.sessions.updateEntry(ctx.sessionKey, {
  sessionId: targetSession.sessionId,
  sessionFile: targetSession.sessionFile,
});
```

## License

MIT
channels

Comments

Sign in to leave a comment

Loading comments...