# Posting messages into a Slack channel from Node-RED

**URL:** <https://discourse.nodered.org/t/posting-messages-into-a-slack-channel-from-node-red/53416>\
**Category:** General\
**Created:** [9 November 2021 01:58 UTC](https://discourse.nodered.org/t/posting-messages-into-a-slack-channel-from-node-red/53416 "2021-11-09T01:58:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryce](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bryce/32/23590_2.png) [@Bryce](https://discourse.nodered.org/u/Bryce)\
**Post date:** [9 November 2021 01:58 UTC](https://discourse.nodered.org/t/posting-messages-into-a-slack-channel-from-node-red/53416/1 "2021-11-09T01:58:02Z")

</div>

Hi there,

This is a safety feature for a science lab,  
I have a flow set up that monitors water flow from a tap (for water cooling chemistry experiments), it is read as a frequency. The whole purpose of it is if the water is accidentally turned off, or water is shut off to the building it then turns off the power to the heating mantles via a tp-link switch (using the Kasa node).

I have that part of the flow all working correctly and tidy. I would now like to send a message to a Slack channel to tell all users the water has been turned off. We use slack as our work messaging system, so this is very integrated into my workplace.

Could anyone explain how to get Node-RED using nodes to trigger a message in a specific Slack channel? The easiest method is best, I can use IFTTT or Slack API, just need some guidance.

I am not a coder or computer engineer, and I have been getting rather confused with all the new terminology I have come across, (Webhooks, OAuth Tokens, Slack API, Scopes etc)

Thanks in advance for any help or clarity on the issue  
Bryce

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [9 November 2021 13:03 UTC](https://discourse.nodered.org/t/posting-messages-into-a-slack-channel-from-node-red/53416/2 "2021-11-09T13:03:10Z")

</div>

Nothing in the flows site that would help?

[Library - Node-RED (nodered.org)](https://flows.nodered.org/search?term=slack)

---

<div class="post-metadata">

**Author:** ![sammachin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sammachin/32/5121_2.png) [@sammachin](https://discourse.nodered.org/u/sammachin)\
**Post date:** [9 November 2021 15:48 UTC](https://discourse.nodered.org/t/posting-messages-into-a-slack-channel-from-node-red/53416/3 "2021-11-09T15:48:57Z")

</div>

Hi Bryce,

I'm using the `slack-web-out` node from this pacakge [node-red-contrib-slack (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-slack)

The node itself is simple enough to setup you to send in the msg.topic as the channel name you want to post to eg #general (with the #) and then msg.payload is the text of the message.

The auth is a little more complex as Slack have been through a number of ways of doing things over the years but I've just tested this method and its probabbly the simplest for your use case.

(You will need to be an admin on the slack workspace you want to setup against) goto [https://api.slack.com](https://api.slack.com)  
You'll need to create a new app, then install that app onto your workspace and then in the oAuth section you should be able to create a bot user and that user will have a token. That token is what you need to setup the config in the slack node.

---

<div class="post-metadata">

**Author:** ![Bryce](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bryce/32/23590_2.png) [@Bryce](https://discourse.nodered.org/u/Bryce)\
**Post date:** [9 November 2021 21:34 UTC](https://discourse.nodered.org/t/posting-messages-into-a-slack-channel-from-node-red/53416/4 "2021-11-09T21:34:04Z")

</div>

Hi Sam,

Thank you so much, that has helped.  
I have been promoted to admin of the Slack workspace, where I have created a channel called lab\_notifications.

Do I then use a `function` node with the following code?

if (msg.payload == 0) {  
msg.payload = "Water Flow has stopped, Power has been turned off";  
}  
msg.topic = "#lab\_notifications";  
return msg;

If not, what do I use to inject the text I would like to appear in the Slack channel into the `slack-web-out` node

1. I've built an app in the Slack API, and under the "Bot Token Scopes"  
I have added:  
-chat:write  
-incoming-webhook as its two OAuth Scopes.

2. I installed it to a workspace, and gave it permission to post in the #lab\_notifications channel, which gave me a Bot User OAuth Token, which I copy and pasted into the `slack-web-out` node in the Token field

Do I need to do anything with a Webhood URL?

I still can't get it to post, if possible could you give me more instructions and steps to follow, this is all new for me and very confusing

Thanks heaps for helping me  
Bryce

---

<div class="post-metadata">

**Author:** ![Bryce](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bryce/32/23590_2.png) [@Bryce](https://discourse.nodered.org/u/Bryce)\
**Post date:** [9 November 2021 23:19 UTC](https://discourse.nodered.org/t/posting-messages-into-a-slack-channel-from-node-red/53416/5 "2021-11-09T23:19:02Z")

</div>

I think I have figured it out. It took a small amount of code in a `function` node for it to send through to my Slack channel.

If anyone else find this thread or needs the solution that worked for me, then this is the code I used:

msg.topic = "chat.postMessage";  
msg.payload = {  
channel: "#lab\_notifications",  
text: "Water Flow to the LARGE soxhlets (Metals Lab) has stopped. Power to its heating element has been turned off"  
}

return msg;

Using the Bot OAuth Token from the App I made, it all seems to work well. Thanks for pointing me in the right direction. Much appreciated !!

---

<div class="post-metadata">

**Author:** ![sammachin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sammachin/32/5121_2.png) [@sammachin](https://discourse.nodered.org/u/sammachin)\
**Post date:** [10 November 2021 08:17 UTC](https://discourse.nodered.org/t/posting-messages-into-a-slack-channel-from-node-red/53416/6 "2021-11-10T08:17:14Z")

</div>

Glad you've worked it out, according to the help a simple message posting should work with just the channel in the topic field, (thats what I have) but this will also do it, I wonder if it makes a difference if the bot is added to the channel you're posting too.

You don't _have_ to use a function node to setup your message either, you could do this with a change node or (for testing) with an inject node and set the properties within that node.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 November 2021 08:17 UTC](https://discourse.nodered.org/t/posting-messages-into-a-slack-channel-from-node-red/53416/7 "2021-11-24T08:17:18Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
