A bot for Prosody (XMPP server) that executes bash scripts using commands in private messages. It is written in Python using the slixmpp library and runs in Docker.
погода, новости)ping, helpCreate a folder structure:
mkdir -p xmpp-bot/{scripts,data}
cd xmpp-bot
Create a configuration file .env:
cat > .env << EOF
[email protected]
XMPP_PASSWORD=your-secure-password
XMPP_SERVER=xmpp-prosody
XMPP_PORT=5222
EOF
Launch the container:
docker run -d \
--name xmpp-bot \
--env-file .env \
-v $(pwd)/scripts:/app/scripts:ro \
-v $(pwd)/bot.py:/app/bot.py:ro \ # IMPORTANT: mounting bot.py to customize the commands
--network your-xmpp-network \
your_login/xmpp-command-bot:latest
========= docker-compose.yaml ========
services:
xmpp-bot:
image: owl5053/xmpp_bot_slixmpp:latest
container_name: xmpp-bot
restart: unless-stopped
volumes:
- ./scripts:/app/scripts:ro # your bash scripts
- ./bot.py:/app/bot.py:ro # bot code (for quick edits)
- ./data:/app/data # bot data (optional)
- /etc/localtime:/etc/localtime:ro # to synchronize time with the server
- /etc/timezone:/etc/timezone:ro # to synchronize time with the server
environment:
- [email protected]
- XMPP_PASSWORD=super_password
- XMPP_SERVER=xmpp-prosody # name of the prosody container
- XMPP_PORT=5222
networks:
- xmpp-net
networks:
xmpp-net:
external: true
name: xmpp-net
Copy bot.py from container:
docker cp xmpp-bot:/app/bot.py ./bot.py
Edit/add scripts in the "scripts" directory
==== Command Configuration
All commands are configured in bot.py in the dictionary of self.commands:
python
self.commands = {
'погода': '/app/scripts/weather.sh', # bash-script
'новости': '/app/scripts/news.sh',
'ping': None,
'help': None,
}
Every script receives the sender's JID as its first argument ($1). This allows your scripts to personalize responses or send files back to the user.
| Command Example | Script Receives |
|---|---|
погода | $1 = [email protected] |
новости 5 | $1 = [email protected], $2 = 5 |
анекдот детский | $1 = [email protected], $2 = детский |
Example hello.sh script:
#!/bin/bash
# Get the sender's JID from the first argument
USER_JID="$1"
# Extract the username (part before @)
USERNAME=$(echo "$USER_JID" | cut -d'@' -f1)
echo "Hello, $USERNAME! Your JID is $USER_JID."
Important: Additional user arguments (e.g., 5 in новости 5) are passed to the script as $2, $3, and so on.
==== Adding new commands Create .sh script in the scripts folder/
Make it executable: chmod +x scripts/new_script.sh
Add the command to the self.commands dictionary in bot.py
Restart the bot: docker-compose restart
🔧 Environment variables
Variable Description Default value
XMPP_JID Full JID bots bot@<xmm_server>
XMPP_PASSWORD Password mandatory
XMPP_SERVER Address XMPP-server xmpp-prosody
XMPP_PORT Connection port 5222
📂 Project structure
xmpp-bot/
├── docker-compose.yaml
├── Dockerfile
├── bot.py
├── scripts/
│ ├── weather.sh
│ ├── news.sh
│ └── ...
└── data/
└── ...
📄 MIT License
If you want to assemble the image yourself: ======= dockerfile =======
FROM python:3.11-slim
RUN apt-get update && apt-get install -y bash curl wget libxml2-utils jq git vim && rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip
RUN pip install slixmpp beautifulsoup4 lxml # lxml для парсинга XML/HTML
WORKDIR /app
COPY bot.py .
RUN mkdir -p /app/scripts
# Create a symlink in the current directory if there are common commands in the scripts
RUN ln -sf /app/scripts/functions.sh /app/functions.sh
CMD ["python", "bot.py"]
Content type
Image
Digest
sha256:0f735d663…
Size
120.4 MB
Last updated
3 months ago
docker pull owl5053/xmpp_bot_slixmpp