Sign inSign up

laoning666/synology-chat-bot

By laoning666

•Updated 10 months ago

https://github.com/laoning666/synology-chat-bot

Image
1

3.9K

laoning666/synology-chat-bot repository overview

⁠Synology Chat AI Assistant

An AI-powered chatbot for Synology Chat that enables users to interact directly with AI models (such as GPT) within their chat interface.

⁠Features

  • šŸ¤– AI-driven intelligent conversations
  • šŸ’¬ Seamless Synology Chat integration
  • šŸ”„ Conversation context maintenance
  • ⚔ Automatic message processing
  • šŸ•’ Session timeout management
  • šŸ” API call retry mechanism
  • šŸ”’ Webhook token validation
  • 🐳 Docker support

⁠Requirements

  • Synology Chat server
  • AI API access (e.g., OpenAI API key)
  • Docker

⁠Installation

⁠Using Docker
  1. Pull the image:
docker pull laoning666/synology-chat-bot:latest
  1. Run the container:
docker run -d \
  --name synology-chat-bot \
  -p 8008:8008 \
  -e CHAT_API_URL=YOUR_API_URL \
  -e CHAT_API_KEY=YOUR_API_KEY \
  -e CHAT_API_MODEL=YOUR_MODEL \
  -e SYNOLOGY_INCOMING_WEBHOOK_URL=YOUR_WEBHOOK_URL \
  -e SYNOLOGY_OUTGOING_WEBHOOK_TOKEN=YOUR_TOKEN \
  laoning666/synology-chat-bot:latest
  1. Copy .env.example to .env in your local directory

  2. Modify the environment variables in .env

  3. Run with the following docker-compose.yml:

version: '3.8'

services:
  synology-chat-bot:
    image: laoning666/synology-chat-bot
    container_name: synology-chat-bot
    ports:
      - "8008:8008"
    restart: unless-stopped

⁠Synology Chat Setup

  1. Create Bot
  • Click your profile picture in the top right corner
  • Select [Integration]
  • Click [Bots] tab
  • Click [+ Create] button to create a new bot
  1. Configure Webhook
  • In the bot details page, set [Outgoing Webhook] to http://your_server_ip:8008/webhook (Note: your_server_ip is the IP address of the server running the bot service)
  • Set [Incoming URL] as the container's SYNOLOGY_INCOMING_WEBHOOK_URL variable
  • Set [Token] as the container's SYNOLOGY_OUTGOING_WEBHOOK_TOKEN variable
  • Click [OK] to save all settings
⁠AI Interface Configuration
VariableDescriptionDefault
CHAT_API_URLAI API endpoint-
CHAT_API_KEYAPI authentication key-
CHAT_API_MODELAI model identifier-
CHAT_API_TEMPERATUREResponse randomness (0.0-1.0)0.7
CHAT_API_MAX_TOKENSMaximum response length4096
CHAT_API_SYSTEM_PROMPTAI system prompt"I'm an AI assistant ready to help you."
⁠Synology Chat Configuration
VariableDescriptionDefault
SYNOLOGY_INCOMING_WEBHOOK_URLWebhook URL for sending messages-
SYNOLOGY_OUTGOING_WEBHOOK_TOKENToken for validating incoming webhooks-
⁠Server Configuration
VariableDescriptionDefault
SERVER_HOSTServer host address0.0.0.0
SERVER_PORTServer port8008
SERVER_DEBUGDebug modeFalse
⁠Session Settings
VariableDescriptionDefault
CONVERSATION_MAX_HISTORYMaximum conversation history entries10
CONVERSATION_TIMEOUTSession timeout (seconds)1800
CONVERSATION_TYPING_TEXTTyping indicator text...
⁠HTTP Client Settings
VariableDescriptionDefault
HTTP_TIMEOUTHTTP request timeout (seconds)30
HTTP_MAX_RETRIESMaximum retry attempts3

⁠Synology Chat Setup Steps

  1. Create Incoming Webhook:

    • Open Synology Chat
    • Go to Integration -> Incoming Webhook
    • Create a new webhook and copy the URL
    • Set the URL as SYNOLOGY_INCOMING_WEBHOOK_URL
  2. Create Outgoing Webhook:

    • Go to Integration -> Outgoing Webhook
    • Create a new webhook
    • Set URL to your bot's endpoint (e.g., http://your-server:8008/webhook⁠)
    • Generate and copy the token
    • Set the token as SYNOLOGY_OUTGOING_WEBHOOK_TOKEN

⁠Usage

  1. Install the project
  2. Add the bot to Synology Chat
  3. Send messages in the channel to interact with AI

⁠Development Guide

⁠Project Structure
synology-chat-bot/
ā”œā”€ā”€ app.py                 # Application entry
ā”œā”€ā”€ config/
│   └── settings.py       # Configuration management
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ bot/
│   │   ā”œā”€ā”€ chat_manager.py     # Chat session management
│   │   └── message_handler.py  # Message processing
│   ā”œā”€ā”€ models/
│   │   └── conversation.py     # Session state
│   └── utils/
│       └── http_client.py      # HTTP client utilities
ā”œā”€ā”€ Dockerfile            # Docker configuration
ā”œā”€ā”€ requirements.txt      # Python dependencies
└── .env                 # Environment variables
⁠Contributing
  1. Fork the project
  2. Create a feature branch (git checkout -b feature/NewFeature)
  3. Commit your changes (git commit -m 'Add new feature')
  4. Push to the branch (git push origin feature/NewFeature)
  5. Create a Pull Request

⁠FAQ

Q: How to modify the AI model's response style? A: Customize the AI's system prompt by modifying the CHAT_API_SYSTEM_PROMPT environment variable.

Q: Will data be lost after session timeout? A: Yes, expired sessions are automatically cleared. Adjust CONVERSATION_TIMEOUT to modify the timeout duration.

Q: Which AI models are supported? A: Any model compatible with the OPEN API format, including OpenAI's GPT series, Claude, etc.

Q: How is message security ensured? A: The system uses webhook token validation and supports HTTPS encrypted transmission.

Q: Is streaming output supported? A: No, as Synology Chat doesn't support this feature.

⁠Security Notes

  1. Securely store all API keys and webhook tokens
  2. Recommended for internal network deployment
  3. Regularly update dependencies to patch potential security vulnerabilities
  4. Use environment variables for sensitive configurations
  5. Enable HTTPS for encrypted data transmission

⁠License

This project is licensed under the MIT License - see the LICENSE file for details

Tag summary

Content type

Image

Digest

sha256:4a7c1245c…

Size

53.5 MB

Last updated

10 months ago

docker pull laoning666/synology-chat-bot