Matrix chatbot to process commands

Hello

Every family member has a matrix.org-account and we share a chatroom to communicate. I would like to add a chatbot to that room.

That chatbot could take action via Node-Red if some 'commands' are given. But I don't know where to start. If I search for 'matrix' I get:

  • node-red-contrib-matrix, but that one was active 4 years ago and the documentation isn't that much.
  • node-red-contrib-matrix-chat is updated 5 months ago and seems to have better documentation with examples. As a description it mentions 'Matrix chat server client', but I think I only need a Matrix client as I don't want to run my own server. It seems like overkill for my purpose. Or do I misinterpret that?
  • node-red-contrib-matrixbot is updated 3 years ago and mentions 'Matrix bot nodes for Node-RED'. The documentation isn't very elaborate, but it seems to mention the things I need:
    ** Matrix sender: sends messages from your Node-RED flow to the chatroom
    ** Matrix receiver: listens to messages in a chatroom and sends them to your Node-RED flow
    ** Matrix command: listens only to messages starting with a specific command and sends them to your Node-RED flow
  • node-red-contrib-matrixbot-markdown is updated 3 years ago and is a fork of the previous.

What would offer me the easist way of doing things? I have Node-RED 3.0.2, node.JS v16.20.2 and npm v8.19.4.

The first thing I would like to do is my chatbot to ask every evening if I want 'domestic hot water' in the morning. Standard it would be 'no', but if one of the family members answers with yes the flow would set the desired temperature to 51 °C. The reason is that I would like to experiment with getting my 'self use' of PV power a bit higher.

Hi,

Did you find a solution? I'm looking for something similar myself. But mostly for notifications for me.

@Gibbz, not yet :frowning: . I'm still hoping somebody could provide some instructions...

Did you look at the docs in that repo?

There are payload examples and a flow screenshot too.


Also, the nodes have a little built in help:

matrix sender

An output Matrix node that sends a message to a chatroom. This can be text of an image.

Sends the msg.payload property as text to the chatroom.

  • msg.payload: Text to be sent

When sending an image, msg.payload needs the following values:

  • msg.payload["content"]: Binary data containing the image
  • msg.payload["raw"]: Empty sting "" works (TODO: Not sure what this value does)
  • msg.payload["imgType"]: mime type of the image eg. image/jpeg
  • msg.payload["type"]: String "image"
  • msg.payload["text"]: String for the filename

An example:

// This should be the picture in binary format
var binbuffer = msg.payload
var mimetype = "image/jpeg"
var filename = "test.jpg"
msg.payload = { content: binbuffer,
                raw: "",
                imgType: mimetype,
                type: "image",
                text: filename
};
    

In both cases, msg.roomId can be specified (which is filled by receiver nodes) or in the configuration node.

  • msg.roomId: ID of the room where it was sent

matrix receiver

An input Matrix node that outputs messages received in a chatroom.

Outputs a message with the properties:

  • msg.payload: text of the received message
  • msg.sender: ID of the sender
  • msg.roomId: ID of the room where it was sent

Note: When an image is sent to the room, msg.payload will only contain the filename, the image itself is not received. TODO??

matrix command

An input Matrix node that triggers the output when a command is received from the chatroom.

Outputs a message with the properties:

  • msg.payload: rest of the received text (excluding the command)
  • msg.sender: ID of the sender
  • msg.roomId: ID of the room where it was sent
  • msg.originalMessage: text sent in the chat (including the command)

1 Like

@Steve-Mcl, thanks for pointing me to the docs in the repo of node-red-contrib-matrixbot. I managed to setup a quick test to send to a matrix room. I also tested 'matrix receiver' and although it seems to pick up most of the messages, it doesn't pick up every message.