Skip to content

Instantly share code, notes, and snippets.

@majkrzak
Created May 24, 2022 20:19
Show Gist options
  • Save majkrzak/af8e2e1293899c089b01671a26127849 to your computer and use it in GitHub Desktop.
Save majkrzak/af8e2e1293899c089b01671a26127849 to your computer and use it in GitHub Desktop.
Quick and dirty desktop notification from brandmeister network.
#!/usr/bin/env python
from socketio import Client as socket_io_client
from json import loads
import dbus
from sys import argv
if __name__ != "__main__":
exit()
try:
group = int(argv[1])
except:
print("usage:\n\t./bm_notify.py <TG>")
exit()
nit = dbus.Interface(
object=dbus.SessionBus().get_object(
"org.freedesktop.Notifications", "/org/freedesktop/Notifications"
),
dbus_interface="org.freedesktop.Notifications",
)
sio = socket_io_client()
@sio.on("mqtt")
def on_mqtt(data):
payload = loads(data["payload"])
if payload["Event"] != "Session-Start":
return
if payload["DestinationID"] != group:
return
# https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html
nit.Notify(
"Brandmeister",
0,
"",
f"TG{group} Group Call",
f'{payload["SourceID"]} {payload["SourceCall"]} {payload["SourceName"]}',
[],
{"urgency": 1},
20 * 1000,
)
sio.connect(
url="https://api.brandmeister.network",
socketio_path="/lh/socket.io",
transports="websocket",
)
sio.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment