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
In the case above,
platypush.backend.voicemailwill be your package name.
If your module is
voicemail, then its main class should be named
The configuration for your module will be read from a section named
config.yaml. Its values will be passed over the backend constructor arguments.
runmethod. Since a backend is a thread that polls for new messages on a channel, this will be the thread main method.
self.on_messageat the end to post a new message to the application.
send_messagemethod. This method will be called whenever the application needs to send a new message through
send_response. You should never call
__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.yamlfile 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