telegram: show name and id in envelope
This commit is contained in:
@@ -104,7 +104,9 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
||||
|
||||
const body = formatAgentEnvelope({
|
||||
surface: "Telegram",
|
||||
from: isGroup ? `group:${chatId}` : `telegram:${chatId}`,
|
||||
from: isGroup
|
||||
? buildGroupLabel(msg, chatId)
|
||||
: buildSenderLabel(msg, chatId),
|
||||
timestamp: msg.date ? msg.date * 1000 : undefined,
|
||||
body: rawBody,
|
||||
});
|
||||
@@ -208,6 +210,25 @@ function buildSenderName(msg: TelegramMessage) {
|
||||
return name || undefined;
|
||||
}
|
||||
|
||||
function buildSenderLabel(msg: TelegramMessage, chatId: number | string) {
|
||||
const name = buildSenderName(msg);
|
||||
const username = msg.from?.username ? `@${msg.from.username}` : undefined;
|
||||
let label = name;
|
||||
if (name && username) {
|
||||
label = `${name} (${username})`;
|
||||
} else if (!name && username) {
|
||||
label = username;
|
||||
}
|
||||
const idPart = `id:${chatId}`;
|
||||
return label ? `${label} ${idPart}` : idPart;
|
||||
}
|
||||
|
||||
function buildGroupLabel(msg: TelegramMessage, chatId: number | string) {
|
||||
const title = msg.chat?.title;
|
||||
if (title) return `${title} id:${chatId}`;
|
||||
return `group:${chatId}`;
|
||||
}
|
||||
|
||||
function hasBotMention(msg: TelegramMessage, botUsername: string) {
|
||||
const text = (msg.text ?? msg.caption ?? "").toLowerCase();
|
||||
if (text.includes(`@${botUsername}`)) return true;
|
||||
|
||||
Reference in New Issue
Block a user