# \[Solved\] Not able to send Linux command's output to Telegram

**URL:** <https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919>\
**Category:** General\
**Created:** [10 March 2020 12:21 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919 "2020-03-10T12:21:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [10 March 2020 12:21 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/1 "2020-03-10T12:21:54Z")

</div>

Hello All,

Greetings!!

I am newbie in Node-Red(BTW GREAT tech and would like to learn it more).  
I created flow today whose json is as follows.

```auto
[{"id":"e8fec1f1.d46c7","type":"tab","label":"/help function in bot.","disabled":false,"info":""},{"id":"fcb32d51.06df8","type":"telegram receiver","z":"e8fec1f1.d46c7","d":true,"name":"/help","bot":"db43ddd0.9b459","saveDataDir":"","x":90,"y":100,"wires":[["d100118a.caee5"],[]]},{"id":"d100118a.caee5","type":"function","z":"e8fec1f1.d46c7","d":true,"name":"help funct","func":"//comments here testing again...\nvar helpMsg = \"/help - shows help\\n\"\nhelpMsg += \"/foo - opens a dialog\\n\\n\\n\"\nif (msg.payload.chatId === 760176267){\n helpMsg = \"R. Singh, Welcome sir!!!! \"\n}\nelse{\nhelpMsg += \"You are welcome, \"+ msg.originalMessage.from.username;\n}\nhelpMsg += \"Your chat id is: \" + msg.payload.chatId;\nmsg.payload.content = helpMsg\nreturn msg;","outputs":1,"noerr":0,"x":280,"y":40,"wires":[["d15c5bfa.0d8738"]]},{"id":"d15c5bfa.0d8738","type":"telegram sender","z":"e8fec1f1.d46c7","d":true,"name":"response from BOT","bot":"db43ddd0.9b459","x":530,"y":40,"wires":[["d38b5da7.daa43"]]},{"id":"d38b5da7.daa43","type":"debug","z":"e8fec1f1.d46c7","d":true,"name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":730,"y":40,"wires":[]},{"id":"7a930af1.0d88d4","type":"telegram receiver","z":"e8fec1f1.d46c7","name":"/help","bot":"db43ddd0.9b459","saveDataDir":"","x":50,"y":240,"wires":[["66c5029a.4dc8cc"],[]]},{"id":"4b33c9c5.0c6038","type":"debug","z":"e8fec1f1.d46c7","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":750,"y":400,"wires":[]},{"id":"612c98a1.b75a08","type":"telegram sender","z":"e8fec1f1.d46c7","name":"","bot":"db43ddd0.9b459","x":690,"y":320,"wires":[["4b33c9c5.0c6038"]]},{"id":"66c5029a.4dc8cc","type":"function","z":"e8fec1f1.d46c7","name":"help funct1","func":"var helpMsg = \"/help - shows help\\n\"\nhelpMsg += \"/foo - opens a dialog\\n\\n\\n\"\nif (msg.payload.chatId === 760176267){\n helpMsg = \"R. Singh, Welcome sir!!!! \"\n}\nelse{\nhelpMsg += \"You are welcome, \"+ msg.originalMessage.from.username;\n}\nhelpMsg += \"Your chat id is: \" + msg.payload.chatId;\nmsg.payload.content = helpMsg\n\nreturn msg;","outputs":1,"noerr":0,"x":190,"y":320,"wires":[["a094494f.5b0ce8","612c98a1.b75a08","4f037622.b1a0c8"]]},{"id":"a094494f.5b0ce8","type":"debug","z":"e8fec1f1.d46c7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":340,"y":400,"wires":[]},{"id":"4f037622.b1a0c8","type":"exec","z":"e8fec1f1.d46c7","command":"df / | awk 'FNR==2'","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"*nix command","x":360,"y":220,"wires":[["dc04d410.b91be8"],[],[]]},{"id":"9b4d5856.171c58","type":"debug","z":"e8fec1f1.d46c7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":700,"y":260,"wires":[]},{"id":"dc04d410.b91be8","type":"function","z":"e8fec1f1.d46c7","name":"send output","func":"//var msg1=msg.payload;\nmsg.payload.content = msg.payload\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":280,"wires":[["612c98a1.b75a08","9b4d5856.171c58"]]},{"id":"db43ddd0.9b459","type":"telegram bot","z":"","botname":"singh_is_king13","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"1000","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":true}]

```

Its recognizing my chat id by first function and providing me proper response on Telegram but NOT giving any output for df command in Telegram, though it gives me df command's output(exec toolkit) on DEBUG console. I have tried to search a lot but couldn't find solution, any help is greatly appreciated here.

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![realjax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/realjax/32/895_2.png) [@realjax](https://discourse.nodered.org/u/realjax)\
**Post date:** [10 March 2020 15:09 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/2 "2020-03-10T15:09:22Z")

</div>

Which telegram node are you using ? Seems there are multiple out there.

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [10 March 2020 16:01 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/3 "2020-03-10T16:01:35Z")

</div>

Hello realjax,

Thank you for your reply, if you mean type of buttons, then I am using telegram receiver and telegram sender 2 functions. Error is coming in telegram sender side.

My belief is exec module is loosing the Chat id from msg.payload. Any help will be greatly appreciated since I am working on this from last 4 to 5 hours and no luck yet, it prints the message correctly(unix command output) in DEBUG window but don't send it to Telegram.

Thanks,  
R. Singh

---

<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:** [10 March 2020 16:15 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/4 "2020-03-10T16:15:04Z")

</div>

The question which telegram nodes means what node did you install? Probably node-red-contrib-something.

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [10 March 2020 16:54 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/5 "2020-03-10T16:54:07Z")

</div>

Thank you for your reply Colin. Oh ok got it; I am using "node-red-contrib-telegrambot".  
Kindly do let me know in case of any more queries here, will be grateful for any guidance here.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 March 2020 17:27 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/6 "2020-03-10T17:27:09Z")

</div>

You need to save msg.payload.chatid to a flow variable because the `exec` node is creating a new msg.payload. Then before using the `telegram` out node you need to build  
msg.payload,content  
msg.payload.type  
msg.payload.chatid

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [10 March 2020 17:55 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/7 "2020-03-10T17:55:03Z")

</div>

> [@zenofmud](#):
>
> msg.paylkoad,content  
> msg.payload.type  
> msg.payload.chatid

Thank you for your reply.

I used following to create variables(custom ones) to save values before exec module:

```auto
flow.set('ChatID',msg.payload.chatId);

flow.set('content',msg.payload.content);

flow.set('type',msg.payload.type)

return msg;

```

Then after exec I created one function and used this to again assign them values:

```auto
msg.payload.chatId=global.get('ChatID');
msg.payload.content=global.get('content');
msg.payload.type=global.get('type');

```

But still I am getting same error, I know its a minor issue, trust me I am working on it now more than 7 hours or so ☹

Any help/guidance will be appreciated.

NOTE: Error again for reference is:

```auto
3/10/2020, 11:25:24 PMnode: 612c98a1.b75a08
msg : string[27]
"msg.payload.chatId is empty"

```

Thanks,  
R.Singh

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 March 2020 17:57 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/8 "2020-03-10T17:57:15Z")

</div>

can you provide your current flow?

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [11 March 2020 02:07 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/9 "2020-03-11T02:07:55Z")

</div>

Hello zenofmud,

Following is the flow details in form of js (note: This is a bit different from 1st post of mine, since I was keep doing experiments to fix the issue):

```auto
[{"id":"e8fec1f1.d46c7","type":"tab","label":"/help function in bot.","disabled":false,"info":""},{"id":"fcb32d51.06df8","type":"telegram receiver","z":"e8fec1f1.d46c7","d":true,"name":"/help","bot":"db43ddd0.9b459","saveDataDir":"","x":70,"y":20,"wires":[["d100118a.caee5"],[]]},{"id":"d100118a.caee5","type":"function","z":"e8fec1f1.d46c7","d":true,"name":"help funct","func":"//comments here testing again...\nvar helpMsg = \"/help - shows help\\n\"\nhelpMsg += \"/foo - opens a dialog\\n\\n\\n\"\nif (msg.payload.chatId === 760176267){\n helpMsg = \"R. Singh, Welcome sir!!!! \"\n}\nelse{\nhelpMsg += \"You are welcome, \"+ msg.originalMessage.from.username;\n}\nhelpMsg += \"Your chat id is: \" + msg.payload.chatId;\nmsg.payload.content = helpMsg\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":20,"wires":[["d15c5bfa.0d8738"]]},{"id":"d15c5bfa.0d8738","type":"telegram sender","z":"e8fec1f1.d46c7","d":true,"name":"response from BOT","bot":"db43ddd0.9b459","x":510,"y":20,"wires":[["d38b5da7.daa43"]]},{"id":"d38b5da7.daa43","type":"debug","z":"e8fec1f1.d46c7","d":true,"name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":710,"y":20,"wires":[]},{"id":"7a930af1.0d88d4","type":"telegram receiver","z":"e8fec1f1.d46c7","name":"/help","bot":"db43ddd0.9b459","saveDataDir":"","x":50,"y":240,"wires":[["9faef31b.5c1"],[]]},{"id":"4b33c9c5.0c6038","type":"debug","z":"e8fec1f1.d46c7","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":790,"y":120,"wires":[]},{"id":"612c98a1.b75a08","type":"telegram sender","z":"e8fec1f1.d46c7","name":"","bot":"db43ddd0.9b459","x":670,"y":180,"wires":[["4b33c9c5.0c6038"]]},{"id":"66c5029a.4dc8cc","type":"function","z":"e8fec1f1.d46c7","name":"help","func":"var helpMsg = \"/help - shows help\\n\"\ncontext.set(\"chatId\",msg.payload.chatId)\nhelpMsg += \"/foo - opens a dialog\\n\\n\\n\"\nif (msg.payload.chatId === 760176267){\n helpMsg = \"R. Singh, Welcome sir!!!! \"\n}\nelse{\nhelpMsg += \"You are welcome, \"+ msg.originalMessage.from.username;\n}\nhelpMsg += \"Your chat id is: \" + msg.payload.chatId;\nmsg.payload.content = helpMsg\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":180,"wires":[["a094494f.5b0ce8","612c98a1.b75a08"]]},{"id":"a094494f.5b0ce8","type":"debug","z":"e8fec1f1.d46c7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":100,"wires":[]},{"id":"fbb59e9d.943ff","type":"debug","z":"e8fec1f1.d46c7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":460,"wires":[]},{"id":"9faef31b.5c1","type":"switch","z":"e8fec1f1.d46c7","name":"check","property":"payload.content","propertyType":"msg","rules":[{"t":"eq","v":"help","vt":"str"},{"t":"eq","v":"df","vt":"str"},{"t":"eq","v":"df","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":190,"y":260,"wires":[["66c5029a.4dc8cc"],["a4d5e323.71f43"],["9a404f67.cc6b3"]]},{"id":"a4d5e323.71f43","type":"function","z":"e8fec1f1.d46c7","name":"df","func":"flow.set('ChatID',msg.payload.chatId);\nflow.set('content',msg.payload.content);\nflow.set('type',msg.payload.type)\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":260,"wires":[["733a5a27.28f004"]]},{"id":"9a404f67.cc6b3","type":"exec","z":"e8fec1f1.d46c7","command":"df -h / | awk 'FNR==2'","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"df","x":510,"y":400,"wires":[["fbb59e9d.943ff","8286b21e.de059"],[],[]]},{"id":"733a5a27.28f004","type":"debug","z":"e8fec1f1.d46c7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":410,"y":300,"wires":[]},{"id":"8286b21e.de059","type":"function","z":"e8fec1f1.d46c7","name":"","func":"msg.payload.chatId=global.get('ChatID');\nmsg.payload.content=global.get('content');\nmsg.payload.type=global.get('type');\n\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":280,"wires":[["612c98a1.b75a08","c5223391.62c21"]]},{"id":"c5223391.62c21","type":"debug","z":"e8fec1f1.d46c7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":720,"y":380,"wires":[]},{"id":"db43ddd0.9b459","type":"telegram bot","z":"","botname":"singh_is_king13","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"1000","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":true}]

```

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 March 2020 09:03 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/10 "2020-03-11T09:03:34Z")

