This project based on Bun, which needs to be installed globally:
npm install -g bun
To install dependencies:
bun install
To start bot service:
bun run server
Build Docker image:
docker build --pull -t telly-bot:latest .
Use the image to spin up a container:
docker run -d -p 3300:3300 --name telly-bot telly-bot:latest
Create .env
in root directory to hold environment variables.
Required environment variables:
# Telegram bot token
TELEGRAM_BOT_TOKEN=XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXX
Optional common environment variables:
# Listening port of service. Default to `3300`
PORT=3300
# Secret token to execute private (POST) API
API_SECRET_TOKEN=YOUR_SECRET_TOKEN
# Telegram chat that receives monitoring messages and so on. The chat between bot and yourself is recommended
TELEGRAM_CHAT_ID_ADMIN=TARGET_CHAT_ID
Telly bot chooses MongoDB as the provider of database service. Some features require connecting to MongoDB.
# MongoDB uri
MONGO_URI=mongodb://username:password@127.0.0.1:27017/telly-bot
Don't worry, Telly bot can work without MongoDB.
# AList address
ALIST_URL=http://127.0.0.1:5244
# AList login username
ALIST_USERNAME=YOUR_ALIST_USERNAME
# AList login password
ALIST_PASSWORD=YOUR_ALIST_PASSWORD
# Custom service routes
ALIST_ROUTES=[{"route":"/random-img","path":"/path/to/img-dir","type":"random-image"}]
When visit http://127.0.0.1:3300/alist/random-img
or send /random_img
to bot, you will get a random image from the /path/to/img-dir
directory in AList.
Notes: If directory /path/to/img-dir
has too many files, the first request in a certain time interval may failed. This is due to AList's file cache mechanism (default to 30 minutes, can be configured on the AList management page), please wait a few seconds and try again.
Adapt to ChatAnywhere.
# ChatGPT model version. Default to `gpt-3.5-turbo-0125`
CHATGPT_MODEL=gpt-3.5-turbo-0125
# ChatAnywhere API key
CHATGPT_API_KEY=YOUR_CHATGPT_API_KEY
# Telegram chat that receives key usage
TELEGRAM_CHAT_ID_CHATGPT_BALANCE=TARGET_CHAT_ID
Send /chat ${message}
to play with a cat girl! You can also:
/chat_cat_girl ${message}
: Same to/chat ${message}
./chat_dan ${message}
: Chat with an unlimited AI agent named Dan./chat_poet ${message}
: Talk with a poet who writes impressive words.
Visit http://127.0.0.1:3300/chatgpt/balance
to view key usage. If TELEGRAM_CHAT_ID_CHATGPT_BALANCE
(higher priority) or TELEGRAM_CHAT_ID_ADMIN
is set, key usage will also be forwarded to target chat every 9 AM and 9 PM.
GITHUB_PERSONAL_ACCESS_TOKEN=YOUR_GITHUB_PERSONAL_ACCESS_TOKEN
Based on Minecraft Server Status.
MINECRAFT_SERVER_HOST=example.domain.com
TELEGRAM_CHAT_ID_MINECRAFT_MONITOR=TARGET_CHAT_ID
axios.get("http://127.0.0.1:3300/bot/status");
Send custom message to target chat. Content should be parsable by HTML mode: https://core.telegram.org/bots/api#html-style.
axios.post(
"http://127.0.0.1:3300/bot/send-message",
{
content: "custom message",
chatId: TELEGRAM_CHAT_ID_ADMIN,
},
{
headers: { Authorization: API_SECRET_TOKEN },
},
);
If chatId
is blank, TELEGRAM_CHAT_ID_ADMIN
will be used.
axios.get("http://127.0.0.1:3300/chatgpt/balance");
axios.post(
"http://127.0.0.1:3300/chatgpt/chat",
{
content: "custom message",
},
{
headers: { Authorization: API_SECRET_TOKEN },
},
);
To develop:
bun run start
To lint files and fix code syntax:
# Require a Node.js >=20.11.0 to get typing check
bun run lint
# Auto fix
bun run lint:fix