Giter Site home page Giter Site logo

Comments (32)

guidone avatar guidone commented on September 24, 2024 1

from node-red-contrib-chatbot.

Batman781 avatar Batman781 commented on September 24, 2024

some infos about stack error:
TypeError: msg.chat is not a function at TelegramOutNode.<anonymous> (/root/.node-red/node_modules/node-red-contrib-chatbot/chatbot-telegram-receive.js:391:29) at emitOne (events.js:77:13) at TelegramOutNode.emit (events.js:169:7) at TelegramOutNode.Node.receive (/usr/lib/node_modules/node-red/red/runtime/nodes/Node.js:211:14) at FunctionNode.Node.send (/usr/lib/node_modules/node-red/red/runtime/nodes/Node.js:198:14) at sendResults (/usr/lib/node_modules/node-red/nodes/core/core/80-function.js:47:18) at FunctionNode.<anonymous> (/usr/lib/node_modules/node-red/nodes/core/core/80-function.js:184:21) at emitOne (events.js:77:13) at FunctionNode.emit (events.js:169:7) at FunctionNode.Node.receive (/usr/lib/node_modules/node-red/red/runtime/nodes/Node.js:211:14) at ChangeNode.Node.send (/usr/lib/node_modules/node-red/red/runtime/nodes/Node.js:133:22) at ChangeNode.<anonymous> (/usr/lib/node_modules/node-red/nodes/core/logic/15-change.js:245:22...

from node-red-contrib-chatbot.

Batman781 avatar Batman781 commented on September 24, 2024

Issue still persist, tried some different things, but it appears chat object is not preserved during session transition between different flows like mine

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

@gabbiano83 sorry for taking so long to answer.

Basically in msg.originalMessage and msg.chat() are stored all information needed to track the current conversation with the end user.
As general pattern in node-red a node should manipulate the inbound message just adding/changing the value in msg.payload and keeping the original msg object.

So no matter how many node you could chain, at the end of the flow in the outbound message you should be able to find the right msg.originalMessage and the method msg.chat().
If this is not happening means that some node in the flow is cleaning up the msg object.

I don't know how it's designed your flow but you could place a debug node out of every inner node and check where the .chat() method disappears, then we can give a look at that node and find a work around.

Meanwhile I can improve the error handling in case the chat() method is not found

from node-red-contrib-chatbot.

Batman781 avatar Batman781 commented on September 24, 2024

Thanks, I guess that, but my main issue is that currently I'm using a flows with MQTT to send remotely "msg.payload" only.
Do you have any idea about how I can preserve msg.originalMessage?
I've already tried to move msg.originalMessage on msg.payload.originalMessage field and after the message receive on the remote site move back msg.payload.originalMessage to msg.originalMessage, but this issue still persist.

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

ok, the chat() method is not essential in the outbound node, the originalMessage should be enough, I can fix it and then try if your solution to put back the originalMessage works

from node-red-contrib-chatbot.

Batman781 avatar Batman781 commented on September 24, 2024

Grazie :)

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

@gabbiano83 ok can you try this beta version (I've to fix more bugs before a release)

npm install [email protected]

from node-red-contrib-chatbot.

Batman781 avatar Batman781 commented on September 24, 2024

Funziona!!!!!!!!
It works

Grazie mille :)

from node-red-contrib-chatbot.

TJphonix avatar TJphonix commented on September 24, 2024

Same issue for me, @guidone
I have 0.9.25 version.
If i try to install beta version as suggested, doesn't wotk (probably because my actually version is newest).

Did you think i must to uninstall my actyally version and install the old beta you suggest before?

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

Yes the beta is old, perhaps it’s a different problem.
Can you send exactly what you see in system console?

from node-red-contrib-chatbot.

TJphonix avatar TJphonix commented on September 24, 2024

"TypeError: message.chat is not a function"
the same error of @gabbiano83

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

Can you share the flow (export), in this way I can debug on my box?

from node-red-contrib-chatbot.

TJphonix avatar TJphonix commented on September 24, 2024

