# Detect a word and activate an output

**URL:** <https://discourse.nodered.org/t/detect-a-word-and-activate-an-output/45822>\
**Category:** General\
**Created:** [18 May 2021 09:23 UTC](https://discourse.nodered.org/t/detect-a-word-and-activate-an-output/45822 "2021-05-18T09:23:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![raulrodca](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@raulrodca](https://discourse.nodered.org/u/raulrodca)\
**Post date:** [18 May 2021 09:23 UTC](https://discourse.nodered.org/t/detect-a-word-and-activate-an-output/45822/1 "2021-05-18T09:23:18Z")

</div>

Hello good day  
I want to make a flow that when detecting a specific word when receiving it in an email message, it triggers an output.

The idea is to receive a message such as "High temperature alert" that when detecting the word "alert" an output is activated.

Thanks for the help

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [18 May 2021 09:37 UTC](https://discourse.nodered.org/t/detect-a-word-and-activate-an-output/45822/2 "2021-05-18T09:37:45Z")

</div>

I would make the "alert" more distinctive as a message may contain "alert" in a sentence. Maybe `"*alert*"`.  
here is an example of checking the email text payload and outputing only if it contains `"*alert*"`. You would need to add the email node you are going to use.

```auto
[{"id":"c7648fb2.b10bd","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"this an *alert* high temp","payloadType":"str","x":120,"y":540,"wires":[["f4392a80.3c6538"]]},{"id":"4c559864.5b934","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"this is a simple message that contains the word alert alert","payloadType":"str","x":110,"y":580,"wires":[["f4392a80.3c6538"]]},{"id":"f4392a80.3c6538","type":"function","z":"c74669a0.6a34f8","name":"","func":"if(msg.payload.includes(\"*alert*\")){\n return msg;\n}else{\n return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":560,"wires":[["f3880de1.60f03"]]},{"id":"f3880de1.60f03","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":580,"wires":[]}]

```

the top inject contains `"*alert*"` the lower one does not.

---

<div class="post-metadata">

**Author:** ![raulrodca](https://avatars.discourse-cdn.com/v4/letter/r/c77e96/32.png) [@raulrodca](https://discourse.nodered.org/u/raulrodca)\
**Post date:** [18 May 2021 11:39 UTC](https://discourse.nodered.org/t/detect-a-word-and-activate-an-output/45822/3 "2021-05-18T11:39:31Z")

</div>

Thank you very much for your quick response and for your help.

now I have the problem that the output does not separate me, with the switch node.

for example I have two exits and if it receives \* alert \* it will exit through exit 1 and if it does not contain the message \* alert \* it will exit through exit 2

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [18 May 2021 11:42 UTC](https://discourse.nodered.org/t/detect-a-word-and-activate-an-output/45822/4 "2021-05-18T11:42:30Z")

</div>

Do you have an example flow?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 May 2021 11:47 UTC](https://discourse.nodered.org/t/detect-a-word-and-activate-an-output/45822/5 "2021-05-18T11:47:17Z")

</div>

> [@raulrodca](#):
>
> now I have the problem that the output does not separate me, with the switch node.
> 
> for example I have two exits and if it receives \* alert \* it will exit through exit 1 and if it does not contain the message \* alert \* it will exit through exit 2

Thats not what your original question asked. 😕

Use a switch node instead of a function...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2ef5c2db956d2d00c7c4f7d75798dece5b4f4bfd.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/7896c4f79981b6ab7878528c799627a3e3c7aaa5.png)

Demo...

```auto
[{"id":"c7648fb2.b10bd","type":"inject","z":"4b3f21a3.ba434","name":"this an *alert* high temp","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"this an *alert* high temp","payloadType":"str","x":500,"y":2360,"wires":[["65088910.38ce38"]]},{"id":"4c559864.5b934","type":"inject","z":"4b3f21a3.ba434","name":"this is a simple message that contains the word alert","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"this is a simple message that contains the word alert","payloadType":"str","x":410,"y":2400,"wires":[["65088910.38ce38"]]},{"id":"f3880de1.60f03","type":"debug","z":"4b3f21a3.ba434","name":"ALERT! - to email we go","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":2340,"wires":[]},{"id":"65088910.38ce38","type":"switch","z":"4b3f21a3.ba434","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"*alert*","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":2360,"wires":[["f3880de1.60f03"],["426e9e4.0c7346"]]},{"id":"6fc35c78.1aa394","type":"inject","z":"4b3f21a3.ba434","name":"this is a warning only","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"this is a warning only","payloadType":"str","x":510,"y":2320,"wires":[["65088910.38ce38"]]},{"id":"426e9e4.0c7346","type":"debug","z":"4b3f21a3.ba434","name":"No alert in that message - yippee","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":2380,"wires":[]}]

```

---

<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:** [1 June 2021 11:47 UTC](https://discourse.nodered.org/t/detect-a-word-and-activate-an-output/45822/6 "2021-06-01T11:47:29Z")

</div>

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