21 lines
737 B
TypeScript
21 lines
737 B
TypeScript
/**
|
|
|
|
* 企微群机器人 markdown/text 消息 @ 成员扩展语法。
|
|
|
|
* @see https://developer.work.weixin.qq.com/document/path/91770
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** 生成 `<@userid>` 片段 */
|
|
|
|
export function formatWecomAtMention(wecomUserId?: string | null): string {
|
|
|
|
const uid = (wecomUserId || '').trim();
|
|
|
|
return uid ? `<@${uid}>` : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 若正文未含 `<@userid>` 则前缀追加 */
|
|
|
|
export function applyWecomAtMentionInContent(content: string, wecomUserId?: string | null): string {
|
|
|
|
const text = (content || '').trim();
|
|
|
|
const atTag = formatWecomAtMention(wecomUserId);
|
|
|
|
if (!atTag) return text;
|
|
|
|
if (!text) return atTag;
|
|
|
|
if (text.includes(atTag)) return text;
|
|
|
|
return `${atTag} ${text}`;
|
|
|
|
}
|
|
|
|
|