mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat(telegram): render markdown and send author avatar photo
This commit is contained in:
parent
568e206643
commit
50ae8c7607
4 changed files with 175 additions and 32 deletions
|
|
@ -9,27 +9,13 @@ interface TelegramResponse {
|
|||
result?: { message_id?: number };
|
||||
}
|
||||
|
||||
export async function sendMessage(
|
||||
async function post(
|
||||
token: string,
|
||||
method: string,
|
||||
body: Record<string, unknown>,
|
||||
chatId: string,
|
||||
text: string,
|
||||
topicId?: string,
|
||||
): Promise<SendResult> {
|
||||
if (!token) {
|
||||
return { ok: false, error: "TELEGRAM_TOKEN not configured", errorCode: "NO_TOKEN" };
|
||||
}
|
||||
|
||||
const body: Record<string, unknown> = {
|
||||
chat_id: chatId,
|
||||
text,
|
||||
parse_mode: "HTML",
|
||||
disable_web_page_preview: true,
|
||||
};
|
||||
if (topicId) {
|
||||
body.message_thread_id = Number(topicId);
|
||||
}
|
||||
|
||||
const url = `${TELEGRAM_API}/bot${token}/sendMessage`;
|
||||
const url = `${TELEGRAM_API}/bot${token}/${method}`;
|
||||
let lastStatus = 0;
|
||||
let lastError = "";
|
||||
|
||||
|
|
@ -95,3 +81,48 @@ export async function sendMessage(
|
|||
attempts: 3,
|
||||
};
|
||||
}
|
||||
|
||||
export async function sendMessage(
|
||||
token: string,
|
||||
chatId: string,
|
||||
text: string,
|
||||
topicId?: string,
|
||||
): Promise<SendResult> {
|
||||
if (!token) {
|
||||
return { ok: false, error: "TELEGRAM_TOKEN not configured", errorCode: "NO_TOKEN" };
|
||||
}
|
||||
const body: Record<string, unknown> = {
|
||||
chat_id: chatId,
|
||||
text,
|
||||
parse_mode: "HTML",
|
||||
disable_web_page_preview: true,
|
||||
};
|
||||
if (topicId) {
|
||||
body.message_thread_id = Number(topicId);
|
||||
}
|
||||
return post(token, "sendMessage", body, chatId);
|
||||
}
|
||||
|
||||
export async function sendPhoto(
|
||||
token: string,
|
||||
chatId: string,
|
||||
photoUrl: string,
|
||||
caption?: string,
|
||||
topicId?: string,
|
||||
): Promise<SendResult> {
|
||||
if (!token) {
|
||||
return { ok: false, error: "TELEGRAM_TOKEN not configured", errorCode: "NO_TOKEN" };
|
||||
}
|
||||
const body: Record<string, unknown> = {
|
||||
chat_id: chatId,
|
||||
photo: photoUrl,
|
||||
parse_mode: "HTML",
|
||||
};
|
||||
if (caption) {
|
||||
body.caption = caption;
|
||||
}
|
||||
if (topicId) {
|
||||
body.message_thread_id = Number(topicId);
|
||||
}
|
||||
return post(token, "sendPhoto", body, chatId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue