@o25.16pm.0510/multi-notify
v1.260513.11916
Published
CLI gửi thông báo đa kênh; kênh nào đủ cấu hình .env thì gửi, thiếu thì tự bỏ qua.
Maintainers
Readme
Multi Env Notify CLI
CLI gửi thông báo đa kênh theo nguyên tắc:
Kênh nào đủ cấu hình
.envthì gửi. Kênh nào thiếu cấu hình thì tự bỏ qua.
Bản này được cấu trúc theo hướng dễ public lên npmjs: không cần build TypeScript, chạy trực tiếp bằng Node.js ESM, có bin command.
Kênh hỗ trợ
- Telegram: nhiều bot, nhiều group/chat, topic/thread.
- Email SMTP: một hoặc nhiều cấu hình SMTP.
- Slack Incoming Webhook.
- Discord Incoming Webhook.
- Twilio SMS.
- ntfy HTTP publish.
- Generic Webhook.
Cài đặt dev
npm run install
cp .env.example .env
npm run dev -- --title "Test" --message "Xin chào" --level successChạy CLI
node bin/multi-notify.js --title "Deploy OK" --message "Production đã deploy xong" --level successSau khi publish npm:
npx multi-env-notify-cli --title "Deploy OK" --message "Production đã deploy xong" --level successHoặc cài global:
npm i -g multi-env-notify-cli
multi-notify --title "Hello" --message "Tin nhắn từ CLI"Quy tắc Telegram
1 bot gửi 1 group/chat
MULTI_NOTIFY_TELEGRAM_BOT_TOKEN=123456:ABC
MULTI_NOTIFY_TELEGRAM_CHAT_ID=-1001111111111
MULTI_NOTIFY_TELEGRAM_PARSE_MODE=HTML1 bot gửi nhiều group/chat
MULTI_NOTIFY_TELEGRAM_BOT_TOKEN=123456:ABC
MULTI_NOTIFY_TELEGRAM_CHAT_ID_1=-1001111111111
MULTI_NOTIFY_TELEGRAM_CHAT_ID_1_NAME=ops-group
MULTI_NOTIFY_TELEGRAM_CHAT_ID_2=-1002222222222
MULTI_NOTIFY_TELEGRAM_CHAT_ID_2_NAME=dev-groupNhiều bot, mỗi bot gửi nhiều group/chat
MULTI_NOTIFY_TELEGRAM_BOT_1_NAME=ops-bot
MULTI_NOTIFY_TELEGRAM_BOT_1_TOKEN=111111:AAA
MULTI_NOTIFY_TELEGRAM_BOT_1_CHAT_ID_1=-1001111111111
MULTI_NOTIFY_TELEGRAM_BOT_1_CHAT_ID_1_NAME=ops-group
MULTI_NOTIFY_TELEGRAM_BOT_1_CHAT_ID_2=-1002222222222
MULTI_NOTIFY_TELEGRAM_BOT_1_CHAT_ID_2_NAME=dev-group
MULTI_NOTIFY_TELEGRAM_BOT_2_NAME=business-bot
MULTI_NOTIFY_TELEGRAM_BOT_2_TOKEN=222222:BBB
MULTI_NOTIFY_TELEGRAM_BOT_2_CHAT_ID_1=-1003333333333
MULTI_NOTIFY_TELEGRAM_BOT_2_CHAT_ID_1_NAME=business-groupGửi vào topic/forum của Telegram group
MULTI_NOTIFY_TELEGRAM_BOT_1_TOKEN=111111:AAA
MULTI_NOTIFY_TELEGRAM_BOT_1_CHAT_ID_1=-1001111111111
MULTI_NOTIFY_TELEGRAM_BOT_1_CHAT_ID_1_THREAD_ID=12345Dạng danh sách nhanh
MULTI_NOTIFY_TELEGRAM_BOT_3_TOKEN=333333:CCC
MULTI_NOTIFY_TELEGRAM_BOT_3_CHAT_IDS=-1001111111111,-1002222222222ntfy
Cấu hình tối thiểu:
MULTI_NOTIFY_NTFY_TOPIC=my-alert-topicTùy chọn:
MULTI_NOTIFY_NTFY_SERVER_URL=https://ntfy.sh
MULTI_NOTIFY_NTFY_TOKEN=
MULTI_NOTIFY_NTFY_PRIORITY=default
MULTI_NOTIFY_NTFY_TAGS=warning,computer
MULTI_NOTIFY_NTFY_CLICK_URL=https://example.comCó thể gửi riêng ntfy:
multi-notify --only ntfy --title "Test" --message "Xin chào ntfy"CLI options
multi-notify \
--title "Cảnh báo" \
--message "Dung lượng ổ đĩa vượt 90%" \
--level warning \
--meta server=prod-01 \
--meta disk=92%| Option | Mô tả |
| ----------------------- | ---------------------------------------------- |
| --title | Tiêu đề tin nhắn |
| --message | Nội dung tin nhắn |
| --level | debug, info, success, warning, error |
| --meta key=value | Thêm metadata, dùng được nhiều lần |
| --env-file .env.prod | Load file env tùy chọn |
| --json | In kết quả dạng JSON |
| --only telegram,slack | Chỉ gửi một số provider |
| --dry-run | Chỉ hiển thị target sẽ gửi, không gửi thật |
| --list-targets | Liệt kê target đang detect được từ env |
Kiểm tra target trước khi gửi
multi-notify --list-targetsChỉ kiểm tra Telegram:
multi-notify --only telegram --list-targetsDry-run:
multi-notify --only telegram --dry-run --title "Test" --message "Không gửi thật"Publish npm
- Sửa
nametrongpackage.jsonnếu tênmulti-env-notify-cliđã bị dùng. - Login npm:
npm login- Kiểm tra gói publish:
npm pack --dry-run- Publish:
npm publish --access publicBảo mật
- Không commit
.env. - Không đưa token thật vào README, test, fixture hoặc
.env.example. - Token Telegram/Twilio/Slack/Discord nếu lộ phải rotate ngay.
