Comments (9)
Tested. Subflow access to chat context from global context works in 0.5.9-beta. Thanks.
from node-red-contrib-chatbot.
@BrandonSmith should be
var chat = context.flow.get('chat:' + chatId); chat.get(...)
from node-red-contrib-chatbot.
@guidone context
is what I started out with, but has the same result.
var chatId = msg.originalMessage.chat.id
console.log(chatId)
var chat = context.flow.get('chat:' + chatId)
console.log(chat)
chat.get('email')
Results with:
G1429V2JH
undefined
2 Sep 15:05:53 - [error] [function:Email payload scrub] TypeError: Cannot read property 'get' of undefined
However, if the listen node and function node are executing from the top-level flow, everything works as expected:
G1429V2JH
{ get: [Function: get],
set: [Function: set],
dump: [Function: dump],
all: [Function: all] }
from node-red-contrib-chatbot.
@guidone I think the issue is in chatbot-listen.js
. Namely, the ChatContext is retrieved from the flow context or created if it doesn't exist. In the condition it doesn't exist, the locally created ChatContext never gets put back into the flow context.
The following patch seems to work:
var chatContext = context.flow.get('chat:' + chatId);
if (!chatContext) {
chatContext = ChatContext(chatId);
context.flow.set('chat:' + chatId, chatContext);
}
from node-red-contrib-chatbot.
Good catch @BrandonSmith , I'll include your fix tomorrow
Thanks!
from node-red-contrib-chatbot.
@BrandonSmith I've pushed a fix in 0.5.8
But it's strange, your fix is right but the chat context is always created in a receiver node.
Is it possible that you used a receiver node in the top level flow and the listen node in a subflow?
Subflows don't share the same context with the top level flow, I can fix it by storing all the chat contexts in the global context, in this way they will be available everywhere.
Thanks for your feedback
from node-red-contrib-chatbot.
That is the exact configuration I am exploring... Receive and send in the top-level flow and reusable bits in subflows.
Again, I'm a node-red newb and am only just learning the difference between node, flow, and global contexts. Seems like it would be a common use case to want data living owning flow contexts to be injected into subflows. I understand the value of a "pristine" context being created so that subflows don't make any assumptions about context. What is the idiomatic node-red way here? Is there a simple way of lifting context values and pass as explicit inputs into a subflow?
from node-red-contrib-chatbot.
The node context is available just in the node, and is cleared every time the node is redeployed.
Flow context is available for all nodes of the flow but not subflow, it's cleared when the flow is redeployed.
Global is available for every flow.
I'm not sure about what is the idiomatic way but
- it's ok to store chat data in the global context, generally in hosted environment like FRED, they run multiple instance of Node-Red for different customers, so any sensitivie information that might be stored in global context is not exposed
- it's better to store in chat context the results of parsing, etc in order to not mix informations of concurrent users of the chat bot
I've a branch ready for that, it moves the chat context under the global context, so it's available via script in subflows
// get the chat context
var chatId = msg.originalMessage.chat.id
var chat = context.global.get('chat:' + chatId);
Unfortunately it's a breaking change, I'll push in a while with a beta release tag, I'll keep you posted.
from node-red-contrib-chatbot.
ok @BrandonSmith, would you like to try
npm install [email protected]
from node-red-contrib-chatbot.
Related Issues (20)
- Documentation: Changelog is being populated with 'Untitled'
- Feature request: add phone number information HOT 1
- feature request: linkedin messenger
- npm ERR! errno ETIMEDOUT HOT 1
- Snyk vulnerabilities HOT 1
- Image URL param support?
- Telegram Webhook not responding
- An example of how to create mediaGroup?
- Telegram pinned_message
- MC not working in Docker HOT 1
- Viber Images
- install error on node red on pi HOT 6
- Uncaught Exception in Text node HOT 1
- Unable to install from Palette / Docker HOT 3
- Can I use this package to integrate with home-made web-app bot?
- FR: Support MarkdownV2 in Telegram messages.
- Elements not recognized
- Could not login to Mission Control
- FR: Support for Telegram reactions
- Tutorial for messenger
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-red-contrib-chatbot.