推送通知几乎适用于每个平台!
apprise的Python项目详细描述
ap·prise/verb
通知或告诉(某人)使某人意识到某事。
apprise允许您向apprise发送通知,这些通知几乎是我们今天可以使用的所有最流行的notification服务,例如:电报、不和、松弛、twitter等。
- 一个通知库来管理它们。
- 一种常见且直观的通知语法。
- 支持处理图像(到将接受图像的通知服务)。
希望提供通知服务的系统所有者不再需要研究每一个新的消息。他们只需要包含这一个库,然后他们就可以立即访问我们今天可以使用的几乎所有通知服务。
希望从计划任务或命令行发送通知的系统管理员也不再需要为作业找到正确的工具。本产品附带的apprise脚本中已经包装并支持了所有内容。
支持的通知
此部分标识此库支持的所有服务。Check out the wiki for more information on the supported modules here。
热门通知服务
下表列出了此工具支持的服务和一些示例服务url,您需要使用这些url才能利用它。
Notification Service | Service ID | Default Port | Example Syntax |
---|---|---|---|
Boxcar | boxcar:// | (TCP) 443 | boxcar://hostname boxcar://hostname/@tag boxcar://hostname/device_token boxcar://hostname/device_token1/device_token2/device_tokenN boxcar://hostname/@tag/@tag2/device_token |
Discord | discord:// | (TCP) 443 | discord://webhook_id/webhook_token discord://avatar@webhook_id/webhook_token |
Dbus | dbus:// qt:// glib:// kde:// | n/a | dbus:// qt:// glib:// kde:// |
Emby | emby:// or embys:// | (TCP) 8096 | emby://user@hostname/ emby://user:password@hostname |
Faast | faast:// | (TCP) 443 | faast://authorizationtoken |
Flock | flock:// | (TCP) 443 | flock://token flock://botname@token flock://app_token/u:userid flock://app_token/g:channel_id flock://app_token/u:userid/g:channel_id |
Gitter | gitter:// | (TCP) 443 | gitter://token/room gitter://token/room1/room2/roomN |
Gnome | gnome:// | n/a | gnome:// |
Gotify | gotify:// or gotifys:// | (TCP) 80 or 443 | gotify://hostname/token gotifys://hostname/token?priority=high |
Growl | growl:// | (UDP) 23053 | growl://hostname growl://hostname:portno growl://password@hostname growl://password@hostname:port Note: you can also use the get parameter version which can allow the growl request to behave using the older v1.x protocol. An example would look like: growl://hostname?version=1 |
IFTTT | ifttt:// | (TCP) 443 | ifttt://webhooksID/Event ifttt://webhooksID/Event1/Event2/EventN ifttt://webhooksID/Event1/?+Key=Value ifttt://webhooksID/Event1/?-Key=value1 |
Join | join:// | (TCP) 443 | join://apikey/device join://apikey/device1/device2/deviceN/ join://apikey/group join://apikey/groupA/groupB/groupN join://apikey/DeviceA/groupA/groupN/DeviceN/ |
KODI | kodi:// or kodis:// | (TCP) 8080 or 443 | kodi://hostname kodi://user@hostname kodi://user:password@hostname:port |
Mailgun | mailgun:// | (TCP) 443 | mailgun://user@hostname/apikey mailgun://user@hostname/apikey/email mailgun://user@hostname/apikey/email1/email2/emailN mailgun://user@hostname/apikey/?name="From%20User" |
Matrix | matrix:// or matrixs:// | (TCP) 80 or 443 | matrix://hostname matrix://user@hostname matrixs://user:pass@hostname:port/#room_alias matrixs://user:pass@hostname:port/!room_id matrixs://user:pass@hostname:port/#room_alias/!room_id/#room2 matrixs://token@hostname:port/?webhook=matrix matrix://user:token@hostname/?webhook=slack&format=markdown |
Mattermost | mmost:// | (TCP) 8065 | mmost://hostname/authkey mmost://hostname:80/authkey mmost://user@hostname:80/authkey mmost://hostname/authkey?channel=channel mmosts://hostname/authkey mmosts://user@hostname/authkey |
Microsoft Teams | msteams:// | (TCP) 443 | msteams://TokenA/TokenB/TokenC/ |
Prowl | prowl:// | (TCP) 443 | prowl://apikey prowl://apikey/providerkey |
PushBullet | pbul:// | (TCP) 443 | pbul://accesstoken pbul://accesstoken/#channel pbul://accesstoken/A_DEVICE_ID pbul://accesstoken/email@address.com pbul://accesstoken/#channel/#channel2/email@address.net/DEVICE |
Pushjet | pjet:// or pjets:// | (TCP) 80 or 443 | pjet://secret@hostname pjet://secret@hostname:port pjets://secret@hostname pjets://secret@hostname:port |
Push (Techulus) | push:// | (TCP) 443 | push://apikey/ |
Pushed | pushed:// | (TCP) 443 | pushed://appkey/appsecret/ pushed://appkey/appsecret/#ChannelAlias pushed://appkey/appsecret/#ChannelAlias1/#ChannelAlias2/#ChannelAliasN pushed://appkey/appsecret/@UserPushedID pushed://appkey/appsecret/@UserPushedID1/@UserPushedID2/@UserPushedIDN |
Pushover | pover:// | (TCP) 443 | pover://user@token pover://user@token/DEVICE pover://user@token/DEVICE1/DEVICE2/DEVICEN Note: you must specify both your user_id and token |
Rocket.Chat | rocket:// or rockets:// | (TCP) 80 or 443 | rocket://user:password@hostname/RoomID/Channel rockets://user:password@hostname:443/#Channel1/#Channel1/RoomID rocket://user:password@hostname/#Channel rocket://webhook@hostname rockets://webhook@hostname/@User/#Channel |
Ryver | ryver:// | (TCP) 443 | ryver://Organization/Token ryver://botname@Organization/Token |
Slack | slack:// | (TCP) 443 | slack://TokenA/TokenB/TokenC/ slack://TokenA/TokenB/TokenC/Channel slack://botname@TokenA/TokenB/TokenC/Channel slack://user@TokenA/TokenB/TokenC/Channel1/Channel2/ChannelN |
Telegram | tgram:// | (TCP) 443 | tgram://bottoken/ChatID tgram://bottoken/ChatID1/ChatID2/ChatIDN |
twitter:// | (TCP) 443 | twitter://CKey/CSecret/AKey/ASecret twitter://user@CKey/CSecret/AKey/ASecret twitter://CKey/CSecret/AKey/ASecret/User1/User2/User2 twitter://CKey/CSecret/AKey/ASecret?mode=tweet | |
Twist | twist:// | (TCP) 443 | twist://pasword:login twist://password:login/#channel twist://password:login/#team:channel twist://password:login/#team:channel1/channel2/#team3:channel |
XBMC | xbmc:// or xbmcs:// | (TCP) 8080 or 443 | xbmc://hostname xbmc://user@hostname xbmc://user:password@hostname:port |
XMPP | xmpp:// or xmpps:// | (TCP) 5222 or 5223 | xmpp://password@hostname xmpp://user:password@hostname xmpps://user:password@hostname:port?jid=user@hostname/resource xmpps://password@hostname/target@myhost, target2@myhost/resource |
Windows Notification | windows:// | n/a | windows:// |
Webex Teams (Cisco) | wxteams:// | (TCP) 443 | wxteams://Token |
Zulip Chat | zulip:// | (TCP) 443 | zulip://botname@Organization/Token zulip://botname@Organization/Token/Channel zulip://botname@Organization/Token/Email |
短信通知支持
Notification Service | Service ID | Default Port | Example Syntax |
---|---|---|---|
AWS SNS | sns:// | (TCP) 443 | sns://AccessKeyID/AccessSecretKey/RegionName/+PhoneNo sns://AccessKeyID/AccessSecretKey/RegionName/+PhoneNo1/+PhoneNo2/+PhoneNoN sns://AccessKeyID/AccessSecretKey/RegionName/Topic sns://AccessKeyID/AccessSecretKey/RegionName/Topic1/Topic2/TopicN |
D7 Networks | d7sms:// | (TCP) 443 | d7sms://user:pass@PhoneNo d7sms://user:pass@ToPhoneNo1/ToPhoneNo2/ToPhoneNoN |
Nexmo | nexmo:// | (TCP) 443 | nexmo://ApiKey:ApiSecret@FromPhoneNo nexmo://ApiKey:ApiSecret@FromPhoneNo/ToPhoneNo nexmo://ApiKey:ApiSecret@FromPhoneNo/ToPhoneNo1/ToPhoneNo2/ToPhoneNoN/ |
Twilio | twilio:// | (TCP) 443 | twilio://AccountSid:AuthToken@FromPhoneNo twilio://AccountSid:AuthToken@FromPhoneNo/ToPhoneNo twilio://AccountSid:AuthToken@FromPhoneNo/ToPhoneNo1/ToPhoneNo2/ToPhoneNoN/ twilio://AccountSid:AuthToken@ShortCode/ToPhoneNo twilio://AccountSid:AuthToken@ShortCode/ToPhoneNo1/ToPhoneNo2/ToPhoneNoN/ |
电子邮件支持
Service ID | Default Port | Example Syntax |
---|---|---|
mailto:// | (TCP) 25 | mailto://userid:pass@domain.com mailto://domain.com?user=userid&pass=password mailto://domain.com:2525?user=userid&pass=password mailto://user@gmail.com&pass=password mailto://mySendingUsername:mySendingPassword@example.com?to=receivingAddress@example.com mailto://userid:password@example.com?smtp=mail.example.com&from=noreply@example.com&name=no%20reply |
mailtos:// | (TCP) 587 | mailtos://userid:pass@domain.com mailtos://domain.com?user=userid&pass=password mailtos://domain.com:465?user=userid&pass=password mailtos://user@hotmail.com&pass=password mailtos://mySendingUsername:mySendingPassword@example.com?to=receivingAddress@example.com mailtos://userid:password@example.com?smtp=mail.example.com&from=noreply@example.com&name=no%20reply |
apprise内置了一些电子邮件服务(如yahoo、fastmail、hotmail、gmail等),大大简化了mailto:/服务。查看更多详细信息here。
自定义通知
Post Method | Service ID | Default Port | Example Syntax |
---|---|---|---|
JSON | json:// or jsons:// | (TCP) 80 or 443 | json://hostname json://user@hostname json://user:password@hostname:port json://hostname/a/path/to/post/to |
XML | xml:// or xmls:// | (TCP) 80 or 443 | xml://hostname xml://user@hostname xml://user:password@hostname:port xml://hostname/a/path/to/post/to |
安装
最简单的方法是从pypi安装这个包:
pip install apprise
命令行
这个包还提供了一个名为apprise的小型命令行工具。如果您知道要通知的服务器url,只需在命令行中提供它们,然后按以下方式发送通知:
# Send a notification to as many servers as you want# as you can easily chain one after another: apprise -t 'my title' -b 'my notification body'\'mailto://myemail:mypass@gmail.com'\'pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b'# If you don't specify a --body (-b) then stdin is used allowing# you to use the tool as part of your every day administration: cat /proc/cpuinfo | apprise -t 'cpu info'\'mailto://myemail:mypass@gmail.com'# The title field is totally optional uptime | apprise \'discord:///4174216298/JHMHI8qBe7bk2ZwO5U711o3dV_js'
配置文件
没有人想在命令行上显示所有人的凭据。没问题apprise也支持配置文件。它可以处理特定的YAML format或非常简单的TEXT format。您也可以通过http查询来获取这些配置文件!有关APVISE配置的更多信息,请参见here
# By default now if no url or configuration is specified aprise will# peek for this data in:# ~/.apprise# ~/.apprise.yml# ~/.config/apprise# ~/.config/apprise.yml# Windows users can store their default configuration files here:# %APPDATA%/Apprise/apprise# %APPDATA%/Apprise/apprise.yml# %LOCALAPPDATA%/Apprise/apprise# %LOCALAPPDATA%/Apprise/apprise.yml# If you loaded one of those files, your command line gets really easy: apprise -t 'my title' -b 'my notification body'# Know the location of the configuration source? No problem, just# specify it. apprise -t 'my title' -b 'my notification body'\ --config=/path/to/my/config.yml # Got lots of configuration locations? No problem, specify them all: apprise -t 'my title' -b 'my notification body'\ --config=/path/to/my/config.yml \ --config=https://localhost/my/apprise/config
开发人员
要从python应用程序内部发送通知,请执行以下操作:
importapprise# Create an Apprise instanceapobj=apprise.Apprise()# Add all of the notification services by their server url.# A sample email notificationapobj.add('mailto://myemail:mypass@gmail.com')# A sample pushbullet notificationapobj.add('pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b')# Then notify these services any time you desire. The below would# notify all of the services loaded into our Apprise object.apobj.notify(body='what a great notification service!',title='my notification title',)
配置文件
开发人员也需要访问配置文件。好消息是,它们的使用只涉及声明另一个对象(称为appriseconfig),该对象可以摄取apprise。您还可以自由地混合和匹配配置和通知条目,只要您愿意!
importapprise# Create an Apprise instanceapobj=apprise.Apprise()# Create an Config instanceconfig=apprise.AppriseConfig()# Add a configuration source:config.add('/path/to/my/config.yml')# Add another...config.add('https://myserver:8080/path/to/config')# Make sure to add our config into our apprise objectapobj.add(config)# You can mix and match; add an entry directly if you want too# In this entry we associate the 'admin' tag with our notificationapobj.add('mailto://myemail:mypass@gmail.com',tag='admin')# Then notify these services any time you desire. The below would# notify all of the services loaded into our Apprise object; this includes# all items identified in the configuration files.apobj.notify(body='what a great notification service!',title='my notification title',)# If you're using tagging, then you can load all of your notifications# but only selectively notify the ones associated with one or more # matched tags:apobj.notify(body='send a notification to our admin group'title='Attention Admins',# notify any services tagged with the 'admin' tagtag='admin',)
如果您有兴趣阅读有关如何自定义通知的此方法和其他方法的更多信息,请访问https://github.com/caronc/apprise/wiki/Development_API