10000 allow slack bolt to support bot messages by ITJamie · Pull Request #68106 · saltstack/salt · GitHub
[go: up one dir, main page]

Skip to content

allow slack bolt to support bot messages #68106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3007.x
Choose a base branch
from
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
16 changes: 15 additions & 1 deletion salt/engines/slack_bolt_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ def generate_triggered_messages(

def just_data(m_data):
"""Always try to return the user and channel anyway"""
message_source = "user"
if "user" not in m_data:
if "message" in m_data and "user" in m_data["message"]:
log.debug(
Expand All @@ -595,17 +596,23 @@ def just_data(m_data):
elif "comment" in m_data and "user" in m_data["comment"]:
log.debug("Comment was added, so we look for user in the comment.")
user_id = m_data["comment"]["user"]
elif "subtype" in m_data and m_data['subtype'] == "bot_message":
user_id = m_data.get("bot_id")
message_source = "bot"
user_name = m_data.get("username")
else:
user_id = m_data.get("user")
channel_id = m_data.get("channel")
if channel_id.startswith("D"): # private chate with bot user
channel_name = "private chat"
else:
channel_name = all_slack_channels.get(channel_id)
if message_source == "user":
user_name = all_slack_users.get(user_id)
data = {
"message_data": m_data,
"user_id": user_id,
"user_name": all_slack_users.get(user_id),
"user_name": user_name,
"channel_name": channel_name,
}
if not data["user_name"]:
Expand Down Expand Up @@ -984,6 +991,13 @@ def run_command_async(self, msg):
# Check for pillar string representation of dict and convert it to dict
if "pillar" in kwargs:
kwargs.update(pillar=ast.literal_eval(kwargs["pillar"]))
if "test" in kwargs and cmd.lower() in ["state.apply", "state.highstate"]:
if str(kwargs["test"]).lower() in ["true", "false"]:
if kwargs["test"].lower() == "true":
kwargs["test"] = True
else:
kwargs["test"] = False


# Check for target. Otherwise assume None
target = msg["target"]["target"]
Expand Down
Loading
0