# Telegram post caption filter

**URL:** <https://discourse.nodered.org/t/telegram-post-caption-filter/53579>\
**Category:** General\
**Tags:** telegram\
**Created:** [11 November 2021 15:33 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579 "2021-11-11T15:33:39Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![gleba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gleba/32/50938_2.png) [@gleba](https://discourse.nodered.org/u/gleba)\
**Post date:** [11 November 2021 15:33 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/1 "2021-11-11T15:33:39Z")

</div>

Hi, I state that my level is basic.  
I would like to filter the content of a channel by a keyword in the caption and then forward it to a second channel.  
i use contrib telegram nodes, and have tried with switch nodes to no avail.

what solution can i adopt?

---

<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:** [11 November 2021 21:06 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/2 "2021-11-11T21:06:24Z")

</div>

Welcome to the forum @gleba.

Have you started by making sure you can (a) get the messages from the first channel and output to the debug panel, and (b) send a message to channel 2?

---

<div class="post-metadata">

**Author:** ![gleba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gleba/32/50938_2.png) [@gleba](https://discourse.nodered.org/u/gleba)\
**Post date:** [11 November 2021 22:14 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/3 "2021-11-11T22:14:20Z")

</div>

Yes. Currently I forward all messages, but I'm only interested in one that in the caption starts with #

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 November 2021 17:55 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/4 "2021-11-12T17:55:37Z")

</div>

You can use a switch node to only pass the ones you want. If it doesn't work then show us what the message looks like and how you have configured the switch.

---

<div class="post-metadata">

**Author:** ![gleba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gleba/32/50938_2.png) [@gleba](https://discourse.nodered.org/u/gleba)\
**Post date:** [12 November 2021 20:45 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/5 "2021-11-12T20:45:56Z")

</div>

I have already tried with the node of Switch, But surely wrong configuration. I set msg.payload.caption and in the filters contains string key words. As a second filter I put otherwise. I always get the second exit.  
As soon as possible post photos.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 November 2021 22:01 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/6 "2021-11-12T22:01:02Z")

</div>

If you want to test for the caption starting with `#` then use `Matches regex` and for the regex use `^#`  
`^` matches the start of the string, so that will find any strings where the first character is `#`

---

<div class="post-metadata">

**Author:** ![gleba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gleba/32/50938_2.png) [@gleba](https://discourse.nodered.org/u/gleba)\
**Post date:** [13 November 2021 00:37 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/7 "2021-11-13T00:37:57Z")

</div>

I did a test but posting a photo with and without caption containing # I always get the exit. 2.

 ![IMG_20211113_013403_466](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1e3f1df98cb38568c8ad52c535d0c6201b295ff9.jpeg)

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [13 November 2021 04:03 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/8 "2021-11-13T04:03:15Z")

</div>

Perhaps `payload.caption` isn't what you expect it to be. The test below works.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab058a6e3466311cfbe50ffe5a062a40a7c4431f.png)

EDIT: I just notice you wrote "caption containing #'. The '^#' regex looks for strings starting with '#'. If you want '#' to be anywhere within the caption, use a regex of just '#' (or indeed use 'contains' rather than 'matches regex').

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 November 2021 07:08 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/9 "2021-11-13T07:08:51Z")

</div>

I don't see caption in the debug node output, if you click on the debug output it will expand so you can see what is there.

---

<div class="post-metadata">

**Author:** ![gleba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gleba/32/50938_2.png) [@gleba](https://discourse.nodered.org/u/gleba)\
**Post date:** [13 November 2021 09:21 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/10 "2021-11-13T09:21:52Z")

</div>

This is the caption used.

 ![IMG_20211113_102050_056](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c05d0e95b28e3915202fc9c5a37a16f2b0abee74.jpeg)

---

<div class="post-metadata">

**Author:** ![gleba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gleba/32/50938_2.png) [@gleba](https://discourse.nodered.org/u/gleba)\
**Post date:** [13 November 2021 09:40 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/11 "2021-11-13T09:40:44Z")

</div>

I tried to run the test but in both cases it has always been output 2

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61d410c1b11ccc8bd26e941e034bdec3406f7146.png)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [13 November 2021 10:06 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/12 "2021-11-13T10:06:48Z")

</div>

Isn't that msg.originalMessage.caption? Or msg.originalMessage.photo.caption?

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/1/a1a173e0e3dd56a9815b839f160ad0a9ac0d535d.jpeg)

---

<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:** [13 November 2021 10:07 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/13 "2021-11-13T10:07:59Z")

</div>

If you use the copy path button next to the caption property, you will find the path is  
`originalMessage.caption`  
The copy path button appears when you hover the mouse to the right of the property in the debug panel.  
so it should be `msg.originalMessgae.caption`

@jbudd photo is an array with 3 items not 4.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [13 November 2021 12:33 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/14 "2021-11-13T12:33:36Z")

</div>

Yes, it is. I was peering myopically at my phone screen! 🧐

---

<div class="post-metadata">

**Author:** ![gleba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gleba/32/50938_2.png) [@gleba](https://discourse.nodered.org/u/gleba)\
**Post date:** [13 November 2021 13:13 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/15 "2021-11-13T13:13:56Z")

</div>

Thanks it worked and now I can filter the content of the captions.

---

<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:** [27 November 2021 13:14 UTC](https://discourse.nodered.org/t/telegram-post-caption-filter/53579/16 "2021-11-27T13:14:29Z")

</div>

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