Using node-red, I receive messages from Telegram which are formatted like:
{
"payload": {
"chatId": 12345,
"messageId": 1,
"type": "message",
"content": "Hi_._MainChat"
},
"originalMessage": {
"message_id": 1,
"from": {
"id": 1234567890,
"is_bot": false,
"first_name": "John",
"username": "JohnDoe",
"language_code": "en"
},
"chat": {
"id": 12345,
"first_name": "John",
"username": "JohnDoe",
"type": "private"
},
"date": 1590504750,
"text": "Hi_._MainChat"
},
"_msgid": "3be22fdd.3c9f5"
}
I want to split the content
at '_._
' and store the left ("Hi") and the right ("MainChat") part in two variables for later use. Could one be so kind and assist me how to do this?
I tried a function like
// Split the message content to extract text and origin
var text = {};
text.payload = (msg.originalMessage.text.split("_._"))[0];
text.type = "text";
var origin = {};
origin.payload = (msg.originalMessage.text.split("_._"))[1];
origin.type = "origin";
msg.payload.text = text.payload;
msg.payload.origin = origin.payload;
return [text,origin];
but failed miserably.