Answer product-owner round 1: 0 🔴, 0 🟡 (0 misread); escape the characters Slack reads as control characters, and say the DM isn't only Mattermost's
This commit is contained in:
+4
-3
@@ -1,5 +1,6 @@
|
||||
"""Sends a direct message from a Slack app's bot to one user, through Slack's Web API. `notifier` picks it where a project's config names `slack`."""
|
||||
"""Sends a direct message from a Slack app's bot to one user, through Slack's Web API. The `notifier` setting `slack` picks it."""
|
||||
import dataclasses
|
||||
import html
|
||||
import pathlib
|
||||
|
||||
from failure import Failure
|
||||
@@ -29,8 +30,8 @@ def read_config(path: pathlib.Path) -> Config | Failure:
|
||||
|
||||
|
||||
def send(config: Config, message: str, http: Http) -> Failure | None:
|
||||
"""Posts message to the recipient's member ID, which Slack opens as a DM from the app's bot; the bot needs the `chat:write` scope."""
|
||||
answer = http("POST", f"{API}/chat.postMessage", config.token, {"channel": config.recipient, "text": message})
|
||||
"""Posts message to the recipient's member ID, which Slack opens as a DM from the app's bot; the bot needs the `chat:write` scope. Slack reads `&`, `<` and `>` as control characters, so they are escaped as its docs ask."""
|
||||
answer = http("POST", f"{API}/chat.postMessage", config.token, {"channel": config.recipient, "text": html.escape(message, quote=False)})
|
||||
if isinstance(answer, Failure):
|
||||
return answer
|
||||
if isinstance(answer, dict) and answer.get("ok") is True:
|
||||
|
||||
Reference in New Issue
Block a user