Simultaneous Data Insertion: for Populating a Data...
# 📖tutorials
c
In this tutorial, we will explore a powerful feature that allows you to effortlessly input data into a Data Table right after a user provides their input. This functionality captures the data in real-time, eliminating the need to wait until the last node or input. It's an invaluable tool for those who need to capture data simultaneously, enabling efficient data management and analysis. It's a detailed tutorial that you can modify to suit your needs. > Thanks to @quick-musician-29561 for assisting me with complex processes and flows. Without his efforts, I wouldn't have been able to make this possible. > Also, thanks to @gray-activity-74012 for bringing this to my attention. [ ? ] Use Cases: - Real-time data capture - Simplified ecommerce workflows - Data analysis - Streamlined data management Lets begin with the tutorial now. __Create a Table:__ Create a Table from the left side menu ( Add Table ). We named ours
NamesTable
.
Open that table and create some rows (Name, Phone, Email). It will be needed later. Keep Reading!!
======================================================================= _Node: _ Part 1 : Can call this part as Previous Data Overwriting. Create a Node and add - Text (optional), - Raw Input (will be used as Name), - Execute code (code will be provided below), - Find Records, - expressions (one will be used to flow to the existing node , one will be used to flow to the new node) Now, click the Raw Input and set the
Question to ask the user
with your preferred text and then create a variable (name whatever you like, we named it
name
) to store the result.
Open the Execute Code and enter this code:
Copy code
workflow.firstLetterCapital = workflow.name.charAt(0).toUpperCase() + workflow.name.slice(1);
[ ? ] What it does? It capitalizes the first letter of the workflow's name variable (as we named our variable name). Moving to the next, open Find Records and select the Table, enter the value into
Records Filter
similar to this (depends on that variable u have set) :
Copy code
Name is either @workflow.name or @workflow.firstLetterCapital
And **Result Variable : **create a variable and name it (we named ours
userRow
)
Now, enter this code in *Label: *
Copy code
[previous steps result variable].length greater than zero
Note: change
[previous steps result variable]
*with yours. i.e ours was*
workflow.userRow
so the code was
Copy code
workflow.userRow.length greater than zero
It will execute as similar to this
workflow.userRow.length > 0
Its done. Moving to the last part of this node, theres a slight changes here. Input in Label:
Copy code
[previous steps result variable].length is zero
Will look in Condition as:
Copy code
workflow.userRow.length === 0
Now that you know how it works, lets do the remaining tasks a little faster. Create another node and add - Execute Code (one) - Code to enter:
Copy code
const firstName = workflow.name
const records = workflow.userRow
console.log("RECORDS: " + JSON.stringify(records))

workflow.record = records[0].id
Close. - Open Phone Number (Capture Information) and
Question to ask the user
with whatever you like and then create a variable (we named ours `phone`—example shown below)
- Update Record: Select the Table (ours called NamesTable), - Record ID*:
@workflow.record
(put this code as it was coded into the Execute Code earlier) - Phone:
@workflow.phone
Now, everything will look similar to this.
Create another node and add **Email Address **card and Update Record card Email Address: same as before, create a variable (we named
email
).
Update Record: select the table and same as Phones node (record id:
@workflow.record
) and Email:
@workflow.email
Part 2: Can call it as new data entry. Create a node > - phone : store result in >
workflow.phone
(same variable that was used before) - Insert Record : select the same table > Name:
@workflow.name
(no change required) - Phone:
@worfkflow.phone
- Email: Leave the email empty right now.
Next, create another node > Find Records : select Table (same), * Records Filter: *
Name equals @workflow.name
(same) * Result Variable: *
workflow.userRow
(same) Execute Code : (same as before in Part 1, you can just copy and paste from previous)
Copy code
const firstName = workflow.name
const records = workflow.userRow
console.log("RECORDS: " + JSON.stringify(records))

workflow.record = records[0].id
Email: copy and paste from the previous email card Update Record: copy and paste from the Update Record card. --------------------------------------------------------------------------------------------------------- Optional: You can create another node with texts lie Thank you for your info…blab la bla..Its upto you. ================================= Build Done =========================================== Time to test the bot. Here’s ours: Chat:
Existing Data overwritten and executed to this **output**:
And, for the new user part here how it looked like:
In Record section:
q
message has been deleted
What a great Tutorial! 🛠️ 🫡 Thanks @clean-holiday-47965
c
🔥 Thank you also for helping me out, @quick-musician-29561
c
wow!!!!! ❤️ I happen to know the person who selects Botbassadors 😉 let me know if you want to join the crew @clean-holiday-47965
c
That sounds exciting! I will definitely keep that in mind. But first i have to pass my exam (in 2 days). 🚀
c
let's goooo ! 🔥
c
@clean-holiday-47965 per our converstaion yesterday I see the thread is removed but I added the following video on the topic if you wanted to tell me if I i missed anything

https://youtu.be/APsP_PHZDCg?si=HDZM4fWjffO4wEXZ

