Skip to content

fix: telegram-bot, add cdn links + return error #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions supabase/functions/telegram-bot/index.ts
Original file line number Diff line number Diff line change
@@ -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/[email protected]/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/[email protected]/mod.ts";

const bot = new Bot(Deno.env.get("BOT_TOKEN") || "");

Expand All @@ -16,15 +13,21 @@ 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);
if (url.searchParams.get("secret") !== Deno.env.get("FUNCTION_SECRET")) {
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!`);