mirror of https://github.com/caronc/apprise
slack:// now has timestamp=yes/no kwarg support (#1394)
parent
c00c36f8f8
commit
52801b6369
|
@ -271,6 +271,12 @@ class NotifySlack(NotifyBase):
|
||||||
"to": {
|
"to": {
|
||||||
"alias_of": "targets",
|
"alias_of": "targets",
|
||||||
},
|
},
|
||||||
|
"timestamp": {
|
||||||
|
"name": _("Include Timestamp"),
|
||||||
|
"type": "bool",
|
||||||
|
"default": True,
|
||||||
|
"map_to": "include_timestamp",
|
||||||
|
},
|
||||||
"token": {
|
"token": {
|
||||||
"name": _("Token"),
|
"name": _("Token"),
|
||||||
"alias_of": ("access_token", "token_a", "token_b", "token_c"),
|
"alias_of": ("access_token", "token_a", "token_b", "token_c"),
|
||||||
|
@ -327,6 +333,7 @@ class NotifySlack(NotifyBase):
|
||||||
targets=None,
|
targets=None,
|
||||||
include_image=None,
|
include_image=None,
|
||||||
include_footer=None,
|
include_footer=None,
|
||||||
|
include_timestamp=None,
|
||||||
use_blocks=None,
|
use_blocks=None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
|
@ -423,6 +430,12 @@ class NotifySlack(NotifyBase):
|
||||||
self.template_args["footer"]["default"] \
|
self.template_args["footer"]["default"] \
|
||||||
if include_footer is None else include_footer
|
if include_footer is None else include_footer
|
||||||
|
|
||||||
|
# timestamp inclusion (only applicable if footer also defined
|
||||||
|
self.include_timestamp = \
|
||||||
|
self.template_args["timestamp"]["default"] \
|
||||||
|
if include_timestamp is None \
|
||||||
|
else include_timestamp
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def send(
|
def send(
|
||||||
|
@ -572,10 +585,9 @@ class NotifySlack(NotifyBase):
|
||||||
"title": title,
|
"title": title,
|
||||||
"text": body,
|
"text": body,
|
||||||
"color": self.color(notify_type),
|
"color": self.color(notify_type),
|
||||||
# Time
|
|
||||||
"ts": time(),
|
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
|
|
||||||
# Acquire our to-be footer icon if configured to do so
|
# Acquire our to-be footer icon if configured to do so
|
||||||
image_url = (
|
image_url = (
|
||||||
None if not self.include_image else self.image_url(notify_type)
|
None if not self.include_image else self.image_url(notify_type)
|
||||||
|
@ -592,6 +604,9 @@ class NotifySlack(NotifyBase):
|
||||||
# Include the footer only if specified to do so
|
# Include the footer only if specified to do so
|
||||||
payload["attachments"][0]["footer"] = self.app_id
|
payload["attachments"][0]["footer"] = self.app_id
|
||||||
|
|
||||||
|
if self.include_timestamp:
|
||||||
|
# Timestamp
|
||||||
|
payload["attachments"][0]["ts"] = time()
|
||||||
if (
|
if (
|
||||||
attach
|
attach
|
||||||
and self.attachment_support
|
and self.attachment_support
|
||||||
|
@ -1115,6 +1130,7 @@ class NotifySlack(NotifyBase):
|
||||||
params = {
|
params = {
|
||||||
"image": "yes" if self.include_image else "no",
|
"image": "yes" if self.include_image else "no",
|
||||||
"footer": "yes" if self.include_footer else "no",
|
"footer": "yes" if self.include_footer else "no",
|
||||||
|
"timestamp": "yes" if self.include_timestamp else "no",
|
||||||
"blocks": "yes" if self.use_blocks else "no",
|
"blocks": "yes" if self.use_blocks else "no",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1233,6 +1249,11 @@ class NotifySlack(NotifyBase):
|
||||||
parse_bool(results["qsd"].get(
|
parse_bool(results["qsd"].get(
|
||||||
"image", NotifySlack.template_args["image"]["default"]))
|
"image", NotifySlack.template_args["image"]["default"]))
|
||||||
|
|
||||||
|
results["include_timestamp"] = \
|
||||||
|
parse_bool(results["qsd"].get(
|
||||||
|
"timestamp",
|
||||||
|
NotifySlack.template_args["timestamp"]["default"]))
|
||||||
|
|
||||||
# Get Payload structure (use blocks?)
|
# Get Payload structure (use blocks?)
|
||||||
if "blocks" in results["qsd"] and len(results["qsd"]["blocks"]):
|
if "blocks" in results["qsd"] and len(results["qsd"]["blocks"]):
|
||||||
results["use_blocks"] = parse_bool(results["qsd"]["blocks"])
|
results["use_blocks"] = parse_bool(results["qsd"]["blocks"])
|
||||||
|
|
|
@ -170,7 +170,9 @@ apprise_url_tests = (
|
||||||
),
|
),
|
||||||
# Test using a bot-token (also test footer set to no flag)
|
# Test using a bot-token (also test footer set to no flag)
|
||||||
(
|
(
|
||||||
"slack://username@xoxb-1234-1234-abc124/#nuxref?footer=no",
|
(
|
||||||
|
"slack://username@xoxb-1234-1234-abc124/#nuxref?footer=no"
|
||||||
|
"×tamp=yes"),
|
||||||
{
|
{
|
||||||
"instance": NotifySlack,
|
"instance": NotifySlack,
|
||||||
"requests_response_text": {
|
"requests_response_text": {
|
||||||
|
@ -179,18 +181,71 @@ apprise_url_tests = (
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
# Test blocks mode
|
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
"slack://?token=T1JJ3T3L2/A1BRTD4JD/TIiajkdnlazkcOXrIdevi7FQ/"
|
"slack://username@xoxb-1234-1234-abc124/#nuxref?footer=yes"
|
||||||
"&to=#chan&blocks=yes&footer=yes"
|
"×tamp=yes"),
|
||||||
),
|
{
|
||||||
{"instance": NotifySlack, "requests_response_text": "ok"},
|
"instance": NotifySlack,
|
||||||
|
"requests_response_text": {
|
||||||
|
"ok": True,
|
||||||
|
"message": "",
|
||||||
|
},
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
(
|
||||||
|
"slack://username@xoxb-1234-1234-abc124/#nuxref?footer=yes"
|
||||||
|
"×tamp=no"),
|
||||||
|
{
|
||||||
|
"instance": NotifySlack,
|
||||||
|
"requests_response_text": {
|
||||||
|
"ok": True,
|
||||||
|
"message": "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
(
|
||||||
|
(
|
||||||
|
"slack://username@xoxb-1234-1234-abc124/#nuxref?footer=yes"
|
||||||
|
"×tamp=no"),
|
||||||
|
{
|
||||||
|
"instance": NotifySlack,
|
||||||
|
"requests_response_text": {
|
||||||
|
"ok": True,
|
||||||
|
"message": "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
# Test blocks mode with timestamp variation
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
"slack://?token=T1JJ3T3L2/A1BRTD4JD/TIiajkdnlazkcOXrIdevi7FQ/"
|
"slack://?token=T1JJ3T3L2/A1BRTD4JD/TIiajkdnlazkcOXrIdevi7FQ/"
|
||||||
"&to=#chan&blocks=yes&footer=no"
|
"&to=#chan&blocks=yes&footer=yes×tamp=no"
|
||||||
|
),
|
||||||
|
{"instance": NotifySlack, "requests_response_text": "ok"},
|
||||||
|
),
|
||||||
|
# Test blocks mode with another timestamp
|
||||||
|
(
|
||||||
|
(
|
||||||
|
"slack://?token=T1JJ3T3L2/A1BRTD4JD/TIiajkdnlazkcOXrIdevi7FQ/"
|
||||||
|
"&to=#chan&blocks=yes&footer=yes×tamp=yes"
|
||||||
|
),
|
||||||
|
{"instance": NotifySlack, "requests_response_text": "ok"},
|
||||||
|
),
|
||||||
|
# footer being disabled means timestamp isn't shown
|
||||||
|
(
|
||||||
|
(
|
||||||
|
"slack://?token=T1JJ3T3L2/A1BRTD4JD/TIiajkdnlazkcOXrIdevi7FQ/"
|
||||||
|
"&to=#chan&blocks=yes&footer=no×tamp=yes"
|
||||||
|
),
|
||||||
|
{"instance": NotifySlack, "requests_response_text": "ok"},
|
||||||
|
),
|
||||||
|
# footer and timestamp disabled
|
||||||
|
(
|
||||||
|
(
|
||||||
|
"slack://?token=T1JJ3T3L2/A1BRTD4JD/TIiajkdnlazkcOXrIdevi7FQ/"
|
||||||
|
"&to=#chan&blocks=yes&footer=no×tamp=no"
|
||||||
),
|
),
|
||||||
{"instance": NotifySlack, "requests_response_text": "ok"},
|
{"instance": NotifySlack, "requests_response_text": "ok"},
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue