I am experiencing a 404: NOT_FOUNDCode: NOT_FOUNDID: cdg1::jrnqx-1737508046559-0a0ea22d6922 error when trying to connect my Telegram bot (hosted on Vercel) to a Supabase database. Here are the key details:
- Supabase Configuration:
- Supabase URL and Service Role Key are correctly set as environment variables.
- The database project includes a
userstable, and Row Level Security (RLS) is enabled with appropriate policies forSELECT,INSERT, andUPDATEoperations. - A storage bucket (
william) has been created, and access policies for operations (SELECT,INSERT, etc.) have been configured.
- Vercel Configuration:
- My Telegram bot is hosted on Vercel and uses the
supabase-pylibrary to connect to Supabase. - All necessary environment variables (
SUPABASE_URLandSUPABASE_SERVICE_ROLE_KEY) have been added to Vercel's project settings.
- Issue:
- Database requests from the bot (such as inserting or fetching data) result in a
404: NOT_FOUNDerror. - Supabase logs do not show any activity, suggesting the requests are not reaching the database.
- Steps Taken to Troubleshoot:
- Verified that the
SUPABASE_URLandSUPABASE_SERVICE_ROLE_KEYare correct and working locally. - Confirmed that the
userstable exists and has the proper schema for storing user data. - Tested Supabase policies to ensure RLS is not blocking access.
- Confirmed that the
williambucket exists and is accessible with valid policies.
Current Behavior:
My webhook, hosted on Vercel, is unable to connect to the Supabase database. It keeps returning the error:
404: NOT_FOUNDCode: NOT_FOUNDID: cdg1::jrnqx-1737508046559-0a0ea22d6922
Expected Behavior: The webhook should successfully communicate with the Supabase database and return bot is running "Bot is running"
from http.server import BaseHTTPRequestHandlerimport osimport jsonimport asyncioimport requestsimport datetimeimport iofrom telebot.async_telebot import AsyncTelebotfrom supabase import create_client, Clientfrom telebot import typesfrom telebot.types import InlineKeyboardMarkup, InlineKeyboardButton, WebAppInfo
# Initialize BotBOT_TOKEN = os.environ.get('BOT_TOKEN')bot = AsyncTelebot(BOT_TOKEN)
# Initialize SupabaseSUPABASE_URL = os.environ.get("SUPABASE_URL")SUPABASE_KEY = os.environ.get("SUPABASE_SERVICE_ROLE_KEY")supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
# Supabase storage bucketbucket_name = "william"
def generate_start_keyboard(): keyboard = InlineKeyboardMarkup() keyboard.add(InlineKeyboardButton("Open William app", web_app=WebAppInfo(url="https://williamfrontend.netlify.app/"))) return keyboard
@bot.message_handler(commands=['start'])async def start(message): user_id = str(message.from_user.id) user_first_name = str(message.from_user.first_name) user_last_name = message.from_user.last_name user_username = message.from_user.username user_language_code = str(message.from_user.language_code) is_premium = getattr(message.from_user, 'is_premium', False) text = message.text.split()
welcome_message = ( f"Hi, {user_first_name}! 👋
" f"Welcome to William Drop Memecoin Airdrop!
" f"Here you can earn coins by mining or by spending!
" f"Invite friends to earn more coins and level up faster! 🚀" )
try: user_data = { 'userImage': None, 'firstName': user_first_name, 'lastName': user_last_name, 'username': user_username, 'languageCode': user_language_code, 'isPremium': is_premium, 'referrals': {}, 'balance': 0, 'mineRate': 0.001, 'isMining': False, 'miningStartedTime': None, 'daily': { 'claimedTime': None, 'claimedDay': 0, }, 'links': None, }
photos = await bot.get_user_profile_photos(user_id, limit=1) if photos.total_count > 0: file_id = photos.photos[0][-1].file_id file_info = await bot.get_file(file_id) file_path = file_info.file_path file_url = f"https://api.telegram.org/file/bot{BOT_TOKEN}/{file_path}"
# Download the image response = requests.get(file_url) if response.status_code == 200: # Wrap content in a file-like object file_data = io.BytesIO(response.content) file_name = f"user_images/{user_id}.jpg" supabase.storage.from_(bucket_name).upload(file_name, file_data)
# Generate public URL user_image = supabase.storage.from_(bucket_name).get_public_url(file_name) user_data['userImage'] = user_image
# Handle referral code if len(text) > 1 and text[1].startswith('ref_'): referrer_id = text[1][4:] referrer = supabase.table('users').select("*").eq('id', referrer_id).execute()
if referrer.data: referrer_data = referrer.data[0] user_data['referredBy'] = referrer_id
bonus_amount = 500 if is_premium else 100 new_balance = referrer_data['balance'] + bonus_amount referrals = referrer_data.get('referrals', {}) or {}
referrals[user_id] = { 'addedValue': bonus_amount, 'firstName': user_first_name, 'lastName': user_last_name, 'userImage': user_data['userImage'], }
# Update referrer in the database supabase.table('users').update({ 'balance': new_balance, 'referrals': referrals, }).eq('id', referrer_id).execute()
# Save user data to the database supabase.table('users').upsert(user_data).execute()
keyboard = generate_start_keyboard() await bot.reply_to(message, welcome_message, reply_markup=keyboard)
except Exception as e: error_message = "Error. Please try again!" await bot.reply_to(message, error_message) print(f"Error: {str(e)}")
class Handler(BaseHTTPRequestHandler): def do_POST(self): content_length = int(self.headers['Content-Length']) post_data = self.rfile.read(content_length) update_dict = json.loads(post_data.decode('utf-8'))
asyncio.run(self.process_update(update_dict))
self.send_response(200) self.end_headers()
async def process_update(self, update_dict): update = types.Update.de_json(update_dict) await bot.process_new_updates([update])
def do_GET(self): self.send_response(200) self.end_headers() self.wfile.write("Bot is running".encode())Configuration:
- Environment variables are set in Vercel:
SUPABASE_URLSUPABASE_SERVICE_ROLE_KEY
- Database
userstable schema has been created in Supabase. - Row-Level Security (RLS) is enabled for the
userstable, and appropriate policies forINSERTandSELECToperations are in place.
Steps to Reproduce:
- Deploy the webhook to Vercel.
- Trigger any operation that communicates with the Supabase database (e.g., inserting a new user).
github for links https://github.com/Mhatem1995/Williambackend/tree/main/api
Project Information
Framework: Python, http.server for handling requests, using supabase-py for database interaction.
Environment: Deployed on Vercel, environment variables are configured properly in the Vercel dashboard.
Project Settings: The users table is in the public schema. Realtime is enabled, and RLS policies have been configured to allow authenticated access.
screens:-
[grid]
[/grid]




