Parsing text sent from Telegram

Hi all, I've been using Node-Red for a few months for a school project, and it's great.

I'm trying to do something that is probably simple, but I don't even know what terms to search for.

I want to write simple text messages on my phone, and have Node-RED record them in a database. I already got the database working, I'm just having trouble using and parsing what I get from Telegram.
So, for example, I want to record that I just let my cat Plump out (he's old and can't jump, so he stays in front of the door when it's sunny, and he doesn't wander away. He knocks on the door when wants back in)

So, I type "Plump out" on my phone, and a debug node after the Telegram receiver node in Node-RED outputs this:

Screenshot 2022-03-02 at 11.35.53

Object
chatId: 8xxxxxx0
messageId: 42
type: "message"
content: "Plump out"
date: 1646220823

The question is: how do I get the "Plump out" and the timestamp parts to use them in say a switch node and in other functions and to log it into my db?

Thanks!

You need to read this page and pay attention to When you hover over any element, a set of buttons appear on the right: This will show you how to get the paths to the valuesfrom your object.

https://nodered.org/docs/user-guide/messages

So you need to translate the incoming msg into one suitable for the DB node that you are using.

Sharing the db node you want to use would help here as we could advise on the correct format. If your DB supports "prepared" statements, you should use those so that your input is relatively safe being fed into the table. You should also ALWAYS sanitise any external input before trying to feed it to the table.

To get to the text content in the example you have given, you would need to use msg.payload.content since Node-RED uses JavaScript conventions throughout.

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