发现一个信息推送小工具,ntfy。挺好用的,不需要我自己做的那个简陋版本了。
服务端是 Golang 开发的,然后官方支持的客户端:
- Phone
- Android
- iOS
- Web APP (没有看到源代码仓库)
- CLI
无需注册,客户端订阅指定主题,然后直接往这个主题推送消息就行了。
这是官网上的几个推送示例:
curl -d "Backup successful 😀" ntfy.sh/wuhan
curl -H "Title: Dogs are better than cats" -d "Oh my ..." ntfy.sh/wuhan
curl -H "Tags: horse,unicorn" -d "Unicorns are just horses with unique horns" ntfy.sh/wuhan
订阅与推送的相关接口文档,官网写得足够好了,非常容易集成。
项目完全开源,包括 Android / iOS 端,可以自己部署,也可以就是用托管服务。
免费套餐对于个人使用也是足够了的,每天 250 条消息。
小问题:
- 只有 Web APP 支持 Markdown,而且支持的语法比较少,不大够。
命令行
ntfy pub -t <title> -f <filepath> <topic> <message>
-> % ntfy
NAME:
ntfy - Simple pub-sub notification service
USAGE:
ntfy [OPTION..]
COMMANDS:
help, h Shows a list of commands or help for one command
Client commands:
publish, pub, send, trigger Send message via a ntfy server
subscribe, sub Subscribe to one or more topics on a ntfy server
GLOBAL OPTIONS:
--debug, -d enable debug logging (default: false) [$NTFY_DEBUG]
--trace enable tracing (very verbose, be careful) (default: false) [$NTFY_TRACE]
--no-log-dates, --no_log_dates disable the date/time prefix (default: false) [$NTFY_NO_LOG_DATES]
--log-level value, --log_level value set log level (default: "INFO") [$NTFY_LOG_LEVEL]
--log-level-overrides value, --log_level_overrides value [ --log-level-overrides value, --log_level_overrides value ] set log level overrides [$NTFY_LOG_LEVEL_OVERRIDES]
--log-format value, --log_format value set log format (default: "text") [$NTFY_LOG_FORMAT]
--log-file value, --log_file value set log file, default is STDOUT [$NTFY_LOG_FILE]
--help, -h show help
Try 'ntfy COMMAND --help' or https://ntfy.sh/docs/ for more information.
To report a bug, open an issue on GitHub: https://github.com/binwiederhier/ntfy/issues.
If you want to chat, simply join the Discord server (https://discord.gg/cT7ECsZj9w), or
the Matrix room (https://matrix.to/#/#ntfy:matrix.org).
ntfy 2.11.0 (Homebre), runtime go1.22.3, built at 2024-05-13T20:11:29Z
Copyright (C) 2022 Philipp C. Heckel, licensed under Apache License 2.0 & GPLv2
-> % ntfy pub --help
NAME:
ntfy publish - Send message via a ntfy server
USAGE:
ntfy publish [OPTIONS..] TOPIC [MESSAGE...]
ntfy publish [OPTIONS..] --wait-cmd COMMAND...
NTFY_TOPIC=.. ntfy publish [OPTIONS..] [MESSAGE...]
CATEGORY:
Client commands
DESCRIPTION:
Publish a message to a ntfy server.
Examples:
ntfy publish mytopic This is my message # Send simple message
ntfy send myserver.com/mytopic "This is my message" # Send message to different default host
ntfy pub -p high backups "Backups failed" # Send high priority message
ntfy pub --tags=warning,skull backups "Backups failed" # Add tags/emojis to message
ntfy pub --delay=10s delayed_topic Laterzz # Delay message by 10s
ntfy pub --at=8:30am delayed_topic Laterzz # Send message at 8:30am
ntfy pub -e phil@example.com alerts 'App is down!' # Also send email to phil@example.com
ntfy pub --click="https://reddit.com" redd 'New msg' # Opens Reddit when notification is clicked
ntfy pub --icon="http://some.tld/icon.png" 'Icon!' # Send notification with custom icon
ntfy pub --attach="http://some.tld/file.zip" files # Send ZIP archive from URL as attachment
ntfy pub --file=flower.jpg flowers 'Nice!' # Send image.jpg as attachment
ntfy pub -u phil:mypass secret Psst # Publish with username/password
ntfy pub --wait-pid 1234 mytopic # Wait for process 1234 to exit before publishing
ntfy pub --wait-cmd mytopic rsync -av ./ /tmp/a # Run command and publish after it completes
NTFY_USER=phil:mypass ntfy pub secret Psst # Use env variables to set username/password
NTFY_TOPIC=mytopic ntfy pub "some message" # Use NTFY_TOPIC variable as topic
cat flower.jpg | ntfy pub --file=- flowers 'Nice!' # Same as above, send image.jpg as attachment
ntfy trigger mywebhook # Sending without message, useful for webhooks
Please also check out the docs on publishing messages. Especially for the --tags and --delay options,
it has incredibly useful information: https://ntfy.sh/docs/publish/.
The default config file for all client commands is /etc/ntfy/client.yml (if root user),
or "~/Library/Application Support/ntfy/client.yml" for all other users.
OPTIONS:
--debug, -d enable debug logging (default: false) [$NTFY_DEBUG]
--trace enable tracing (very verbose, be careful) (default: false) [$NTFY_TRACE]
--no-log-dates, --no_log_dates disable the date/time prefix (default: false) [$NTFY_NO_LOG_DATES]
--log-level value, --log_level value set log level (default: "INFO") [$NTFY_LOG_LEVEL]
--log-level-overrides value, --log_level_overrides value [ --log-level-overrides value, --log_level_overrides value ] set log level overrides [$NTFY_LOG_LEVEL_OVERRIDES]
--log-format value, --log_format value set log format (default: "text") [$NTFY_LOG_FORMAT]
--log-file value, --log_file value set log file, default is STDOUT [$NTFY_LOG_FILE]
--config value, -c value client config file [$NTFY_CONFIG]
--title value, -t value message title [$NTFY_TITLE]
--message value, -m value message body [$NTFY_MESSAGE]
--priority value, -p value priority of the message (1=min, 2=low, 3=default, 4=high, 5=max) [$NTFY_PRIORITY]
--tags value, --tag value, -T value comma separated list of tags and emojis [$NTFY_TAGS]
--delay value, --at value, --in value, -D value delay/schedule message [$NTFY_DELAY]
--click value, -U value URL to open when notification is clicked [$NTFY_CLICK]
--icon value, -i value URL to use as notification icon [$NTFY_ICON]
--actions value, -A value actions JSON array or simple definition [$NTFY_ACTIONS]
--attach value, -a value URL to send as an external attachment [$NTFY_ATTACH]
--markdown, --md Message is formatted as Markdown (default: false) [$NTFY_MARKDOWN]
--filename value, --name value, -n value filename for the attachment [$NTFY_FILENAME]
--file value, -f value file to upload as an attachment [$NTFY_FILE]
--email value, --mail value, -e value also send to e-mail address [$NTFY_EMAIL]
--user value, -u value username[:password] used to auth against the server [$NTFY_USER]
--token value, -k value access token used to auth against the server [$NTFY_TOKEN]
--wait-pid value, --wait_pid value, --pid value wait until PID exits before publishing (default: 0) [$NTFY_WAIT_PID]
--wait-cmd, --wait_cmd, --cmd, --done run command and wait until it finishes before publishing (default: false) [$NTFY_WAIT_CMD]
--no-cache, --no_cache, -C do not cache message server-side (default: false) [$NTFY_NO_CACHE]
--no-firebase, --no_firebase, -F do not forward message to Firebase (default: false) [$NTFY_NO_FIREBASE]
--quiet, -q do not print message (default: false) [$NTFY_QUIET]
--help, -h show help
参考资料与拓展阅读
- 2021/11/20, 如何推送消息给手机