# Personalize Telegram message with entity\_id name

**URL:** <https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453>\
**Category:** General\
**Created:** [27 February 2019 21:32 UTC](https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453 "2019-02-27T21:32:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![msanchezt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msanchezt/32/6324_2.png) [@msanchezt](https://discourse.nodered.org/u/msanchezt)\
**Post date:** [27 February 2019 21:32 UTC](https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453/1 "2019-02-27T21:32:16Z")

</div>

Hi,

I'm using Home Assistant in conjunction with NodeRed. I have the following automation in place that sends a Telegram alert every time opens a blind (I have 4 blinds in the living room). The

The problem is don't know how to personalize the generic message I have right now ("Opening living room blinds") by including the name of the blind ("Opening living room blind 1/2/3/4").

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

How can I pass the name (entity\_id) of the blind to the Telegram node and include it in the message?

Thanks a lot.

---

<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:** [27 February 2019 21:44 UTC](https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453/2 "2019-02-27T21:44:59Z")

</div>

> [@msanchezt](#):
>
> How can I pass the name (entity\_id) of the blind to the Telegram node and include it in the message?

The way I do it is to use a function or change node to change the payload, adding the data you want to the text string to be sent. You can also use simplistic HTML or Markdown as well but you can only do simple things like bold and italics.

Here are some example messages from one of my bots:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/5518bd02010fde8b8cecbd645dc85f049f8113e4.png)

The bold titles are actually part of the payload.

---

<div class="post-metadata">

**Author:** ![msanchezt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msanchezt/32/6324_2.png) [@msanchezt](https://discourse.nodered.org/u/msanchezt)\
**Post date:** [28 February 2019 13:29 UTC](https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453/3 "2019-02-28T13:29:42Z")

</div>

Thanks, that function node seems like the way to go. Would you mind sharing some code examples for that node?

---

<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:** [28 February 2019 14:57 UTC](https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453/4 "2019-02-28T14:57:43Z")

</div>

I'll see what I can do, it is a collection of nodes and I make the telegram part a common target node by using lots of link nodes. But I'll see what I can extract.

---

<div class="post-metadata">

**Author:** ![msanchezt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msanchezt/32/6324_2.png) [@msanchezt](https://discourse.nodered.org/u/msanchezt)\
**Post date:** [2 March 2019 10:12 UTC](https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453/5 "2019-03-02T10:12:47Z")

</div>

The problem I have is that all the information (I get this with a debug node) that I can see in the output of "Living room blind 1 - OPEN" is the following, but friendly name is not listed there:

> object
> 
> payload: object
> 
> domain: "cover"
> 
> service: "open\_cover"
> 
> data: object
> 
> entity\_id: "switch.sonoff\_ch4\_1"
> 
> \_msgid: "f910e57.eb50718"

I tried getting the friendly name at the output of this node with "data.attributes.friendly\_name" but is not working.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [2 March 2019 10:16 UTC](https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453/6 "2019-03-02T10:16:44Z")

</div>

In the debug node you should be able to click on a small arrow to “open” the ones that say object to see the nested value.

(see the page on working with messages in the documentation)

---

<div class="post-metadata">

**Author:** ![msanchezt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msanchezt/32/6324_2.png) [@msanchezt](https://discourse.nodered.org/u/msanchezt)\
**Post date:** [3 March 2019 13:06 UTC](https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453/7 "2019-03-03T13:06:22Z")

</div>

That was exactly mi issue, that info was not included in the output (even if I open/display the whole output).

I solved it with:

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

And this the content of the function node:

> msg.payload = {}  
> var my\_friendly\_name = msg.data.attributes.friendly\_name;  
> msg.payload.chatId = MY\_ID  
> msg.payload.type = "message"  
> msg.payload.content = "Opening: " + my\_friendly\_name  
> return msg;

Note that I needed to use the "Telegram Sender" node. As the one I was using (Notify) was not capable of injecting a custom message. It needed to be defined as a text/string in the node itself.

---

<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:** [3 March 2019 15:28 UTC](https://discourse.nodered.org/t/personalize-telegram-message-with-entity-id-name/8453/8 "2019-03-03T15:28:17Z")

</div>

> [@msanchezt](#):
>
> Would you mind sharing some code examples for that node?

Here is an example function node:

```javascript
/**
 * Get all latest humidities and save to global var for replay.
 * WARNING: Requires Node.JS v8+
 **/

let currentHumidities = global.get('currentHumidities') || {}

let payload = ''
let locns = Object.keys(currentHumidities).sort()

locns.forEach(function(locn) {
    let h = Math.round(currentHumidities[locn]).toString().padStart(3)
    payload += `\`${locn.padEnd(15)}: ${h}\`
` // Note the newline, also note text is wrapped in `` as output is markdown - this makes the text fixed width
});

msg.payload.content = "*Current Humidities are*:\n" + payload

msg.payload.options = { "parse_mode": "Markdown" }

msg.topic = 'TELEGRAM/myBOT/Current_House_Humidities'

return msg;

// EOF

```

Note the requirement for at least Node.js v8 due to back-ticks. Also note the embeded markdown.
