Using Google Sheets as a Base for a GPT Bot (Instead of Notion)
The reason for writing this article was the departure of Notion from Russia, since we were actively connecting databases in Notion to our GPT bots (article about this: https://habr.com/ru/articles/820377/)
So, let's say we have this table:
Step #1: Create a GPT Bot
It's very easy to make a GPT bot and link it to Telegram on ProTalk:
Immediately upon creating the bot, we will link it to Telegram:
Step #2: Connect the function to the bot
First, let's go to the function catalog and search for the query: “what to use for google database“.
We connect the found function to the bot:
Step #3: Create a role for the GPT bot
In order for our AI consultant to be able to filter data by apartments, we need to explain to it what columns are in our table (database), this is how it can be done:
Ты должна подбирать квартиры на основе данных в таблице:
https://docs.google.com/spreadsheets/d/1wcKA2__qfMjImLUiEOhK-lHUf0_rt5tmc-dvYEqepro/edit?usp=sharing
Колонки для запроса из таблицы: A - H
Для фильтрации используй эти колонки:
`С` - Цена аренды (в сутки) - числовое поле
`В` - Размер квартиры в м2 - числовое поле
`G` - VIP сегмент - фиксированные значения: `Да`, `Нет`
Testing the bot
For example, let's give our bot the following request: “I need VIP but not more than 2400“.
And this is what we will see in the answer:
Conclusion
If you have any questions while creating such integration, please write in the comments or to me at Telegram and I will try to answer your questions.
P.S. Function code
For those who want to do this integration themselves, here is the code for the filtering function itself:
def get_filtered_google_table(arguments):
import requests
import csv
from io import StringIO
import re
url = arguments['url']
sheet_index = (arguments.get('sheet_index', 1)) - 1
filter_query = arguments.get('filter_query', '')
pattern = r"/spreadsheets/d/([a-zA-Z0-9-_]+)"
spreadsheet_id = re.findall(pattern, url)[0]
file_url = f'https://docs.google.com/spreadsheets/d/{spreadsheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_index}&tq={filter_query}'
response = requests.get(file_url)
csv_content = response.content.decode('utf-8')
csv_reader = csv.reader(StringIO(csv_content.replace(" ", ",")), delimiter=",")
csv_rows = list(csv_reader)
return csv_rows
Here is an example of a function call:
arguments = {
'url': 'https://docs.google.com/spreadsheets/d/1wcKA2__qfMjImLUiEOhK-lHUf0_rt5tmc-dvYEqepro/edit?usp=sharing',
'filter_query': 'SELECT A, B, C, E WHERE C > 2000 AND E LIKE "%балкон%"'
}
filtered_data = get_filtered_google_table(arguments)