From e9d3d4a3d65aedd9373d137cd381e50dfa48f1af Mon Sep 17 00:00:00 2001 From: Guillaume Duhan <31253241+guillaumeduhan@users.noreply.github.com> Date: Fri, 3 Mar 2023 12:10:53 +0000 Subject: [PATCH] fix: add cdn links + return error --- supabase/functions/telegram-bot/index.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/supabase/functions/telegram-bot/index.ts b/supabase/functions/telegram-bot/index.ts index b06d508..46b014d 100644 --- a/supabase/functions/telegram-bot/index.ts +++ b/supabase/functions/telegram-bot/index.ts @@ -1,12 +1,9 @@ -// Follow this setup guide to integrate the Deno language server with your editor: -// https://deno.land/manual/getting_started/setup_your_environment -// This enables autocomplete, go to definition, etc. +import { serve } from "https://deno.land/std@0.168.0/http/server.ts"; -import { serve } from "std/server"; - -console.log(`Function "telegram-bot" up and running!`); - -import { Bot, webhookCallback } from "grammy"; +import { + Bot, + webhookCallback, +} from "https://deno.land/x/grammy@v1.14.1/mod.ts"; const bot = new Bot(Deno.env.get("BOT_TOKEN") || ""); @@ -16,6 +13,8 @@ bot.command("ping", (ctx) => ctx.reply(`Pong! ${new Date()} ${Date.now()}`)); const handleUpdate = webhookCallback(bot, "std/http"); +console.log(`Bot is running!`); + serve(async (req) => { try { const url = new URL(req.url); @@ -23,8 +22,12 @@ serve(async (req) => { return new Response("not allowed", { status: 405 }); } - return await handleUpdate(req); + const response = await handleUpdate(req); + return response; } catch (err) { console.error(err); + return new Response("error", { status: 400 }); } }); + +console.log(`Function "telegram-bot" up and running!`);