</div>

Where are you storing your chat ID? (show the code)

Where do you get the chat ID? (show the code)

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [11 March 2020 09:07 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/11 "2020-03-11T09:07:13Z")

</div>

> [@RavinderSingh13](#):
>
> msg.payload.chatId=global.get('ChatID'); msg.payload.content=global.get('content'); msg.payload.type=global.get('type');

Hello zenofmud,

I pasted those variable initialization in my post#7, here are the details.

```auto
flow.set('ChatID',msg.payload.chatId);
flow.set('content',msg.payload.content);
flow.set('type',msg.payload.type);

msg.payload.chatId=global.get('ChatID');
msg.payload.content=global.get('content');
msg.payload.type=global.get('type');

```

First 3 lines have been put in function before executing exec module AND 2nd 3 statements have been put in another function before sending final data.

Kindly do let me know in case of any more information required.

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 March 2020 09:08 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/12 "2020-03-11T09:08:34Z")

</div>

now look at your code and tell me in words exactly where you store the chat id and where you get it from.

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [11 March 2020 09:15 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/13 "2020-03-11T09:15:07Z")

</div>

Hello zenofmud,

IMHO:

```auto
flow.set('ChatID',msg.payload.chatId);

```

is setting msg.payload.chatId to variable ChatID and likewise all others are doing the same IMHO. Isn't it the case?