g
It's magnificent, I find the final result incredible. You're a genius, my friend. @clean-holiday-47965 This information is very valuable. Thank you very much.
c
💠 I'm glad you find the final result magnificent and incredible! Your support and feedback are greatly appreciated!
Thanks to @crooked-ram-87124 for providing this valuable tutorial. Its useful in some cases. > Created a bot using his tutorial (below)! [ + ] Such As - Finding records inside the database - Writing records inside the database (similar to my tutorial) - It might be possible to overwrite data in existing records (I haven't tried yet) From my POV, I think the data insertion we did can also be done with the idea taken from his tutorial. And I tried a little bit (attached the file, feel free to use that too). > Also, attached my Simultaneous Data Insertion file. Feel free to use that too
Simultaneous Data Insertion file below:
j
yo, teach my expressions im still dumb with expressions
c
Suppose, u set "Users say i want coffee" inside the Label and it will automatically setup the expression code... And then u attach the expression with Coffee related node, Now, if user says i want coffee or anything related to coffee it will pass the user to that coffee node, Its basically a gateway towards the next node according to what user tells the bot.
j
so basicly an ai transition but the user alerady typed in their info
c
I am just thrilled to see you take a concept and mold an idea from it great work!!!! definitely not stealing any of your thunder this is awesome!
j
yo what is this tutorial about ?
c
Pretty much the same as ai transitions but advantage of this is -- it doesnt cost u extra ai token to execute This tutorial is about:- Suppose you want to capture data after every input user does. Even if user gets disconnected between chatting!!
j
👍
do this tutorial
if the user typed in his info incorectly
and he wants to redo it
delete the information in the table
c
I appreciate your feedback @crooked-ram-87124 🔥
j
like if he wants to redo his email delete his email and when he out in his email then you put in his email in the table
c
🔥 @jolly-policeman-82775 that's the answer of your question. Binding this with my above tutorial.... And you are good to go🔥
My this tutorial contains that.. This is already mentioned in my tutorial as Part 2... Existing Data Overwritten But u will just need to tweak some process to meet ur needs. U need to tell the user to confirm his data first then if he confirms he will able to change his data!
j
and you need code for that i thin
i dont know code
f
Hi there @clean-holiday-47965 I am a bit confused by what you mean with label?
c
@fresh-fireman-491 look at the " Open Find Records and select the Table...." we here pasted Name is either.... So we need to save the results right? To save the result just create a Variable and then in **expression**'s Label section..paste workflow.thatResultvariableUcreated.length grater than zero..and done!! Short summary: the Find records Result variable should be pasted in the expression... With that
Copy code
....length grater than zero
f
Thanks a lot
c
You're Welcome 🤟
a
@clean-holiday-47965 Test this out to see if it helps improve the user experience and capture. 1) Use AI Task to capture the user input. That way, it can be a single step ask instead of asking multiple steps. 2) AI Task also allows for users to choose either / or in the replies. e.g. any combi of name, number or email. 2) Store the variables in "user" rather than "workflow". That way, jumping nodes or ending workflows won't erase the captured variable and you can reference it at any point of the chat.
c
Hey @able-rocket-15603 thank you for your valuable feedback. It's amazing! However, I will add one more node or extra Raw Input card for the email (as I am using Reoon email verifier to validate the email through an API, which is working pretty well too!). The other suggestions you mentioned seem perfect to me!
b
excuse me man. Can You explain the utility of both formulas please ( the conditional ones ). Because everytime I enter a name, the worflow uses the second conditional formula, never the first one. Thankkkss
c
Hey @busy-cricket-64025 ! Can you tell me in a more detailed way about what exactly you did and where you are having issues? With what formula or expressions are you having problems? Screenshots would also be better.
b
hi ! it's okay I figured out how it's works. Thanks 🙂
c
Happy bot building ✌️
t
@clean-holiday-47965 if I use sql, can I do the same but using my tables ? I do not want to use botpress’s db, I want to use mine
It is a way of doing this @clean-holiday-47965 ?
c
yes possible but you need to send the data via api to ur sql
t
do u have an example ?
or do u now some github or idk
some link to see it
?
c
i dont have that as i havent connected or made something like that yet and i have less knowledge in database
t
if i have an api with some routes, botpress knows how to call it and read the response
and to do smt ?
@clean-holiday-47965
c
u need to use the POST to send data from botpress to ur proper table of sql and as far i know, you can also GET req from sql and save that response in the code using console.log and from there u can save the data into a variable
t
aha...and botpress to do smt with that variable
?
@clean-holiday-47965
c
didnt understand, can you be little more detailed?
t
Sure
You said that I can sa e data into a variable…I see that in botpress I can use variables, I was wondering if I can use those variables in botpress
@clean-holiday-47965
c
yes after capturing the info into variables you can use the variable in any workflow @thousands-raincoat-37715
t
danke
b
hey i encountered issue in find record card as this card is not accessing the id . what should i do now
c
can you elaborate your problem in my dm? lets see if i can help you with that @broad-postman-77251
5 Views