/** * User helper functions * @module helpers/user-helpers */ import type { User } from '../api/types/index.js'; /** * User-like object that can be from Telegram or custom source * Supports both Telegram API User and custom user objects */ export interface UserLike { id: number; username?: string; first_name?: string; last_name?: string; } /** * Format user as display string * Returns username with @ prefix, or full name, or "User {id}" as fallback * * @param user - User object (Telegram User or custom) * @returns Formatted string: "@username" | "FirstName LastName" | "User {id}" * * @example * ```typescript * const display = formatUserUrl(telegramUser); * // "@johndoe" or "John Doe" or "User 123456" * ``` */ export declare function formatUserUrl(user: UserLike | User | null | undefined): string; /** * Parse mode type for mentions * Can be ParseMode constant ('HTML', 'MarkdownV2') or null for plain URL */ export type MentionParseMode = 'HTML' | 'MarkdownV2' | 'Markdown' | null; /** * Format user as mention with optional formatting * Creates mentions for use in messages with different parse modes * * @param user - User object * @param parseMode - Parse mode: ParseMode.HTML, ParseMode.MARKDOWN_V2, or null (default: null) * @param text - Custom display text (optional, defaults to formatUserUrl) * @returns Formatted mention string * * @example * ```typescript * import { formatUserMention, ParseMode } from '@vvlad1973/telegram-bot-client'; * * // Plain text (default) - returns Telegram mention URL * const mention = formatUserMention(user); * // "tg://user?id=123456789" * * // HTML format using ParseMode constant * const htmlMention = formatUserMention(user, ParseMode.HTML); * // "@johndoe" * * // HTML with custom text * const customHtml = formatUserMention(user, ParseMode.HTML, 'Click here'); * // "Click here" * * // Markdown format * const mdMention = formatUserMention(user, ParseMode.MARKDOWN_V2); * // "[\\@johndoe](tg://user?id=123)" * * // Usage in messages * await bot.sendMessage({ * chat_id: 123, * text: `Hello ${formatUserMention(user, ParseMode.HTML)}!`, * parse_mode: ParseMode.HTML * }); * * await bot.sendMessage({ * chat_id: 456, * text: `Welcome ${formatUserMention(user, ParseMode.MARKDOWN_V2)}!`, * parse_mode: ParseMode.MARKDOWN_V2 * }); * ``` */ export declare function formatUserMention(user: UserLike | User, parseMode?: MentionParseMode, text?: string): string;