# Telegram-WatsonAssistan msg.payload.chatId is empty

**URL:** <https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128>\
**Category:** General\
**Created:** [4 August 2020 11:15 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128 "2020-08-04T11:15:47Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carbar](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@Carbar](https://discourse.nodered.org/u/Carbar)\
**Post date:** [4 August 2020 11:15 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/1 "2020-08-04T11:15:47Z")

</div>

Following Steve-Mcl advice in another post, I attach screen dumps and the message sent and received. So that you can see the whole process and the final error. Vode-RED is installed in my computer.

 ![1 Telegram-Watson](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f95ad16230eabc206d7919f420f50c30139b84e5.png)

 ![2 Reste](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/4/14629956e55a4d0e3bf134e10a7fd6c1747728c6.png)

```auto
{"payload":{"chatId":803280482,"messageId":76,"type":"message","content":"Hola"},"originalMessage":{"message_id":76,"from":{"id":803280482,"is_bot":false,"first_name":"C....s","last_name":"B....l","language_code":"es"},"chat":{"id":803280482,"first_name":"C....s","last_name":"B....l","type":"private"},"date":1596536712,"text":"Hola"},"_msgid":"fb8a5ea8.0a267"}

```

```auto
{"payload":{"intents":[{"intent":"saludos","confidence":1}],"entities":[],"input":{"text":"Hola"},"output":{"generic":[{"response_type":"text","text":"Saludos. ¿En qué puedo ayudarle hoy?"}],"text":["Saludos. ¿En qué puedo ayudarle hoy?"],"nodes_visited":["node_1_1593875544566"],"log_messages":[]},"context":{"conversation_id":"9e2b5b04-5ab7-4918-a159-1dcbe7dc4c08","system":{"initialized":true,"dialog_stack":[{"dialog_node":"root"}],"dialog_turn_counter":2,"dialog_request_counter":2,"_node_output_map":{"node_1_1593875544566":{"0":[1,1,2,0]}},"branch_exited":true,"branch_exited_reason":"completed"}}},"originalMessage":{"message_id":76,"from":{"id":803280482,"is_bot":false,"first_name":"C....s","last_name":"B....l","language_code":"es"},"chat":{"id":803280482,"first_name":"C....s","last_name":"B....l","type":"private"},"date":1596536712,"text":"Hola"},"_msgid":"fb8a5ea8.0a267"}

```

Regards

---

<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:** [4 August 2020 11:17 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/2 "2020-08-04T11:17:27Z")

</div>

Hi before anyone can help you will need to fix your post. (Use the pencil icon to edit it)

To make code more readable and importable it is important to post it between two sets of three backticks - ``` - see this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![Carbar](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@Carbar](https://discourse.nodered.org/u/Carbar)\
**Post date:** [4 August 2020 11:24 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/3 "2020-08-04T11:24:34Z")

</div>

Done. Sorry, it's my first post.

---

<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:** [4 August 2020 11:52 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/4 "2020-08-04T11:52:49Z")

</div>

So as i much suspected and alluded to in your first post (other thread), something in your flow is causing the issue.

Your first debug has the chatId (as expected)

Your second debug does not.

This is because you pass it through the "assistant" node (whatever that is) and it seems that node is not playing nicely - most nodes will only update the properties of msg & pass on the original message (meaning msg.chatId stays present).

there is a workaround but first, what is this assistant node? Does it have an option to retain original msg object? The workaround is a cludge (storing the chatId in context and restoring it after the "assistant node".

Do you _need_ this assistant node? Can you achieve whatever it does another way?

---

<div class="post-metadata">

**Author:** ![Carbar](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@Carbar](https://discourse.nodered.org/u/Carbar)\
**Post date:** [4 August 2020 13:54 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/5 "2020-08-04T13:54:57Z")

</div>

Thank you for your time @Steve-Mcl. This "assistant" node connects to a chatbot in the IBM cloud, it returns the response to the input from Telegram "Hola" ==\> Wiston Assistant "Saludos. ¿En qué puedo ayudarle hoy?, so far it works.

I'm following this IBM tutorial, [Archived | Integrate Watson Assistant and Telegram with Node-RED](https://developer.ibm.com/technologies/artificial-intelligence/tutorials/integrate-coversation-service-with-telegram-using-node-red/). Like I said in my first post (other thread), I use the Node-Red that's on my computer, not the IBM Cloud.

---

<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:** [4 August 2020 14:14 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/6 "2020-08-04T14:14:29Z")

</div>

I can only comment on what I see - and if I am not mistaken, I see the "assistant" node is **not** returning the `chatId` property back in the returned `msg`. And yes, this might be related to running node-red locally & not in the cloud.

So 1 possible work around is using a join node connected to output of "prepare for conversation" and to output of "assistant". The join node would be set for manual mode, key/object & set for 2 parts. Then that would feed into "Prepare for telegram" function. That function would also need modifying to create the payload from the slightly different `msg.payload` it receives from the join node (just needs shuffling around a bit - which you can easily figure out by attaching a `debug` to the output of the `join` and seeing what comes out of it (clue, its the original msg you send from "Prepare for Conversation" and the "Assistant" nodes)). Note also, the join node will need incoming messages to have different topics (something simple like "before\_assistant" and "after\_assistant" - anything to differentiate the messages will do)

It would be worth your while trying to achieve this yourself (Its much harder to explain in text than to achieve) - you would learn a fair bit about node-red. Win win.

Iif you need help achieving that, I will need you to export your flow for me (I aint typing all that code in by hand 😉 )

---

<div class="post-metadata">

**Author:** ![Carbar](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@Carbar](https://discourse.nodered.org/u/Carbar)\
**Post date:** [4 August 2020 14:23 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/7 "2020-08-04T14:23:08Z")

</div>

Thanks again for your answer. I'll try looking at the Node-RED documentation. I only started a week ago and this is my first attempt.

---

<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:** [4 August 2020 14:24 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/8 "2020-08-04T14:24:36Z")

</div>

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). It is by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in less than an hour. A small investment for a lot of gain. It even covers the Join node (if I remember right)

---

<div class="post-metadata">

**Author:** ![Carbar](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@Carbar](https://discourse.nodered.org/u/Carbar)\
**Post date:** [4 August 2020 14:36 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/9 "2020-08-04T14:36:57Z")

</div>

I will. At first I didn't find it difficult to work with Node-Red, you drag the nodes, copy the functions, put the tokens, apis and the rest of the configurations and that's it.

---

<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:** [4 August 2020 14:49 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/10 "2020-08-04T14:49:39Z")

</div>

> [@Steve-Mcl](#):
>
> So 1 possible work around

Another workaround would be to add a `change` node both before and after the "assistant'" node. In the one before the "assistant" node, set a a flow variable (say `flow.chatId`) to `msg.payload.chatId`. In the`change` node after the "assistant" node set `msg.chatId` to `flow.chatId` and now you have the chatId back in the msg.

---

<div class="post-metadata">

**Author:** ![Carbar](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@Carbar](https://discourse.nodered.org/u/Carbar)\
**Post date:** [4 August 2020 18:33 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/11 "2020-08-04T18:33:13Z")

</div>

Solved. msg.playload return `{"chatId":803280482,"messageId":96,"type":"message","content":"Hola"}`. **chatId** not **chatID**.

In both functions I had chatID, that's why it didn't work. I changed everything to chatId and it works perfectly.

Thanks again to @Steve-Mcl and @zenofmud for your help. I'll watch the videos anyway 😉

---

<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:** [4 August 2020 18:38 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/12 "2020-08-04T18:38:46Z")

</div>

> [@Carbar](#):
>
> I'll watch the videos anyway

I definitely recommend it. There are some gems in there that will make your time in node-red a lot smoother.

---

<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:** [3 October 2020 18:38 UTC](https://discourse.nodered.org/t/telegram-watsonassistan-msg-payload-chatid-is-empty/31128/13 "2020-10-03T18:38:49Z")

</div>

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