dummylabs/thewatchman

Watchman is causing notifications dropped due to malformatting

Hiekkaharju opened this issue · 0 comments

At least if only sending notifications, via Telegram bot, by calling Watchman report-service from an automation and not writing file report, following applies:

In beginning of init.py "async_report_to_notification" there is a "if not service_str:" and then "service_str" and "service_data" are conditionally read. This is a bug as in above use case "service_data" can be not-read-earlier even if "service_str" has been read. It should be read e.g. in its own if-clause.

Later in the same function "service_data" is inserted to "data". That's a bug as it s should not be in the outer "data" layer, but in another "data" inside the outer one. See e.g. the very last example on page https://www.home-assistant.io/integrations/telegram_bot.
Replacing the current
data = {} if service_data is None else json.loads(service_data)
with
data = {}
data["data"] = {} if service_data is None else json.loads(service_data)
would seem to work at least in use case described above, but I believe that this is not the best way to do it.

Either of the above issues alone is sufficient to cause the "Notification service data" field in Watchman integration configuration not to take effect. That further causes the report to be formatted by parsemode = Markdown. And that causes e.g. all underscores '_' being treated as special characters = stripped and depending on following character possibly causing the parsing to terminate due to an error and the notification not being delivered (or just text effects like italics in the messages.)