Use Google Sheets as a Database

4.34k views927 WordsCopy TextShare
Typebot
In this video I show you how you can use the Google Sheets block in Typebot to store credits for you...
Video Transcript:
so a user asked me if it would be possible to have a bot that would only answer the question if the user has enough credits so would it be possible to implement a sort of a credit stuff uh maybe with the Google sheet integration and in fact so yeah I worked on this uh a bit on this MVP and I'll just show you how it works so basically we have this spreadsheet with just two columns the email column and the credits column and so the idea is that we will we keep track of the available
credits for a specific user based on its email on his email and each time the user ends ask a question we remove one credit from the store and if it does if he doesn't have any credit left we just ask him to purchase more credits so let me walk you through this but so it's a great example of how the Google Sheets block can be used as a database of some sort so we first ask for the email and we check if uh the the row on the spreadsheet already has this email so we get
the data and we filter it with email equal to the valuable email so the variable is just collected here and then we extract the column uh so we extract only the credits uh column so yeah we might also rename these credits but for now it's credit so the idea is now if so first let's talk about this case if credit is empty it means that credit does not exist so it means that the email wasn't created at all so we don't have a row for that specific email so the idea is that we will be
connected to this create new account group that will set the credits to one and we say okay you have one free credit and then we insert a row with that specific email and that new credit variable so then we jump to the ask a question group we ask a question he answers and we remove one credit from the existed credit amount we update the row with the new credit count as you can see for the update we filter out with the email email equal to the valuable email and we update the credits variable with the
new credit uh that has been updated here with -1 and then we jump to the check credits group again so we we move here again and we have now two other cases so the first one would be if credit is equal to zero it means that the user doesn't have any credits left and we just tell him okay you don't have any credits left purchase more credit and we could have several options you could maybe you know add a payment block with it so that you make sure that the the user has to to pay
for the credits and so here we I don't plug it to any system I just you know add the add the credit amount based on the the user's choice and we just update the row with the new credit variable so it works as the same as this one and then we ask again the question we remove one credit once we have the answer and we jump again to the check credits and let me talk about the you know the the third case which is okay credit is superior to zero credit is not empty it means
it exists so we just have to jump to ask a question group and we just you know jump to this group so we have a you know a call system here where the user can ask a question and the answer is equal to one credit so let me just show you a simple case so let's create a new email so we won't get any data from the sheet so we'll go to that block create a new account you have one free credit ask a question so let me show you in the spreadsheet okay there is
this new test at test.com with one free credit uh so we ask a question question and there we remove One Credit One Credit One credit we update the row and as you can see you don't have any credits left purchase more credit if we check out our spreadsheet we don't have any credits left so that's true let's add three credits we update the row let's take it out okay we have three credits indeed and now you know the idea is that if I'm leaving now and I just restart the bot and I say okay I'm
test at test.com is that it yes he will say okay ask a question and I can ask several questions because I have three credits left so now I have two credits left I can again ask a question and our last question and I'm redirected to you don't have any credits left so yeah you can create that kind of system with Google sheet as your database and yeah Google sheet is an example you could also use any other type of database like service such as airtable or anything even though we don't have a an airtable integration
on type but at the moment but soon we will So yeah thank you for watching and uh and catch you guys in the next one bye
Copyright © 2024. Made with ♥ in London by YTScribe.com