Telegram-WatsonAssistan msg.payload.chatId is empty

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.

{"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"}
{"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

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

Done. Sorry, it's my first post.

1 Like

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?

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. Like I said in my first post (other thread), I use the Node-Red that's on my computer, not the IBM Cloud.

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 :wink: )

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.

I recommend watching this playlist: Node-RED Essentials. 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)

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.

1 Like

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 thechange node after the "assistant" node set msg.chatId to flow.chatId and now you have the chatId back in the msg.

1 Like

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 :wink:

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

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