mirror of
https://github.com/caronc/apprise.git
synced 2024-12-04 05:54:35 +01:00
Page:
DemoPlugin_Basic
Pages
CLI_Usage
DemoPlugin_Basic
DemoPlugin_WebRequest
Development_API
Development_Apprise_Details
Development_Contribution
Development_LogCapture
Home
Notification_Graveyard
Notify_Custom_Form
Notify_Custom_JSON
Notify_Custom_XML
Notify_Revolt
Notify_africas_talking
Notify_apprise_api
Notify_aprs
Notify_bark
Notify_boxcar
Notify_bulksms
Notify_bulkvs
Notify_burst_sms
Notify_chantify
Notify_clicksend
Notify_d7networks
Notify_dapnet
Notify_dbus
Notify_dingtalk
Notify_discord
Notify_email Fastmail
Notify_email
Notify_emby
Notify_enigma2
Notify_faast
Notify_fcm
Notify_feishu
Notify_flock
Notify_freemobile
Notify_gitter
Notify_gnome
Notify_googlechat
Notify_gotify
Notify_growl
Notify_guilded
Notify_homeassistant
Notify_httpsms
Notify_ifttt
Notify_join
Notify_kavenegar
Notify_kodi
Notify_kumulos
Notify_lametric
Notify_line
Notify_lunasea
Notify_macosx
Notify_mailgun
Notify_mastodon
Notify_matrix
Notify_mattermost
Notify_messagebird
Notify_misskey
Notify_mqtt
Notify_msg91
Notify_msteams
Notify_nexmo
Notify_nextcloud
Notify_nextcloudtalk
Notify_notica
Notify_notifiarr
Notify_notifico
Notify_ntfy
Notify_office365
Notify_onesignal
Notify_opsgenie
Notify_pagerduty
Notify_pagertree
Notify_parseplatform
Notify_plivo
Notify_popcornnotify
Notify_prowl
Notify_pushalot
Notify_pushbullet
Notify_pushdeer
Notify_pushed
Notify_pushjet
Notify_pushme
Notify_pushover
Notify_pushsafer
Notify_pushy
Notify_reddit
Notify_rocketchat
Notify_rsyslog
Notify_ryver
Notify_sendgrid
Notify_serverchan
Notify_ses
Notify_seven
Notify_sfr
Notify_signal
Notify_simplepush
Notify_sinch
Notify_slack
Notify_sms_manager
Notify_smseagle
Notify_smtp2go
Notify_sns
Notify_sparkpost
Notify_splunk
Notify_spontit
Notify_streamlabs
Notify_stride
Notify_synology_chat
Notify_syslog
Notify_techulus
Notify_telegram
Notify_threema
Notify_toasty
Notify_twilio
Notify_twist
Notify_twitter
Notify_voipms
Notify_wecombot
Notify_whatsapp
Notify_windows
Notify_workflows
Notify_wxpusher
Notify_wxteams
Notify_xbmc
Notify_xmpp
Notify_zulip
Sponsors
Troubleshooting
URLBasics
config
config_text
config_yaml
decorator_notify
persistent_storage
showcase
4
DemoPlugin_Basic
Chris Caron edited this page 2024-05-24 21:12:51 -04:00
Table of Contents
A Basic Apprise Notification Example
This example shows a basic template of how one might build a Notification Service that does a task as simple as writing to stdout
(Standard Out)
It's very important that the filename apprise/plugins/service.py
does not align with the class name inside of it. In this example, the class is NotifyDemo
. So perhaps a good filename might be apprise/plugins/demo.py
.
The Code
# -*- coding: utf-8 -*-
from .base import NotifyBase
from ..locale import gettext_lazy as _
from ..common import NotifyType
class NotifyDemo(NotifyBase):
"""
A Sample/Demo Notifications
"""
# The default descriptive name associated with the Notification
# _() allows us to support future (language) translations
service_name = _('Apprise Demo Notification')
# The default protocol/schema
# This will be what triggers your service to be activated when
# protocol:// is specified (in example demo:// will activate
# this service).
protocol = 'demo'
# A URL that takes you to the setup/help of the specific protocol
# This is for new-comers who will want to learn how they can
# use your service. Ideally you should point to somewhere on
# the 'https://github.com/caronc/apprise/wiki/
setup_url = 'https://github.com/caronc/apprise/wiki/Notify_Demo'
# This disables throttling by default for this simple plugin.
request_rate_per_sec = 0
#
# Templating Section
#
# 1. `templates`: Identify the way you can use your plugin.
# This example is rather simple, so there isn't really much to do
# here. Check out the other demo's to see where this gets a bit more
# advanced.
#
templates = (
'{schema}://',
)
# For the reasons above, we only need to identify apikey here:
def __init__(self, **kwargs):
"""
Initialize Demo Object
"""
# Always call super() so that parent clases can set up. Make
# sure to only pass in **kwargs
super(NotifyDemo, self).__init__(**kwargs)
#
# Now you can write any initialization you want; if you have nothing to
# initialize then you can skip the definition of the __init__()
# function all together.
#
return
def url(self, *args, **kwargs):
"""
Returns the URL built dynamically based on specified arguments.
"""
# Always call self.url_parameters() at some point.
# This allows your Apprise URL to handle the common/global
# parameters that are used by Apprise. This is for consistency
# more than anything:
params = self.url_parameters(*args, **kwargs)
# Basically we need to write back a URL that looks exactly like
# the one we parsed to build from scratch.
# If we can parse a URL and rebuild it the way it once was,
# Administrators who use Apprise don't need to pay attention to all
# of your custom and unique tokens (from on service to another).
# they only need to store Apprise URL's in their database.
return '{schema}://?{params}'.format(
schema=self.protocol,
params=self.urlencode(params),
)
def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
"""
Perform Demo Notification
"""
#
# Always call throttle before any remote server i/o is made
#
self.throttle()
# Perform your notification here; in this example, we just send the
# output to `stdout`:
print('{type} - {title} - {body}'.format(
type=notify_type, title=title, body=body))
return True
@staticmethod
def parse_url(url):
"""
Parses the URL and returns enough arguments that can allow
us to re-instantiate this object.
"""
# If you're URL does not define what is considered a valid host after
# your' schema/protocol such as this plugin example (demo://) where the
# hostname isn't even required, then set the verify_host to False
results = NotifyBase.parse_url(url, verify_host=False)
if not results:
# We're done early as we couldn't parse the URL
return results
# Handle any additional parsing here if you want
# make sure to write all your changes/updates back into the results
# dictionary
# The contents of our results (a dictionary) will become
# the arguments passed into the __init__() function we defined above.
return results
Testing
You can test your NotifyDemo class using the demo://
schema:
# using the `apprise` found in the local bin directory allows you to test
# the new plugin right away. Use the `demo://` schema we defined. You can also
# set a couple of extra `-v` switches to add some verbosity to the output:
./bin/apprise -vvv -t test -b message demo://