TypeError: message.chat is not a function

Hello,

i try to send a text to a telagram bot, but i get the follow error:
"TypeError: message.chat is not a function"

I use a function

msg.payload = {}
msg.payload.chatId = "my id"
msg.payload.type = 'message'
msg.payload.content = 'hello from nodered'
return msg;

This function ist conected to the "Telegram Sender"

First you should identify the node from where the error is fired. With this description the function is fine.

Hello,

in the Picture you can see my flow and the debug window.
I think the reason for the fault is the function, but i don't know. Sorry i'm a beginner.

If you hover mouse over the node id in debug panel it will highlight the node from the error is fired. May be it is from other tab, but in ths tab you have only one function without name so it may come from that also.

Node is node-red-contrib-chatbot, judging by the code in the opening post. Have you read the wiki for the node? Its documentation is in need of approval as you have to switch between pages to learn what it does/how it works, but it’s there, or was there a month or so ago.

I’m sick in bed (and extremely bored) at the moment, so you’ll have to verify this on the wiki. The nodes use a lot of things internally, including msg.chat. This function is defined by several nodes and added to the message object. It handles all the inner workings.

To get it to work, you need to either connect a telgram in to telegram response (with nodes in between), or use the conversation node to start responding without a direct incoming event. If you use the forum search, you can find a topic where I showcase exactly this in response to a user whose name I can’t remember at the moment (sorry Paul? David? I realky don’t know I’m going to blame the fever) However, keep in mind that version17.0 of this set of nodes introduced a bug with the conversation node that last I heard wasn’t solved yet. Best to downgrade or stay at 16.x to not have to deal with it at the moment. More about this on the github issues page of node-red-contrib-chatbot.

Look at the wiki for the conversation node and read the builtin help for it, it should explain how you have to do this. In most of my own flows I think I keep/set authorised users after first connecting to an object I keep in the (persistent) context with name and chatId so I can get them back whenever I want to have outgoing messages again. If you can find my flow, it has exactly that put in use, it was the first time I implemented it that way.

Good luck!

1 Like