[{"id":"2e65bf09.2da18","type":"chatbot-telegram-send","z":"f65fe3d9.4eac4","bot":"ecd8cf46.a180a","botProduction":"","track":false,"outputs":0,"x":1027,"y":190,"wires":[]},{"id":"e1dea7ab.5cf378","type":"link in","z":"f65fe3d9.4eac4","name":"From MQTT","links":["369d9092.04346","935c5e87.642e2","e312e8e8.277d08"],"x":276,"y":246,"wires":[["278f8bf6.343b14"]]},{"id":"bbb93433.48ad28","type":"link in","z":"f65fe3d9.4eac4","name":"From Telegram","links":["b6fc05e7.ef79b8"],"x":279,"y":431,"wires":[["179d0689.90bcc9"]]},{"id":"fcded81d.969fd8","type":"debug","z":"f65fe3d9.4eac4","name":"Telegram Response","active":true,"console":"true","complete":"payload","x":1047,"y":264,"wires":[]},{"id":"278f8bf6.343b14","type":"change","z":"f65fe3d9.4eac4","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":479,"y":244,"wires":[["f04066b.6275f98"]]},{"id":"f04066b.6275f98","type":"join","z":"f65fe3d9.4eac4","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","x":756,"y":389,"wires":[["fcded81d.969fd8","2e65bf09.2da18"]]},{"id":"179d0689.90bcc9","type":"change","z":"f65fe3d9.4eac4","name":"","rules":[{"t":"delete","p":"payload.content","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":497,"y":432,"wires":[["f04066b.6275f98"]]},{"id":"ecd8cf46.a180a","type":"chatbot-telegram-node","z":"","botname":"vodaxxx_bot","usernames":"","polling":"1000","store":"","log":"/var/log/Node-RED_Telegram_vodaxxx_bot.log","parseMode":""}]

from node-red-contrib-chatbot.

TJphonix avatar TJphonix commented on September 24, 2024

However, when i send a flow to "Telegram Sender" activity, what is the format of structure it expect? Can you post an example? So i think to remap input data for this activity

from node-red-contrib-chatbot.

TJphonix avatar TJphonix commented on September 24, 2024

Update:
i created a custom function between previus palette and telegram sender palette with this code:

var chatId = msg.payload.chatId;
var userId = msg.payload.userId;
var messageId = msg.payload.messageId;
var transport = msg.payload.transport;
var authorized = msg.payload.authorized;
var message = msg.payload.message;
var firstName = msg.payload.firstName;
var type = msg.payload.type;
var ts = msg.payload.ts;
var inbound = msg.payload.inbound;
var content = msg.payload.content;

msg.payload = {
	type: type,
	chatId: chatId,
	userId: userId,
	ts: ts,
	transport: transport,
	inbound: inbound,
	content: content/*,
	messageId: messageId,
	authorized: authorized,
	message: message,
	firstName: firstName*/
};
return msg;

It seems that the issue come from msg.payload.content.
If i set content variable to a static string like "hello world", the flow works fine, otherwise if i set this one to msg.payload.content, sometimes works, other times got error.

Note that msg.payload.content is set once a time from other activities, depending from various conditions

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

Seems to me that you're trying to work directly with the internals of Telegram sender and this is fundamentally wrong, there are a lot of higher level nodes to send text messages, images, etc.
More: the internal behaviour is likely to change in the next versions and any code dealing directly to it will break.

https://d.pr/i/yCXNL8

This kind of error happens when something that is not e RedBot message is sent to Telegram sender (yes, it could more robust and perform some kind of check).

What exactly are you trying to accomplish - at hight level - with this flow?

from node-red-contrib-chatbot.

TJphonix avatar TJphonix commented on September 24, 2024

I want to accomplish a request/replay activity with command send by telegram.

The received telegram command is forwarded to a subflow that execute an activity.
One of this activity send a message to MQTT sender, so the receiver MQTT perform the action and send back the answer that i want to send back to chat user by telegram.

Another activity triggered by telegram command, is to execute a pre set system command and send back the output to telegram.

The main requirement is to replay on the same chat started by a user (anyone user can send commands to my chat bot, but i will provide soon a restriction to allowed users only).
I can't use the "conversation" activity for my purpose because the chatId input is needed to be passed statically, and in my purpose chatId is a variable value assigned to a user that start conversation.
If there is a way to pass chatId dynamically to this activity, i will solve my issue.

Any suggestion to this?

Thanks

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

Yes it's possible

https://github.com/guidone/node-red-contrib-chatbot/wiki/Conversation-node

The parameters chatId and transport can be passed through the payload by the upstream Function node:

msg.payload = {
  chatId: '42' // your variable here
};
return msg;

it should work

from node-red-contrib-chatbot.

TJphonix avatar TJphonix commented on September 24, 2024

so i have to put a function actvity before conversation activity with this code (properly modified for my purpose), and leave blank chatId field into conversation activity?

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

exactly, all redbot nodes work in this way, it's always possible to specify parameters programmatically in the payload

from node-red-contrib-chatbot.

TJphonix avatar TJphonix commented on September 24, 2024

Ok i will try and replay you soon for confirmation...

from node-red-contrib-chatbot.

TJphonix avatar TJphonix commented on September 24, 2024

OK it works!
Solved using Conversation activity between Join and Telegram Sender Activity.
In conversation activity Transport and Telegram Bot must be configured while ChatId and MessageId must be leaved blank.

Attributes must be passed by payload (these come from Join Activity), so the flow works great.

Thank you very much !

image

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

Perfect!

from node-red-contrib-chatbot.

joancorbella avatar joancorbella commented on September 24, 2024

Hi,
I like to send to telegram the value of variable stored on msg.payload from mqtt value.
How I can send this value?

Best

from node-red-contrib-chatbot.

joancorbella avatar joancorbella commented on September 24, 2024

Many thanks guidone

from node-red-contrib-chatbot.

Barabba11 avatar Barabba11 commented on September 24, 2024

I have the same problem, I send a msg.payload with a simple string and I've the error ((
Why there is no description informations and not example?

[{"id":"15439243.067de6","type":"inject","z":"502fd5ce.9341e4","name":"","topic":"","payload":"1000","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":280,"wires":[["d685eb58.6f967"]]},{"id":"d685eb58.6f967","type":"function","z":"502fd5ce.9341e4","name":"","func":"msg = {payload:\"prova ciao\"}\nreturn msg;","outputs":1,"noerr":0,"x":110,"y":380,"wires":[["2a584f05.57239","c410c6fb.5d903"]]},{"id":"2a584f05.57239","type":"chatbot-telegram-send","z":"502fd5ce.9341e4","bot":"487af552.539ccc","botProduction":"487af552.539ccc","track":false,"passThrough":false,"outputs":0,"x":280,"y":440,"wires":[]},{"id":"487af552.539ccc","type":"chatbot-telegram-node","z":"","botname":"Domotica","usernames":"","providerToken":*********************","polling":"1000","store":"3a955f86.7602d","log":"","parseMode":"","debug":false},{"id":"3a955f86.7602d","type":"chatbot-context-store","z":"","name":"","contextStorage":"memory","contextParams":""}]

What is the difference betwen token and provider token? What users field is for?
Also I can't receive nothing with Telegram receiver..

from node-red-contrib-chatbot.

Barabba11 avatar Barabba11 commented on September 24, 2024

I've tried also to add message node, but no output from it.
WHen I deploy now NR take 10 seconds.. (before less then 1)

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

You need to put a conversation node (https://github.com/guidone/node-red-contrib-chatbot/wiki/Conversation-node) before everything

from node-red-contrib-chatbot.

Barabba11 avatar Barabba11 commented on September 24, 2024

Thank you for your kind answer. I follower your scheme, now I don't have more the error, but I don't understand to whom I'm sending messages, where should I specify the destination contact? Maybe the bot just write into its chat, and who is connected to it.. all can see. I'v eno idea.
I'm sending messaged to it from phone and I got an error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: connect ETIMEDOUT 149.154.167.220:443" in the consolle. On the phone the message is sent and delivered, not read. I'm in Russia and it looks like a limitation, but with my phone I?m under the same wifi and the phone works..
both sender and receiver have the status connected

from node-red-contrib-chatbot.

guidone avatar guidone commented on September 24, 2024

These topics are already covered in the wiki and this thread

https://github.com/guidone/node-red-contrib-chatbot/wiki/Start-conversation

Telegram has issues in Russia, it's blocked, that could be the reason of the timeout

from node-red-contrib-chatbot.

Barabba11 avatar Barabba11 commented on September 24, 2024

Thank you, it is not blocked because under the same Wifi I connected my mobile phone and Telegram works. Most of probability new version of the app is using a server which is not blocked. How can I help you to find it?
Also, what is the logic to have a status "connected" (it means it verified the token, server is not blocked) and then have a timeout?

from node-red-contrib-chatbot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.