Stuck at importing workflow variables in my node j...
# 🤝help
b
I am a noob dev trying to create a chatbot for simple data gathering from the user. I have setup a simple node server for the backend and a react frontend. I used the carousel to output data after fetching it using the 'execute code'. But what I ideally would like to do is gather all the information from user through the chatbot and once we are at end of the conversation (user has answered all the questions), I would like to exit out of chatbot and move to a new route and get the user data I collected using chatbot inside my node js server so I can work on it and show results on the new route. If my question is unclear please let me know. In simpler terms I just want to show the search results of my users query in a separate page rather than inside the bot. fyi I have just used the botpress studio to make the bot and added the script to the html page. I have done nothing related to botpress inside my node js server.
f
Hey there, Would you like to look at the data yourself ever so often or is it something that you want to show the user right after their chat closed?
b
I wanted to ask the user their preferences, make a query in the db with those preferences and show the results in a different page (instead of inside the bot with carousel etc)
so once all the quesitons are answered
right after that move to results page where I will show the data received from db
I watched the botpress developer playlist and got the custom trigger event to get the variables to the FE. So I think most of my problems have been solved using that. But again if there is a better way or more correct way I am interested
f
Alrighty. Little disclaimer. I am still new to React, but I can help you a bit. Idea of a high-level approach you can take: 1. In your Botpress chatbot, collect the user's preferences through a series of questions and store the responses in variables within the chatbot's context. 2. Once all the questions are answered instead of displaying the results inside the chatbot using a carousel you can make an API call from the chatbot to your Node.js server. This API call will send the collected user preferences to the server. 3. In your Node.js server create an API endpoint that receives the user preferences from the chatbot. Use these preferences to query your database and retrieve the relevant results. 4. After retrieving the results from the database your Node.js server can send a response back to the chatbot indicating that the data is ready and providing a unique identifier or token associated with the user's session. 5. Upon receiving the response from the server the chatbot can display a message to the user informing them that their results are ready and provide a link or button to navigate to the results page. 6. When the user clicks on the link or button you can redirect them to a new route in your React application, passing the unique identifier or token as a parameter in the URL. 7. In your React application create a new component or page for displaying the search results. When this component mounts, it can make another API call to your Node.js server, passing the unique identifier or token from the URL. 8. Your Node.js server can then use the identifier or token to retrieve the previously stored search results associated with the user's session and send them back to the React component. 9. Finally your React component can render the search results on the page allowing the user to view them outside of the chatbot interface. Simplified flow:
Copy code
User -> Chatbot -> Node.js Server -> Database -> Node.js Server -> React App (Results Page)
You can use it as a starting point. Its really not perfect!
b
this is great. I had not thought of utilisng identifier to tell that the we have received a response.
My appraoach went completely different where I send the workflow variables to frontend and then sent an api request from there
thanks for such a thorough reply. Must've been a pain to write but very clear.
f
You should also be able to do that. You can probably use the "Send Custom Event" card.
b
Yes I did that. But it was nowhere to be found in the documentation. Well more accurately I wasn't able to find it in documentation, not that it isn't there. But in documentation I could only see how to send data to the bot and not how to get it from bot. The old botpress developer videos on YouTube mentioned it and I used it.
3 Views