From 11f0eb672e0d00570592c824a9441a9ce6802f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rainer=20M=C3=BCller?= Date: Wed, 28 Mar 2018 11:24:55 +0200 Subject: [PATCH 1/2] Add new option message_escape Allow to escape the keyword replacements before they are put into message_content with any of the ZNC supported formats. An unknown value will leave the string unmodified. --- push.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/push.cpp b/push.cpp index 15c6b0d..fe72309 100755 --- a/push.cpp +++ b/push.cpp @@ -140,6 +140,7 @@ class CPushMod : public CModule defaults["message_uri_title"] = ""; defaults["message_priority"] = "0"; defaults["message_sound"] = ""; + defaults["message_escape"] = ""; // Notification conditions defaults["away_only"] = "no"; @@ -268,6 +269,14 @@ class CPushMod : public CModule replace["{network}"] = "(No network)"; } + if (options["message_escape"] != "") + { + CString::EEscape esc = CString::ToEscape(options["message_escape"]); + for (MCString::iterator i = replace.begin(); i != replace.end(); i++) { + i->second = i->second.Escape(esc); + } + } + CString message_uri = expand(options["message_uri"], replace); CString message_title = expand(options["message_title"], replace); CString message_content = expand(options["message_content"], replace); @@ -728,6 +737,9 @@ class CPushMod : public CModule params["chat_id"] = options["target"]; params["text"] = message_content; + if (options["message_escape"] == "HTML") { + params["parse_mode"] = "HTML"; + } } else { From 8291d4ee92e96f1f9d9708496a04f0dd7ae90ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rainer=20M=C3=BCller?= Date: Wed, 28 Mar 2018 11:53:00 +0200 Subject: [PATCH 2/2] Document message_escape option Also add a configuration example for the Telegram service. --- README.md | 10 ++++++++++ doc/telegram.md | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 53c0a01..20c139b 100755 --- a/README.md +++ b/README.md @@ -311,6 +311,16 @@ to something similar to "http://domain/#channel/2011-03-09 14:25:09", or When using Nexmo, this value is where the SMS is "from". In most cases, you must use a valid number in international format. +* `message_escape` Default: ` ` + + If set, keyword values will be escaped in this format before they are expanded in + `message_content`. Possible values are all that ZNC supports, most useful here will be + `HTML` or `URL`. + + Note that the resulting string in `message_content` after keyword expansion will not be + escaped. If you need to escape characters for a service, you have to set the escaped + string to `message_content`. + * `message_uri` Default: ` ` URI that will be sent with the push notification. This could be a web address or a diff --git a/doc/telegram.md b/doc/telegram.md index 5794a1a..8f63aa9 100644 --- a/doc/telegram.md +++ b/doc/telegram.md @@ -16,5 +16,12 @@ module by following the above steps. * set secret to the **api key**: /msg *push set secret your-api-key * set target to chat ID: /msg *push set target your-chat-id +You can style your messages with [basic HTML][HTML] when you set the +`message_escape` option accordingly. + + set message_escape HTML + set message_content {context}: <{nick}> {message} + [Telegram]: https://telegram.org [BotFather]: https://core.telegram.org/bots#6-botfather +[HTML]: https://core.telegram.org/bots/api#formatting-options