telechatai 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 telechatai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ include LICENSE
2
+ include README.md
3
+ include requirements.txt
4
+ recursive-include scripts *
@@ -0,0 +1,372 @@
1
+ Metadata-Version: 2.4
2
+ Name: telechatai
3
+ Version: 1.0.0
4
+ Summary: Claude AI on your phone/desktop — personal, self-hosted messenger bot for Telegram, WhatsApp, and Slack
5
+ Author: telechatai
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/telechatai/telechat
8
+ Project-URL: Repository, https://github.com/telechatai/telechat
9
+ Project-URL: Issues, https://github.com/telechatai/telechat/issues
10
+ Keywords: telechat,claude,telegram,whatsapp,slack,chatbot,ai,anthropic
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Communications :: Chat
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: python-telegram-bot>=21.6
24
+ Requires-Dist: anthropic>=0.99.0
25
+ Requires-Dist: requests>=2.32.0
26
+ Requires-Dist: python-dotenv>=1.0.0
27
+ Requires-Dist: slack-bolt>=1.21.0
28
+ Dynamic: license-file
29
+
30
+ # Telechat
31
+
32
+ > **Claude AI on your phone / desktop** — personal, self-hosted, zero-infrastructure.
33
+ > Supports **WhatsApp**, **Telegram**, and **Slack** simultaneously from a single process.
34
+
35
+ A bot that connects to Claude AI via two modes:
36
+
37
+ - **CLI mode** — Uses the Claude Code CLI (`claude`). No API key needed if you have a Claude subscription.
38
+ - **API mode** — Uses the Anthropic API directly. Requires an API key. Works in Docker.
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ # npm (auto-installs Python deps on first run)
44
+ npm install -g telechat
45
+ telechat
46
+
47
+ # pip
48
+ pip install telechat
49
+ telechat
50
+ ```
51
+
52
+ ## Quick Start (from source)
53
+
54
+ ```bash
55
+ # Clone
56
+ git clone https://github.com/telechatai/telechat.git
57
+ cd telechat
58
+
59
+ # Install
60
+ ./scripts/install.sh
61
+
62
+ # Edit .env with your tokens
63
+ nano .env
64
+
65
+ # Run
66
+ ./scripts/start.sh
67
+ ```
68
+
69
+ ## Platform comparison
70
+
71
+ | | Telegram | WhatsApp | Slack |
72
+ |--|----------|----------|-------|
73
+ | Bridge | Telegram Bot API | [Green API](https://green-api.com) free tier | Slack Bolt + Socket Mode |
74
+ | Setup | Talk to @BotFather | Scan a QR code | Create a Slack app |
75
+ | Photo / file support | Yes | Text only | Text only |
76
+ | Interactive UI | Inline buttons | No | Reactions as status indicator |
77
+ | Works without public URL | Yes (polling) | Yes (polling) | Yes (WebSocket) |
78
+ | Works on corporate Wi-Fi | Depends | Yes | Yes |
79
+
80
+ ---
81
+
82
+ ## Setup
83
+
84
+ ### 1 — Choose your platform(s)
85
+
86
+ Set `BOT_MODE` in `.env` — accepts a comma-separated list or a shorthand:
87
+
88
+ | Value | What starts |
89
+ |-------|-------------|
90
+ | `telegram` | Telegram only *(default)* |
91
+ | `whatsapp` | WhatsApp only |
92
+ | `slack` | Slack only |
93
+ | `telegram,slack` | Telegram + Slack |
94
+ | `telegram,whatsapp` | Telegram + WhatsApp |
95
+ | `both` | Telegram + WhatsApp (legacy alias) |
96
+ | `all` | All three platforms |
97
+
98
+ ---
99
+
100
+ ### 2a — Telegram setup
101
+
102
+ 1. Open Telegram and search for **@BotFather** (verified blue checkmark).
103
+ 2. Send `/newbot` and follow the prompts.
104
+ 3. Copy the token → set `TELEGRAM_BOT_TOKEN` in `.env`.
105
+
106
+ **Optional: customize your bot**
107
+
108
+ | BotFather command | What it does |
109
+ |-------------------|--------------|
110
+ | `/setdescription` | Text users see before starting the bot |
111
+ | `/setabouttext` | Bio shown on the bot's profile |
112
+ | `/setuserpic` | Profile picture |
113
+ | `/setcommands` | Register autocomplete hints |
114
+
115
+ Register command hints:
116
+ ```
117
+ start - Welcome message
118
+ reset - Clear conversation history
119
+ mode - Show current mode and model
120
+ id - Show your Telegram user ID
121
+ ```
122
+
123
+ **Finding your user ID (for `ALLOWED_USER_IDS`)**
124
+
125
+ 1. Start your bot and send `/id`
126
+ 2. Copy the numeric ID → paste into `ALLOWED_USER_IDS` in `.env`
127
+
128
+ ---
129
+
130
+ ### 2b — Slack setup (Socket Mode — no public URL needed)
131
+
132
+ > **Corporate / enterprise workspace?** Most company Slack workspaces (e.g. Intuit) block
133
+ > individual users from installing new apps. If you hit _"An error occurred while creating
134
+ > your request"_, create a **free personal workspace** at [slack.com/get-started](https://slack.com/get-started)
135
+ > and install the bot there instead. You're the admin — no approval needed. Invite your
136
+ > teammates to the personal workspace to share the bot.
137
+
138
+ #### Step-by-step
139
+
140
+ 1. Go to <https://api.slack.com/apps> → **Create New App** → **From scratch**
141
+ _(pick your personal workspace, not a corporate one)_
142
+
143
+ 2. **Settings → Socket Mode → Enable**
144
+ → **Create an App-Level Token** → name it anything → scope: `connections:write`
145
+ → copy the `xapp-1-...` token — this is `SLACK_APP_TOKEN`
146
+
147
+ 3. **OAuth & Permissions → Bot Token Scopes** → add all of these:
148
+
149
+ | Scope | Purpose |
150
+ |-------|---------|
151
+ | `chat:write` | Send messages |
152
+ | `channels:history` | Read public channel messages |
153
+ | `groups:history` | Read private channel messages |
154
+ | `im:history` | Read DMs |
155
+ | `im:write` | Open DM conversations |
156
+ | `app_mentions:read` | Detect @mentions |
157
+ | `reactions:write` | Show ⏳ while Claude thinks |
158
+
159
+ 4. **Event Subscriptions → Enable** → Subscribe to bot events:
160
+ `message.im`, `message.channels`, `message.groups`, `app_mention`
161
+ → **Save Changes**
162
+
163
+ 5. **OAuth & Permissions → Install to Workspace** → Allow
164
+ → copy the `xoxb-...` Bot Token — this is `SLACK_BOT_TOKEN`
165
+
166
+ 6. In your Slack workspace, invite the bot to any channel: `/invite @yourbot`
167
+
168
+ #### `.env` for Slack
169
+
170
+ ```env
171
+ BOT_MODE=slack
172
+ SLACK_BOT_TOKEN=xoxb-...
173
+ SLACK_APP_TOKEN=xapp-1-...
174
+
175
+ # Your Slack member ID to restrict access (leave empty to allow everyone)
176
+ # Find it: click your name → View profile → ⋯ → Copy member ID
177
+ SLACK_ALLOWED_USER_IDS=U01234567
178
+ ```
179
+
180
+ #### How it works
181
+
182
+ | Trigger | How to use |
183
+ |---------|-----------|
184
+ | Direct message | Just message the bot |
185
+ | Channel | `@yourbot <question>` |
186
+ | Thread | Reply mentioning the bot to keep conversation in-thread |
187
+
188
+ A ⏳ reaction appears on your message while Claude is thinking, removed when done.
189
+
190
+ ---
191
+
192
+ ### 2c — WhatsApp setup (Green API — free, no Meta account needed)
193
+
194
+ 1. Sign up at <https://console.green-api.com>
195
+ 2. Click **Create instance** → choose **Developer** plan (free — 1 500 msg/month)
196
+ 3. In the instance dashboard → **Scan QR** → scan with your WhatsApp phone
197
+ 4. Copy **Instance ID** and **API Token** → paste into `.env`:
198
+
199
+ ```env
200
+ BOT_MODE=whatsapp
201
+ GREEN_API_INSTANCE_ID=1234567890
202
+ GREEN_API_TOKEN=your_token_here
203
+ WHATSAPP_ALLOWED_NUMBERS=919876543210 # your number without the +
204
+ ```
205
+
206
+ > **Corporate network note:** Green API works over standard HTTPS polling — no
207
+ > webhook or public URL needed. If Telegram is blocked on your network, use
208
+ > `BOT_MODE=whatsapp` instead.
209
+
210
+ ---
211
+
212
+ ### 3 — Configure Claude
213
+
214
+ All Claude settings apply to both platforms:
215
+
216
+ | Variable | Default | Description |
217
+ |----------|---------|-------------|
218
+ | `CLAUDE_MODE` | `cli` | `cli` or `api` |
219
+ | `ANTHROPIC_API_KEY` | — | Required for API mode |
220
+ | `CLAUDE_MODEL` | `claude-sonnet-4-20250514` | API mode model |
221
+ | `SYSTEM_PROMPT` | _(generic)_ | Your personal instructions to Claude |
222
+ | `CLAUDE_CLI_WORK_DIR` | `~` | Working directory for CLI |
223
+ | `CLAUDE_CLI_ADD_DIRS` | — | Comma-separated extra dirs Claude can access |
224
+ | `CLAUDE_CLI_PERMISSION_MODE` | — | `acceptEdits` / `auto` / `bypassPermissions` |
225
+ | `CLAUDE_CLI_MODEL` | `sonnet` | CLI model: `haiku` / `sonnet` / `opus` |
226
+ | `CLAUDE_TIMEOUT` | `180` | Seconds to wait for Claude |
227
+ | `RATE_LIMIT_REQUESTS` | `20` | Max messages per window |
228
+ | `RATE_LIMIT_WINDOW` | `60` | Rate limit window (seconds) |
229
+
230
+ **CLI mode** — requires Claude Code CLI installed and authenticated:
231
+
232
+ ```bash
233
+ # Install Claude Code CLI: https://docs.anthropic.com/en/docs/claude-code
234
+ claude auth login
235
+ ```
236
+
237
+ **API mode:**
238
+
239
+ ```env
240
+ CLAUDE_MODE=api
241
+ ANTHROPIC_API_KEY=sk-ant-...
242
+ ```
243
+
244
+ ---
245
+
246
+ ## Running
247
+
248
+ ### Foreground
249
+
250
+ ```bash
251
+ ./scripts/start.sh
252
+ ```
253
+
254
+ ### As a system service (macOS launchd / Linux systemd)
255
+
256
+ ```bash
257
+ ./scripts/service.sh install # Install and start
258
+ ./scripts/service.sh status # Check status
259
+ ./scripts/service.sh logs # Tail logs
260
+ ./scripts/service.sh restart # Restart
261
+ ./scripts/service.sh stop # Stop
262
+ ./scripts/service.sh uninstall # Remove service
263
+ ```
264
+
265
+ ### Docker (API mode only)
266
+
267
+ ```bash
268
+ # Set CLAUDE_MODE=api in .env
269
+ docker compose up -d
270
+ docker logs -f telechat
271
+ ```
272
+
273
+ ---
274
+
275
+ ## Telegram commands
276
+
277
+ | Command | Description |
278
+ |---------|-------------|
279
+ | `/start` | Welcome message |
280
+ | `/reset` | Clear conversation history |
281
+ | `/mode` | Show current mode and model |
282
+ | `/model` | Switch model (haiku / sonnet / opus) |
283
+ | `/verbose` | Set output verbosity: 0 quiet · 1 normal · 2 detailed |
284
+ | `/permissions` | Change CLI permission mode |
285
+ | `/usage` | Show usage statistics |
286
+ | `/id` | Show your Telegram user ID |
287
+
288
+ ---
289
+
290
+ ## WhatsApp usage
291
+
292
+ Just send a message. There are no slash commands — WhatsApp is intentionally
293
+ kept simple.
294
+
295
+ ---
296
+
297
+ ## Project structure
298
+
299
+ ```
300
+ ├── main.py Entry point — reads BOT_MODE, starts adapters
301
+ ├── claude_core.py Shared: Claude CLI/API, SQLite history, rate limiting
302
+ ├── telegram_bot.py Telegram adapter
303
+ ├── whatsapp_bot.py WhatsApp adapter (Green API polling)
304
+ ├── slack_bot.py Slack adapter (Socket Mode)
305
+ ├── bot.py Backward-compat shim (runs Telegram, same as before)
306
+ ├── scripts/
307
+ │ ├── install.sh
308
+ │ ├── start.sh
309
+ │ └── service.sh
310
+ ├── Dockerfile (API mode only)
311
+ ├── docker-compose.yml
312
+ ├── requirements.txt
313
+ └── .env.example
314
+ ```
315
+
316
+ ---
317
+
318
+ ## Features
319
+
320
+ - **Three platforms** — Telegram, WhatsApp, and Slack from one process (`BOT_MODE=all`)
321
+ - **Dual Claude mode** — CLI (free with Claude subscription) or API
322
+ - **Typing indicator** — shows "typing…" while Claude processes
323
+ - **Image & file analysis** — Telegram only (photos + documents)
324
+ - **Model switching** — haiku / sonnet / opus from Telegram inline buttons
325
+ - **Verbose mode** — see what tools Claude is using
326
+ - **Rate limiting** — configurable per-user throttling
327
+ - **Persistent history** — SQLite, keyed per platform+user; survives restarts
328
+ - **Usage tracking** — per-user message and token statistics
329
+ - **Markdown rendering** — formatted responses with plain-text fallback
330
+
331
+ ---
332
+
333
+ ## Per-developer sharing
334
+
335
+ Each developer runs their **own instance** on their own machine:
336
+
337
+ 1. Clone this repo
338
+ 2. `./scripts/install.sh`
339
+ 3. Set their own credentials + `SYSTEM_PROMPT` in `.env`
340
+ 4. `./scripts/start.sh`
341
+
342
+ No shared server. No shared credentials. Fully private.
343
+
344
+ ---
345
+
346
+ ## Security
347
+
348
+ - Set `ALLOWED_USER_IDS` (Telegram) or `WHATSAPP_ALLOWED_NUMBERS` to restrict who can use your bot
349
+ - Never commit `.env` — it is in `.gitignore`
350
+ - In CLI mode the bot inherits your Claude auth — don't run on untrusted machines
351
+
352
+ ---
353
+
354
+ ## Troubleshooting
355
+
356
+ | Symptom | Fix |
357
+ |---------|-----|
358
+ | WhatsApp: no replies | Check instance status in Green API console — must be `authorized` |
359
+ | Slack: "error creating request" on install | Corporate workspace blocks app installs — create a free personal workspace at [slack.com/get-started](https://slack.com/get-started) instead |
360
+ | Slack: bot doesn't respond | Check Socket Mode is enabled; App-Level Token must have `connections:write` scope |
361
+ | Slack: works in channels but not DMs | Add `im:history` + `im:write` scopes and reinstall the app to workspace |
362
+ | Slack: missing messages after reinstall | Re-subscribe to events (`message.im`, `message.channels`, etc.) under Event Subscriptions |
363
+ | Telegram: SSL/handshake error | Telegram may be blocked on your network; use `BOT_MODE=slack` or `BOT_MODE=whatsapp` |
364
+ | `claude: command not found` | Install Claude Code CLI and ensure it's in PATH |
365
+ | Response cut off | Bot auto-chunks at 4 000 chars per message — expected |
366
+ | Bot stops after reboot | Use `./scripts/service.sh install` for a proper system service |
367
+
368
+ ---
369
+
370
+ ## License
371
+
372
+ MIT