I'm new inPython and to learn about this language I decided to create Telegram BOT. I have the problem trying to connect with supabase, idk if the problem is syntax or or am I forgetting something.
I need to get a random document using RPC (Stores Procedures) with this code but I receive an error:
/Users/alvarogoederivera/web/python_bot/lib/python3.8/site-packages/telegram/ext/dispatcher.py:555: RuntimeWarning: coroutine 'random_quote' was never awaited
handler.handle_update(update, self, check, context)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
import logging
import asyncio
import os
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from supabase_py import create_client, Client
from dotenv import load_dotenv
load_dotenv()
url: str = os.getenv("SUPABASE_URL")
key: str = os.getenv("SUPABASE_KEY")
token: str = os.getenv("TELEGRAM_TOKEN")
supabase: Client = create_client(url, key)
#Conf Logging
logging.basicConfig(
level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger()
def start(update):
logger.info(f"El usuario {update.effective_user['username']}, ha iniciado")
name = update.effective_user['first_name']
update.message.reply_text(f"Hola {name} yo soy tu bot")
async def random_quote(update, context):
quote = await supabase.rpc('get_random_quote', {})
print(quote)
# user_id = update.effective_user['id']
# logger.info(f"el usuario {user_id} ha solicitado una frase")
# context.bot.sendMessage(chat_id = user_id, parse_mode="MarkdownV2", text=f"_Frase_ *x*")
def echo(update, context):
user_id = update.effective_user['id']
logger.info(f"el usuario {user_id} ha enviado un mensaje")
text = update.message.text
context.bot.sendMessage(chat_id = user_id, parse_mode="MarkdownV2", text=f"_escribiste_ *{text}*")
if __name__ == "__main__":
bot = telegram.Bot(token = token)
updater = Updater(bot.token)
dp = updater.dispatcher
loop = asyncio.get_event_loop()
loop.run_until_complete(random_quote({}, {}))
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("random", random_quote))
dp.add_handler(MessageHandler(Filters.text, echo))
updater.start_polling()
print("BOT LOAD")
updater.idle()
Does anyone know how to get the data?
I recently found out how to get the data from supabase, to do so you have to try something like this:
data = supabase.table('users').select('id').eq('id', un).execute()
or
data = supabase.table('users').select('stuff').execute()
Essentially what this is saying is that I want it to select the table called users, then I want to select all the id's that are equal to the object called un
and then once you want to view that data, you use something like this:
data.get('data')
This wil return everything that matches the value of un:
[{'id': 'NotNazuh'}]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.