You can also write your own backends, where a backend is nothing but a thread that listens for messages on a certain channel and pokes the main app whenever it receives one.
-
Create your backend directory under
platypush/backend
(e.g.voicemail
) -
In the case above,
platypush.backend.voicemail
will be your package name. -
Create an
__init__.py
underplatypush/backend/voicemail
. -
If your module is
voicemail
, then its main class should be namedVoicemailBackend
. -
The configuration for your module will be read from a section named
backend.voicemail
from yourconfig.yaml
. Its values will be passed over the backend constructor arguments. -
Implement the
run
method. Since a backend is a thread that polls for new messages on a channel, this will be the thread main method.send_message
should callself.on_message
at the end to post a new message to the application. -
Implement the
send_message
method. This method will be called whenever the application needs to send a new message throughsend_request
andsend_response
. You should never callsend_message
directly.
The __init__.py
will look like this:
from .. import Backend
class VoicemailBackend(Backend)
def __init__(self, phone)
super().__init__()
self.phone = phone
self.voicemail = Voicemail(...)
def send_message(self, msg):
self.voicemail.save_msg(msg)
def run(self):
while True:
msg = self.voicemail.poll()
self.on_message(msg)
- Add a
manifest.yaml
file to the same folder. Example template:
manifest:
type: backend
package: platypush.backend.voicemail
# Events launched by the extension
events:
platypush.message.event.voicemail.OnVoicemailMessage: When a message is received
# Installation requirements
install:
# List of system-wide requirements on Debian/Ubuntu and derived
apt:
- sudo
# List of system-wide requirements on Arch Linux and derived
pacman:
- sudo
# List of pip dependencies
pip:
- requests
# Extra commands to run after the dependencies are installed
exec:
- sudo systemctl enable my-service