Skip to content

Commit 0b909b8

Browse files
committed
Used correct user/channel ID when posting blocks on Slack.
1 parent fc03de1 commit 0b909b8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
### Added
1010
### Changed
1111
- Fixed python path in systemd unit file.
12+
- Used correct user id/channel id with postMessage when using blocks in Slack chat adapter.
1213

1314
### Removed
1415

src/err-stackstorm/errst2lib/chat_adapters.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import abc
33
import logging
44

5+
from errbot.backends.base import (
6+
Person,
7+
Room,
8+
)
9+
510
LOG = logging.getLogger("errbot.plugin.st2.chat_adapters")
611

712

@@ -393,7 +398,12 @@ def _post_block_message(self, whisper, message, target_id, extra):
393398
Reference: https://api.slack.com/methods/chat.postMessage
394399
"""
395400
extra["text"] = message
396-
extra["channel"] = target_id
401+
if isinstance(target_id, Person):
402+
extra["user"] = target_id.userid
403+
elif isinstance(target_id, Room):
404+
extra["channel"] = target_id.id
405+
else:
406+
LOG.warning("target_id is type %s that isn't a Person or Room!", type(target_id))
397407

398408
LOG.debug(f"Sending Slack Block {extra}")
399409
self.bot_plugin._bot.slack_web.api_call("chat.postMessage", data=extra)

0 commit comments

Comments
 (0)