Also code:

```auto
msg.payload.chatId=global.get('ChatID');

```

Is setting msg.paylaod.chatId from variable ChatID.

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 March 2020 09:28 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/14 "2020-03-11T09:28:43Z")

</div>

> flow.set('ChatID',msg.payload.chatId);

this is **setting** a flow variable called 'ChatID' to what is in msg.payload.chatId

> msg.payload.chatId=global.get('ChatID');

this is setting msg.payload.chatId to what is in the global variable 'ChatID'

can you see the problem?

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [11 March 2020 09:49 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/15 "2020-03-11T09:49:40Z")

</div>

> [@zenofmud](#):
>
> this is setting msg.payload.chatId to what is in the global variable 'ChatID'

Thank you for your response here zenofmud, so you mean I need to use `flow.get` method here?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 March 2020 09:56 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/16 "2020-03-11T09:56:33Z")

</div>

if you store something in location `A` can you expect to retreive it from location 'B'?  
You should read the documentation here: [https://nodered.org/docs/user-guide/context](https://nodered.org/docs/user-guide/context) and here: [https://nodered.org/docs/user-guide/writing-functions#storing-data](https://nodered.org/docs/user-guide/writing-functions#storing-data)

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [11 March 2020 10:11 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/17 "2020-03-11T10:11:08Z")

</div>

> [@zenofmud](#):
>
> You should read the documentation here: [Working with context : Node-RED](https://nodered.org/docs/user-guide/context) and here: [Writing Functions : Node-RED](https://nodered.org/docs/user-guide/writing-functions#storing-data)

Thank you zenofmud for your reply, I will check on it and post you in few hours(once I reach home) with my updated code.

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)\
**Post date:** [12 March 2020 09:58 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/18 "2020-03-12T09:58:20Z")

</div>

Hey Ravinder,

Good so see you here.

In general, it's often a good idea to build a new message object with the new or derived params and return that new message object instead of modifying the input message object.

For example,

Early in your flow, you might need to store the chatId.

This might be something like:

```auto
flow.set('ChatID',msg.payload.chatId);

```

Later in the same flow, you might need to build a new message object in Telegram. Telegram requires three params to send a message. You must have at least these three properties in a Telegram outgoing message:

- msg.payload.content
- message.payload.type
- mesage.payload.chatId

So later in your flow, you might do this:

```auto
var message = 'my brilliant message'; // message is required
var chat = flow.get('ChatID'); // chatid type is required
var type = 'message'; // message type is required
newMsg = {payload:{chatId:chat,type:type,content:message}};
return newMsg;

```

This is the generalized construct I use.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@RavinderSingh13](https://discourse.nodered.org/u/RavinderSingh13)\
**Post date:** [12 March 2020 11:44 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/19 "2020-03-12T11:44:38Z")

</div>

Hello All,

Thanks for your guidance and help here, I was able to do it last late night IST, I was able to do it with flow.set and flow.get variable. Where I had get values of chatid, content and type in 1st function before exec and then retrived them back in function after exec successfully. Right now I can't post code since I not on my machine. Will post codes in few hours.

@unixneo Thanks unixneo for letting know another of doing it too.

Appreciate help of zenofmud, Colin, realjax and unixneo here.

_EDIT:_ As promised previously in my reply here are my codes.

_function 1st(before using exec):_

```auto
//console.log("Chat id before:"+msg.payload.chatId);
var ChatID=flow.get('ChatID') // || 0;
//console.log("TYPE test value:"+msg.payload.type)
var TyPE=flow.get('TyPE')
var ConTent=flow.get('ConTent')
flow.set('ChatID',msg.payload.chatId);
flow.set('TyPE',msg.payload.type);
flow.set('ConTent',msg.payload.content);
console.log("Chatid value BEFORE:"+ChatID);
console.log("Type value BEFORE:"+TyPE);
console.log("Content value BEFORE:"+ConTent);
return msg;

```

_2nd function(after exec to retrieve values):_

```auto
var ChatID=flow.get('ChatID') || 0;
var TyPE=flow.get('TyPE') || 0;
var ConTent=flow.get('ConTent') || 0;
//console.log("AFTERRRRRR id value is:"+ ChatID)
var temp=msg.payload;
msg.payload = {};
msg.payload.chatId=ChatID;
msg.payload.type=TyPE;
msg.payload.content=temp;

console.log("Disk space AFTER chat id here:"+msg.payload.chatId);
console.log("Disk space AFTER type here:"+msg.payload.type);
console.log("Disk space AFTER content of message here:"+msg.payload.content);
return msg;

```

I am adding it so that it could help future users, cheers and happy learning 🙂

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 March 2020 11:46 UTC](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919/20 "2020-03-12T11:46:44Z")

</div>

> Will post codes in few hours.

@zenofmud - re-opening this as the few hours have not yet passed...

[Next page](https://discourse.nodered.org/t/solved-not-able-to-send-linux-commands-output-to-telegram/22919.md?page=2)
