guidone / node-red-contrib-chatbot

Visually build a full featured chat bot for Telegram, Facebook Messenger, Whatsapp and Slack with Node-RED. Almost no coding skills required.
http://red-bot.io
936 stars 190 forks source link

Unable to find context().global in Node-RED #28

Closed henksc closed 7 years ago

henksc commented 7 years ago

Hi

I tried the simple Telegram example. It shows its connected, but when sending a message I get 'Unable to find context().global in Node-RED' in the debug screen. I'm using node-red 0.15.2 on IBM Bluemix.

What can this be ?

Thanks Henk

chameleonbr commented 7 years ago

+1

henksc commented 7 years ago

I checked two things:

Any ideas why this is not working in the Telegram example?

guidone commented 7 years ago

Hi @henksc , for some reason in the latest versions of NodeRed the nodes are not able to access the global context, with node.context().global in some circumstances.

This is strange I was not able to reproduce it in any way, so I just put some defensive code and what you see in the error console is actually just a warning.

A question: do you see that error multiple times of just once? After the first error are you able to receive telegram messages and use the chat context?

I suspect that the setup of the global context is after the telegram bot is started, in this way the first telegram message finds a node.context().global null. It's just an hypothesis.

Thanks for the feedback

henksc commented 7 years ago

hi @guidone, thanks for replying. I did some new tests, but I still get the same result. The node connects ok to Telegram. When I send a Telegram message, I get the error message. It appears every time I send a new message, so not just once. Also, I have no access to the chat context from a connected node. I'm new to NodeRed code, but wouldn't calling 'self.error' halt the further execution of the function?

Thanks!

guidone commented 7 years ago

Ok, that helps, I still not able to reproduce the error or to figure out why the global context is empty.

I'm going to prepare a patch that falls back on the flow context if the global one is not available, would you like to test it when it's ready? (later today)

Thanks

10p30pl3 commented 7 years ago

+1

henksc commented 7 years ago

Hi, yes I'm happy to help testing.

emanuelstanciu commented 7 years ago

+1, @guidone is there any update on this? thanks

guidone commented 7 years ago

Hi all, I think I've a solution for that, I am testing it a little bit more and then I'll send it out. Thanks for the patience

guidone commented 7 years ago

Ok, this should fix that

npm install node-red-contrib-chatbot@0.6.7-beta

can some one test it?

Thanks

davidpp commented 7 years ago

I literally just got this problem and you posted a fix just a minute before ? wow, let me install it and will let you know.

For reference, I was testing with Smooch webhook :

5 Dec 17:03:08 - [error] [chatbot-smooch-node:d16785e6.ad4618] Unable to find context().global in Node-RED

davidpp commented 7 years ago

@guidone with 0.6.7-beta I don't get the global error, but I still have an error when Smooch call the webhook on a new message :

5 Dec 17:07:44 - [error] [chatbot-waiting:816005b8.8f63e8] This node is not available for transport: smooch

I just discovered node-red and Redbot, so it might simply be a simple config error on my end.

guidone commented 7 years ago

@davidpp yes this is a node config error, there's no way to send a "writing..." like message through smooch, API doesn't allow it (as far as I know it). You can use it with Telegram and Facebook

davidpp commented 7 years ago

Yeah just realized that, thanks for the help! Well in this case, 0.6.7 does fix the issue 👍

guidone commented 7 years ago

Fixed in in 0.6.7

henksc commented 7 years ago

Thanks a lot for the fix @guidone ! Works perfectly now.