# Run a function if I receive a direct message or a mention in Slack?

**URL:** https://discourse.nodered.org/t/run-a-function-if-i-receive-a-direct-message-or-a-mention-in-slack/24266
**Category:** General
**Created:** [5 April 2020 12:46 UTC](https://discourse.nodered.org/t/run-a-function-if-i-receive-a-direct-message-or-a-mention-in-slack/24266 "2020-04-05T12:46:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mversion](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mversion/32/9501_2.png) [@mversion](https://discourse.nodered.org/u/mversion)
#### Post date: [5 April 2020 12:46 UTC](https://discourse.nodered.org/t/run-a-function-if-i-receive-a-direct-message-or-a-mention-in-slack/24266/1 "2020-04-05T12:46:03Z")

</div>

I'm sure this is doable, but don't know where to start.  
So, my idea is to switch on a tp-link light, if I have an unread direct message or a @mention of my username in Slack and then turn it off if I clear my unread count.

Does anyone know of a guide I can follow?

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [6 April 2020 00:12 UTC](https://discourse.nodered.org/t/run-a-function-if-i-receive-a-direct-message-or-a-mention-in-slack/24266/2 "2020-04-06T00:12:45Z")

</div>

I am not familiar with _slack_ other than it is yet another platform for people to _talk_.

You will need a node (don't ask me which) that listens to the _slack_ channel (or what ever they are called).

You then need to look at the message/s that come out of it.

Going on what you said about `@mention` it shouldn't be hard.

Say the message looks something like:

`@slack_topic @person_talking <their text here.>`

If in the `<their text here>` part there is your name mentioned, you could use a `switch` node.

Configured something like:

```auto
[{"id":"5874a312.36fb9c","type":"switch","z":"b4f1ccd4.5e8d1","name":"Look for your name","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"<your name here>","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":330,"y":810,"wires":[[]]}]

```

Then if it gets a message (payload) which `contains` your name, it sends it to the output.

Then you send that (probably via a `change` node to set the payload) to your `tp-link light`.

But that's the basics.

But I hope it helped.

---

<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: [5 June 2020 00:12 UTC](https://discourse.nodered.org/t/run-a-function-if-i-receive-a-direct-message-or-a-mention-in-slack/24266/3 "2020-06-05T00:12:48Z")

</div>

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