Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions mqttwarn/services/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import requests
from requests.auth import HTTPBasicAuth
from requests.auth import HTTPDigestAuth
import time

Check warning on line 16 in mqttwarn/services/slack.py

View check run for this annotation

Codecov / codecov/patch

mqttwarn/services/slack.py#L16

Added line #L16 was not covered by tests


def plugin(srv, item):
Expand Down Expand Up @@ -82,11 +83,21 @@
if image is None:
slack.chat_postMessage(channel=channel, text=text, username=username, icon_emoji=icon, unfurl_links=True)
else:

srv.logging.debug("Channel id: %s" % channel);

slack.files_upload(file=image,title=text,channels=channel)
srv.logging.debug("image posted")
filename = "%s.jpg" % time.time() # generate a filename
sr = slack.files_getUploadURLExternal(filename=filename, length=len(image), alt_text=text)
if sr["ok"]:
r = requests.post(sr["upload_url"], data=image)
if r.ok:
sr = slack.files_completeUploadExternal(files=[{"id": sr["file_id"], "title": text}], channel_id=channel)
if sr["ok"]:
srv.logging.debug("image posted")

Check warning on line 94 in mqttwarn/services/slack.py

View check run for this annotation

Codecov / codecov/patch

mqttwarn/services/slack.py#L87-L94

Added lines #L87 - L94 were not covered by tests
else:
srv.logging.warning("Cannot complete upload: %s" % sr["error"])

Check warning on line 96 in mqttwarn/services/slack.py

View check run for this annotation

Codecov / codecov/patch

mqttwarn/services/slack.py#L96

Added line #L96 was not covered by tests
else:
srv.logging.warning("Failed to post image to url: %s" % r.reason)

Check warning on line 98 in mqttwarn/services/slack.py

View check run for this annotation

Codecov / codecov/patch

mqttwarn/services/slack.py#L98

Added line #L98 was not covered by tests
else:
srv.logging.warning("Cannot upload image: %s" % sr["error"])

Check warning on line 100 in mqttwarn/services/slack.py

View check run for this annotation

Codecov / codecov/patch

mqttwarn/services/slack.py#L100

Added line #L100 was not covered by tests
except SlackApiError as e:
assert e.response["ok"] is False
assert e.response["error"]
Expand Down
Loading