# Update/edit a Telegram message

**URL:** <https://discourse.nodered.org/t/update-edit-a-telegram-message/31889>\
**Category:** General\
**Created:** [22 August 2020 20:00 UTC](https://discourse.nodered.org/t/update-edit-a-telegram-message/31889 "2020-08-22T20:00:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![acfnews](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@acfnews](https://discourse.nodered.org/u/acfnews)\
**Post date:** [22 August 2020 20:00 UTC](https://discourse.nodered.org/t/update-edit-a-telegram-message/31889/1 "2020-08-22T20:00:34Z")

</div>

Dear All,

Some time ago I observed an interesting Telegram chat which is fed from Nodered.  
The programmers display a 'realtime' list of devices in a chat, and the device online/offline status.  
The interesting is, that the updates are done within the same message, as if the message is edited in some way. There are no new messages which is a kind of relaxed way for feeding the information.

Does anybody know some documentation on how to achieve this way of working with messages to Telegram? I am unable to find what I should be looking for....

Many thanks!

Ronald

---

<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:** [23 August 2020 11:35 UTC](https://discourse.nodered.org/t/update-edit-a-telegram-message/31889/2 "2020-08-23T11:35:08Z")

</div>

> [@acfnews](#):
>
> The interesting is, that the updates are done within the same message, as if the message is edited in some way.

the thing you are looking for is `type` "editMessageText"

The documentation is out there but not in a ready made "how to" for node red nodes I'm afraid.

Using [telegram documentation](https://core.telegram.org/bots/api#editmessagetext) and looking at the [source code for this node-red node](https://github.com/windkh/node-red-contrib-telegrambot/blob/c64c8aefe687d8d424bd0b6f626ec49f731d7ad2/telegrambot/99-telegrambot.js#L1357) I cobbled together a basic demo...

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

- In your telegram app, send `/serverstatus` to begin receiving messages.
- press the injects to fake server status changes - watch the message update
- send `/stop` to clear the chat\_id/message\_id stored and prevent new updates being sent to telegram.

The message you get is just raw JSON (I'll leave that for you to tidy up)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/247a675409db452f1928235aad2a44e11af3a75c.png)

Here is the flow...

```auto
[{"id":"73a7f6b4.fecb78","type":"telegram command","z":"5d3f964c.fef898","name":"/serverstatus","command":"/serverstatus","bot":"fa7a9376.321ce","strict":false,"hasresponse":false,"x":170,"y":1620,"wires":[["2759079.cd0e4f8","e6e3f9e3.9f4b68"]]},{"id":"db357bb6.47cc98","type":"telegram command","z":"5d3f964c.fef898","name":"/stop","command":"/stop","bot":"fa7a9376.321ce","strict":false,"hasresponse":false,"x":150,"y":1740,"wires":[["ef443902.89a8c8","3d8cc89b.0ce768"]]},{"id":"2759079.cd0e4f8","type":"debug","z":"5d3f964c.fef898","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":330,"y":1660,"wires":[]},{"id":"ef443902.89a8c8","type":"debug","z":"5d3f964c.fef898","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":330,"y":1780,"wires":[]},{"id":"e6e3f9e3.9f4b68","type":"change","z":"5d3f964c.fef898","name":"save chat_id","rules":[{"t":"set","p":"chat_id","pt":"flow","to":"payload.chatId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1620,"wires":[["2978358b.f28f4a"]]},{"id":"3d8cc89b.0ce768","type":"change","z":"5d3f964c.fef898","name":"clear chat_id","rules":[{"t":"delete","p":"chat_id","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":1740,"wires":[["5121be07.154ef"]]},{"id":"5121be07.154ef","type":"change","z":"5d3f964c.fef898","name":"delete message_id","rules":[{"t":"delete","p":"message_id","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1740,"wires":[[]]},{"id":"e49f0f49.68edf","type":"change","z":"5d3f964c.fef898","name":"save message_id","rules":[{"t":"set","p":"message_id","pt":"flow","to":"payload.content.message_id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":1660,"wires":[[]]},{"id":"54b22eed.24e99","type":"telegram sender","z":"5d3f964c.fef898","name":"","bot":"fa7a9376.321ce","x":850,"y":1620,"wires":[["e49f0f49.68edf"]]},{"id":"e90adeb2.66434","type":"inject","z":"5d3f964c.fef898","name":"","topic":"server/1/status","payload":"up","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":1840,"wires":[["3e9729fc.44be86"]]},{"id":"39f7c105.cbaade","type":"inject","z":"5d3f964c.fef898","name":"","topic":"server/1/status","payload":"down","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":1880,"wires":[["3e9729fc.44be86"]]},{"id":"83b303bf.feed4","type":"inject","z":"5d3f964c.fef898","name":"","topic":"server/2/status","payload":"up","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":1920,"wires":[["3e9729fc.44be86"]]},{"id":"e11a90b6.db038","type":"inject","z":"5d3f964c.fef898","name":"","topic":"server/2/status","payload":"down","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":1960,"wires":[["3e9729fc.44be86"]]},{"id":"3e9729fc.44be86","type":"function","z":"5d3f964c.fef898","name":"save server status","func":"var server_status = flow.get(\"server_status\") || {};\nserver_status[msg.topic] = msg.payload;\nflow.set(\"server_status\", server_status) \nreturn msg;","outputs":1,"noerr":0,"x":450,"y":1900,"wires":[["41fa2e6a.95e93"]],"info":"## New message\n\nHello *markdown* formatted messages!'\n\nwith `inline` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold**"},{"id":"41fa2e6a.95e93","type":"switch","z":"5d3f964c.fef898","name":"chat_id exists?","property":"chat_id","propertyType":"flow","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":660,"y":1900,"wires":[["2e44ed20.a2f0c2"]]},{"id":"2e44ed20.a2f0c2","type":"switch","z":"5d3f964c.fef898","name":"message_id exists?","property":"message_id","propertyType":"flow","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":870,"y":1900,"wires":[["43757dc6.981834"]]},{"id":"2978358b.f28f4a","type":"function","z":"5d3f964c.fef898","name":"build server status message","func":"var server_status = flow.get(\"server_status\") || {};\nvar stat = JSON.stringify(server_status);\n\nmsg.payload.content = stat;\nmsg.payload.type = \"message\";\n\n\nreturn msg;","outputs":1,"noerr":0,"x":580,"y":1620,"wires":[["54b22eed.24e99"]],"info":"## New message\n\nHello *markdown* formatted messages!'\n\nwith `inline` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold**"},{"id":"43757dc6.981834","type":"function","z":"5d3f964c.fef898","name":"build server status update message","func":"var server_status = flow.get(\"server_status\") || {};\nvar stat = JSON.stringify(server_status);\n\nvar mid = flow.get(\"message_id\");\nvar cid = flow.get(\"chat_id\");\n\nmsg.payload = {};\nmsg.payload.content = stat;\nmsg.payload.type = \"editMessageText\";\nmsg.payload.chatId = cid;\n\nmsg.payload.options = {\n message_id : mid,\n chat_id: cid\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":920,"y":1860,"wires":[["54b22eed.24e99","c31dea56.509f38"]],"info":"## New message\n\nHello *markdown* formatted messages!'\n\nwith `inline` code\n\n> and quote\n>> nested\n\n\\`\\`\\`\nvar code = \"cool\";\n\\`\\`\\`\n\n| table | data |\n|---|---|\n| 1 | fred |\n| 2 | bob |\n\n_Italic_ **bold**"},{"id":"c31dea56.509f38","type":"debug","z":"5d3f964c.fef898","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":870,"y":1800,"wires":[]},{"id":"79f57d65.851a84","type":"comment","z":"5d3f964c.fef898","name":"Send /serverstatus to register you interest in server status updates","info":"","x":340,"y":1580,"wires":[]},{"id":"7e79d1a4.00a12","type":"comment","z":"5d3f964c.fef898","name":"Send /stop to cancel server status updates","info":"","x":260,"y":1700,"wires":[]},{"id":"fa7a9376.321ce","type":"telegram bot","z":"5d3f964c.fef898","botname":"mybot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"","usesocks":false,"sockshost":"","socksport":"","socksusername":"","sockspassword":"","bothost":"","localbotport":"","publicbotport":"","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":false}]

```

---

<div class="post-metadata">

**Author:** ![acfnews](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@acfnews](https://discourse.nodered.org/u/acfnews)\
**Post date:** [24 August 2020 18:22 UTC](https://discourse.nodered.org/t/update-edit-a-telegram-message/31889/3 "2020-08-24T18:22:17Z")

</div>

This seems exactly as what I need to achieve! Many thanks!

---

<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:** [7 September 2020 18:22 UTC](https://discourse.nodered.org/t/update-edit-a-telegram-message/31889/4 "2020-09-07T18:22:20Z")

</div>

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