mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-23 00:21:28 +00:00
feat(telegram): send author avatar as richheader link-preview card
Serve an OG page at /api/richheader and use a small link-preview card (avatar + author name) above the message instead of sending a photo.
This commit is contained in:
parent
be50d23319
commit
fc2e2c2efa
5 changed files with 61 additions and 1 deletions
40
src/web/richheader-routes.ts
Normal file
40
src/web/richheader-routes.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { Hono } from "hono";
|
||||
|
||||
function esc(s: string): string {
|
||||
return String(s)
|
||||
.replace(/&/g, "&")
|
||||
.replace(/"/g, """)
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">");
|
||||
}
|
||||
|
||||
export function createRichHeaderRoutes(): Hono {
|
||||
const app = new Hono();
|
||||
|
||||
app.get("/richheader", (c) => {
|
||||
const title = c.req.query("title") ?? "";
|
||||
const content = c.req.query("content") ?? "";
|
||||
const avatar = c.req.query("avatar") ?? "";
|
||||
|
||||
const html = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:site_name" content="${esc(title)}">
|
||||
${content ? `<meta property="og:title" content="${esc(content)}">` : ""}
|
||||
${avatar ? `<meta property="og:image" content="${esc(avatar)}">` : ""}
|
||||
</head>
|
||||
<body style="font-family: system-ui, -apple-system, sans-serif; text-align: center; padding: 40px; max-width: 600px; margin: 0 auto;">
|
||||
${avatar ? `<img src="${esc(avatar)}" alt="Avatar" style="width: 128px; height: 128px; border-radius: 50%; margin-bottom: 20px;">` : ""}
|
||||
${title ? `<h1 style="margin: 0 0 10px 0; color: #333;">${esc(title)}</h1>` : ""}
|
||||
${content ? `<p style="margin: 0; color: #666;">${esc(content)}</p>` : ""}
|
||||
<p style="margin-top: 40px; font-size: 14px; color: #999;">This page is used for Open Graph meta tags (richheader) only.</p>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
return c.html(html);
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue