Ok so I've googled around a bit and couldn't find many answers on this, so hopefully somebody here can help.
I'm basically trying to make a Slack app which people in my office can use to notify people in the office channel that they are waiting downstairs and need to be let in, since not everybody has a key. Before I started working on this little project an incoming webhook was used to send messages to a specific channel, however I recently changed this to use the Bolt framework instead, as it should simplify the whole process and let me easily add other formatting options in the future.
When a message is sent, it is supposed to mention the Slack app itself as well as the whole channel (@slackApp @channel somebody is downstairs). The channel mention should notify everyone in the channel and the Slack app has to be mentioned so that other processes listening for this event can happen.
However, when I tried to implement this it would send a message into the desired Slack channel but only mention the whole channel.
The code below is called by a lambda function:
def respond_slack(name, location="Placeholder"):
channel_id = ourOfficeChannel # just a placeholder id for this post
slack_token = os.environ["SLACK_BOT_TOKEN"]
slackClient = WebClient(token=slack_token)
try:
result = slackClient.chat_postMessage(
channel=channel_id,
text=str('<@U041Z8F0TGE> <!channel> Somebody is downstairs!')
)
print(result)
except SlackApiError as e:
print(f"Error: {e}")
I tried sending two messages, one with the channel mention and one with the app mention, however it would only send the message containing the channel mention.
I'm only an intern working on this and I don't have any formal training like university or anything, so I don't really know what I'm doing. Any help would be appreciated :).
PS: This is my first StackOverflow post, feel free to let me know what other details I should include in the original post
To mention the Slack app in your message, you need to use the
app's user IDinstead of its name. You can find the user ID of your Slack app by going to theAboutsection of your app's settings page.Here's an updated version of your code that should mention both the Slack app and the channel:
In this updated code, we are using the
users_infomethod of theWebClientclass to get the user ID of the Slack app, and then using that ID to mention the app in the message