mirror of https://github.com/SeanOMik/znc-push.git
Add string replacement to message title and content to match url
This commit is contained in:
parent
e41034374d
commit
a65def9f38
44
README.md
44
README.md
|
@ -151,6 +151,29 @@ Commands
|
||||||
Configuration
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
### Keyword Expansion
|
||||||
|
|
||||||
|
Some configuration options allow for optional keyword expansion, which happens
|
||||||
|
while preparing to send the push notification. Expansion is performed each time
|
||||||
|
a notification is sent. Expansion is only performed on options that explicitly
|
||||||
|
|
||||||
|
|
||||||
|
The following keywords will be replaced with the appropriate value:
|
||||||
|
|
||||||
|
* `{context}`: the channel or query window context
|
||||||
|
* `{nick}`: the nick that sent the message
|
||||||
|
* `{datetime}`: [ISO 8601][] date string, in server-local time
|
||||||
|
* `{unixtime}`: unix-style integer timestamp
|
||||||
|
* `{title}`: the default title for the notification
|
||||||
|
* `{message}`: the shortened message contents
|
||||||
|
* `{username}`: the configured username string
|
||||||
|
* `{secret}`: the configured secret string
|
||||||
|
|
||||||
|
As an example, a value of "http://domain/{context}/{datetime}" would be expanded
|
||||||
|
to something similar to "http://domain/#channel/2011-03-09 14:25:09", or
|
||||||
|
"http://domain/{nick}/{unixtime}" to "http://domain/somenick/1299685136".
|
||||||
|
|
||||||
|
|
||||||
### Push Services
|
### Push Services
|
||||||
|
|
||||||
* `service = ""`
|
* `service = ""`
|
||||||
|
@ -279,19 +302,20 @@ Configuration
|
||||||
|
|
||||||
* `message_uri = ""`
|
* `message_uri = ""`
|
||||||
|
|
||||||
URI that will be sent with the notification to Notifo. This could be a web address or a
|
URI that will be sent with the push notification. This could be a web address or a
|
||||||
local scheme to access a mobile application. Keyword expansion is performed on this
|
local scheme to access a mobile application. Keyword expansion is performed on this
|
||||||
value each time a notification is sent; the following keywords will be replaced with
|
value.
|
||||||
the appropriate value:
|
|
||||||
|
|
||||||
* `{context}`: the channel or query window context
|
* `message_title = "{title}"`
|
||||||
* `{nick}`: the nick that sent the message
|
|
||||||
* `{datetime}`: [ISO 8601][] date string, in server-local time
|
Title that will be provided for the push notification. Keyword expansion is performed
|
||||||
* `{unixtime}`: unix-style integer timestamp
|
on this value.
|
||||||
|
|
||||||
|
* `message_content = "{message}"`
|
||||||
|
|
||||||
|
Message content that will be sent for the push notification. Keyword expansion is
|
||||||
|
performed on this value.
|
||||||
|
|
||||||
As an example, a value of "http://domain/{context}/{datetime}" would be expanded to
|
|
||||||
something similar to "http://domain/#channel/2011-03-09 14:25:09", or
|
|
||||||
"http://domain/{nick}/{unixtime}" to "http://domain/somenick/1299685136".
|
|
||||||
|
|
||||||
### Advanced
|
### Advanced
|
||||||
|
|
||||||
|
|
47
push.cpp
47
push.cpp
|
@ -127,6 +127,8 @@ class CPushMod : public CModule
|
||||||
// Notification settings
|
// Notification settings
|
||||||
defaults["message_length"] = "100";
|
defaults["message_length"] = "100";
|
||||||
defaults["message_uri"] = "";
|
defaults["message_uri"] = "";
|
||||||
|
defaults["message_title"] = "{title}";
|
||||||
|
defaults["message_content"] = "{message}";
|
||||||
|
|
||||||
defaults["debug"] = "off";
|
defaults["debug"] = "off";
|
||||||
}
|
}
|
||||||
|
@ -200,13 +202,20 @@ class CPushMod : public CModule
|
||||||
char iso8601 [20];
|
char iso8601 [20];
|
||||||
strftime(iso8601, 20, "%Y-%m-%d %H:%M:%S", timeinfo);
|
strftime(iso8601, 20, "%Y-%m-%d %H:%M:%S", timeinfo);
|
||||||
|
|
||||||
// URI string replacements
|
// Message string replacements
|
||||||
MCString replace;
|
MCString replace;
|
||||||
replace["{context}"] = context;
|
replace["{context}"] = context;
|
||||||
replace["{nick}"] = nick.GetNick();
|
replace["{nick}"] = nick.GetNick();
|
||||||
replace["{datetime}"] = CString(iso8601);
|
replace["{datetime}"] = CString(iso8601);
|
||||||
replace["{unixtime}"] = CString(time(NULL));
|
replace["{unixtime}"] = CString(time(NULL));
|
||||||
CString uri = expand(options["message_uri"], replace);
|
replace["{message}"] = short_message;
|
||||||
|
replace["{title}"] = title;
|
||||||
|
replace["{username}"] = options["username"];
|
||||||
|
replace["{secret}"] = options["secret"];
|
||||||
|
|
||||||
|
CString message_uri = expand(options["message_uri"], replace);
|
||||||
|
CString message_title = expand(options["message_title"], replace);
|
||||||
|
CString message_content = expand(options["message_content"], replace);
|
||||||
|
|
||||||
// Set up the connection profile
|
// Set up the connection profile
|
||||||
CString service = options["service"];
|
CString service = options["service"];
|
||||||
|
@ -235,10 +244,10 @@ class CPushMod : public CModule
|
||||||
service_auth.Base64Encode();
|
service_auth.Base64Encode();
|
||||||
|
|
||||||
params["to"] = options["username"];
|
params["to"] = options["username"];
|
||||||
params["msg"] = short_message;
|
params["msg"] = message_content;
|
||||||
params["label"] = app;
|
params["label"] = app;
|
||||||
params["title"] = title;
|
params["title"] = message_title;
|
||||||
params["uri"] = uri;
|
params["uri"] = message_uri;
|
||||||
}
|
}
|
||||||
else if (service == "boxcar")
|
else if (service == "boxcar")
|
||||||
{
|
{
|
||||||
|
@ -256,8 +265,8 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
params["email"] = options["username"];
|
params["email"] = options["username"];
|
||||||
params["notification[from_screen_name]"] = context;
|
params["notification[from_screen_name]"] = context;
|
||||||
params["notification[message]"] = short_message;
|
params["notification[message]"] = message_content;
|
||||||
params["notification[source_url]"] = uri;
|
params["notification[source_url]"] = message_uri;
|
||||||
}
|
}
|
||||||
else if (service == "nma")
|
else if (service == "nma")
|
||||||
{
|
{
|
||||||
|
@ -272,9 +281,9 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
params["apikey"] = options["secret"];
|
params["apikey"] = options["secret"];
|
||||||
params["application"] = app;
|
params["application"] = app;
|
||||||
params["event"] = title;
|
params["event"] = message_title;
|
||||||
params["description"] = short_message;
|
params["description"] = message_content;
|
||||||
params["url"] = uri;
|
params["url"] = message_uri;
|
||||||
}
|
}
|
||||||
else if (service == "pushover")
|
else if (service == "pushover")
|
||||||
{
|
{
|
||||||
|
@ -291,12 +300,12 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
params["token"] = pushover_api_token;
|
params["token"] = pushover_api_token;
|
||||||
params["user"] = options["secret"];
|
params["user"] = options["secret"];
|
||||||
params["title"] = title;
|
params["title"] = message_title;
|
||||||
params["message"] = short_message;
|
params["message"] = message_content;
|
||||||
|
|
||||||
if (uri != "")
|
if (message_uri != "")
|
||||||
{
|
{
|
||||||
params["url"] = uri;
|
params["url"] = message_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options["target"] != "")
|
if (options["target"] != "")
|
||||||
|
@ -317,9 +326,9 @@ class CPushMod : public CModule
|
||||||
|
|
||||||
params["apikey"] = options["secret"];
|
params["apikey"] = options["secret"];
|
||||||
params["application"] = app;
|
params["application"] = app;
|
||||||
params["event"] = title;
|
params["event"] = message_title;
|
||||||
params["description"] = short_message;
|
params["description"] = message_content;
|
||||||
params["url"] = uri;
|
params["url"] = message_uri;
|
||||||
}
|
}
|
||||||
else if (service == "supertoasty")
|
else if (service == "supertoasty")
|
||||||
{
|
{
|
||||||
|
@ -336,8 +345,8 @@ class CPushMod : public CModule
|
||||||
service_host = "api.supertoasty.com";
|
service_host = "api.supertoasty.com";
|
||||||
service_url = "/notify/"+options["secret"];
|
service_url = "/notify/"+options["secret"];
|
||||||
|
|
||||||
params["title"] = title;
|
params["title"] = message_title;
|
||||||
params["text"] = short_message;
|
params["text"] = message_content;
|
||||||
params["image"] = "https://github.com/jreese/znc-push/raw/supertoasty/logo.png";
|
params["image"] = "https://github.com/jreese/znc-push/raw/supertoasty/logo.png";
|
||||||
params["sender"] = "ZNC Push";
|
params["sender"] = "ZNC Push";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue