working bot, cleaned up git

This commit is contained in:
2025-08-17 15:18:40 +02:00
commit a1045614c9
7 changed files with 1226 additions and 0 deletions

49
.env.example Normal file
View File

@@ -0,0 +1,49 @@
# Signal configuration
SIGNAL_PHONE_NUMBER=+1234567890
# PrivateMode API configuration
PRIVATEMODE_BASE_URL=http://localhost:8080
# Optional: Model to use (if not specified, will use first available model)
# PRIVATEMODE_MODEL=ibnzterrell/Meta-Llama-3.3-70B-Instruct-AWQ-INT4
# Permission System Configuration
# Path to permissions configuration file (default: permissions.json)
# PERMISSIONS_CONFIG_PATH=permissions.json
# Signal Service Configuration
# Signal CLI REST API service endpoint (default: localhost:8080)
# SIGNAL_SERVICE=localhost:8080
# Security Configuration
# Enable/disable permission system (default: enabled)
# PERMISSIONS_ENABLED=true
# Logging Configuration
# Log level for permission system (default: INFO)
# PERMISSIONS_LOG_LEVEL=INFO
# Admin Configuration
# Default admin phone number for initial setup
# Set this to your phone number to get admin access on first run
# ADMIN_PHONE_NUMBER=+1234567890
# Whisper ASR Configuration
# Comma-separated list of Whisper ASR instance URLs (supports failover)
# Examples for different setups:
# - Host machine: http://localhost:9000,http://localhost:9001
# - Docker container (bridge network): http://172.17.0.1:9000
# - Docker container (host network): http://localhost:9000
# - External server: http://whisper.example.com:9000
# Multiple instances for failover: http://localhost:9000,http://localhost:9001,http://backup-whisper:9000
WHISPER_ASR_URLS=http://localhost:9000
# Optional: Whisper output format (text, json, vtt, srt, tsv)
WHISPER_OUTPUT_FORMAT=text
# Optional: Enable voice activity detection filter
WHISPER_VAD_FILTER=true
# Optional: Language for transcription (auto-detect if not specified)
# WHISPER_LANGUAGE=en
# Voice Activation Configuration
# Phrase that triggers AI chat from voice messages (default: "hey jarvis")
# Examples: "hey computer", "assistant", "ai", "bot"
VOICE_ACTIVATION_PHRASE=hey jarvis

10
Dockerfile Normal file
View File

@@ -0,0 +1,10 @@
FROM python:3.11-slim
WORKDIR /app
COPY permissions.json .
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY signal_bot.py .
CMD ["python", "signal_bot.py"]

98
README.md Normal file
View File

@@ -0,0 +1,98 @@
# Shifra - Signal enabled confidential AI.
A Signal messenger bot that gives you AI agent in your chat.
## Features
- Chat with AI assistant via Signal messages
- Voice message transcription with Whisper ASR
- Multi-instance Whisper support with automatic failover
- Maintains conversation context
- Simple command interface
- Docker deployment ready
## Setup
1. Copy `.env.example` to `.env` and configure:
```bash
cp .env.example .env
```
2. Edit `.env` with your configuration:
- `SIGNAL_PHONE_NUMBER`: Your Signal phone number (e.g., +1234567890)
- `PRIVATEMODE_BASE_URL`: URL of PrivateMode.ai API (default: http://localhost:8080)
- `PRIVATEMODE_MODEL`: Optional - specific model to use (if not set, uses first available)
- `WHISPER_ASR_URLS`: Comma-separated list of Whisper ASR instances (e.g., http://localhost:9000,http://localhost:9001)
- `WHISPER_OUTPUT_FORMAT`: Output format for transcription (default: text)
- `WHISPER_VAD_FILTER`: Enable voice activity detection (default: true)
- `WHISPER_LANGUAGE`: Optional - language for transcription (auto-detect if not set)
3. Link Signal account (first time only):
```bash
docker compose run --rm signal-cli-rest-api signal-cli link -n "Signal Bot"
```
Follow the instructions to scan QR code with Signal app.
4. Start the bot:
```bash
docker compose up -d
```
## Usage
Send messages to the bot:
- `!chat <message>` - Chat with AI assistant
- `!clear` - Clear conversation history
- `!models` - List available AI models
- `!help` - Show available commands
- Any message without command prefix is treated as chat
- **Voice messages** - Send or forward voice memos for automatic transcription
## Available Models
The bot can use any model available through PrivateMode.ai API. Use `!models` command to see available models. Example models:
- `ibnzterrell/Meta-Llama-3.3-70B-Instruct-AWQ-INT4`
## Development
Run locally:
```bash
pip install -r requirements.txt
python signal_bot.py
```
## Architecture
- Uses `signalbot` library for Signal integration
- Connects to PrivateMode.ai Chat Completions API endpoint
- Integrates with Whisper ASR for voice transcription
- Maintains conversation context per sender (last 10 messages)
- Supports docker deployment with signal-cli-rest-api
- No authentication required (follows PrivateMode.ai approach)
## Whisper ASR Integration
The bot supports voice message transcription using Whisper ASR. The docker-compose configuration uses `network_mode: "host"` to ensure the Signal bot can access Whisper instances running on:
- **Host machine**: Use `http://localhost:9000` or `http://127.0.0.1:9000`
- **Docker containers (bridge network)**: Use `http://172.17.0.1:9000` (Docker's default bridge gateway)
- **Docker containers (host network)**: Use `http://localhost:9000`
- **External servers**: Use the server's URL (e.g., `http://whisper.example.com:9000`)
### Multiple Whisper Instances
Configure multiple Whisper instances for automatic failover:
```bash
WHISPER_ASR_URLS=http://localhost:9000,http://localhost:9001,http://backup-server:9000
```
If the first instance fails or is unavailable, the bot automatically tries the next one in the list.
### Voice Message Processing
1. User sends or forwards a voice message to the Signal chat
2. Bot detects the voice attachment
3. Audio is sent to the first available Whisper instance
4. Transcribed text is returned with a 📝 prefix
5. Transcription is stored in conversation history for context

34
docker-compose.yml Normal file
View File

@@ -0,0 +1,34 @@
services:
signal-bot:
build: .
env_file: .env
network_mode: "host"
environment:
- SIGNAL_SERVICE=127.0.0.1:18380
- SIGNAL_PHONE_NUMBER=${SIGNAL_PHONE_NUMBER}
- PRIVATEMODE_BASE_URL=${PRIVATEMODE_BASE_URL}
- PRIVATEMODE_MODEL=${PRIVATEMODE_MODEL}
- WHISPER_ASR_URLS=${WHISPER_ASR_URLS}
- WHISPER_OUTPUT_FORMAT=${WHISPER_OUTPUT_FORMAT:-text}
- WHISPER_VAD_FILTER=${WHISPER_VAD_FILTER:-true}
- WHISPER_LANGUAGE=${WHISPER_LANGUAGE:-}
volumes:
- ./.env:/app/.env
restart: unless-stopped
privatemode-proxy:
image: ghcr.io/edgelesssys/privatemode/privatemode-proxy:latest
environment:
- PRIVATEMODE_API_KEY=${PRIVATEMODE_API_KEY:-}
- PRIVATEMODE_CACHE_MODE=${PRIVATEMODE_CACHE_MODE:-none}
- PRIVATEMODE_CACHE_SALT=${PRIVATEMODE_CACHE_SALT:-}
entrypoint: ["/bin/privatemode-proxy"]
command: [
"--apiKey=${PRIVATEMODE_API_KEY}",
"--port=8080"
]
ports:
- "28082:8080"
restart: unless-stopped

24
example_permissions.json Normal file
View File

@@ -0,0 +1,24 @@
{
"roles": {
"admin": {
"description": "Full access to all commands and user management",
"permissions": ["*"]
},
"user": {
"description": "Standard user with chat access",
"permissions": ["chat", "clear", "models", "help"]
},
"guest": {
"description": "Limited access user",
"permissions": ["help"]
}
},
"users": {
"+123456789": {
"role": "admin",
"name": "Default Admin",
"added_by": "system",
"added_at": "2024-01-01T00:00:00Z"
}
}
}

5
requirements.txt Normal file
View File

@@ -0,0 +1,5 @@
signalbot==0.8.0
aiohttp==3.10.11
python-dotenv==1.0.1
pyyaml==6.0.2
watchdog==3.0.0

1006
signal_bot.py Normal file

File diff suppressed because it is too large Load Diff