MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / sendAnswerOrTelegraph

Method sendAnswerOrTelegraph

deepwiki/deepwiki.ts:765–799  ·  view source on GitHub ↗
(
    msg: Api.Message,
    replyToId: number | undefined,
    headerLines: string[],
    question: string,
    answerMarkdown: string,
    collapseSafe: boolean
  )

Source from the content-addressed store, hash-verified

763 }
764
765 private async sendAnswerOrTelegraph(
766 msg: Api.Message,
767 replyToId: number | undefined,
768 headerLines: string[],
769 question: string,
770 answerMarkdown: string,
771 collapseSafe: boolean
772 ): Promise<void> {
773 const signature = `<i>🍀Powered by DeepWiki</i>`;
774 const html = buildQAHtml(headerLines, question, answerMarkdown, collapseSafe);
775 const finalHtml = html.length + `\n${signature}`.length <= MAX_TG_LEN ? `${html}\n${signature}` : `${html}`;
776
777 if (finalHtml.length <= MAX_TG_LEN) {
778 await MessageSender.sendNew(msg, finalHtml, "html", replyToId, false);
779 return;
780 }
781
782 const headerText = headerLines
783 .filter(Boolean)
784 .map((l) => l.replace(/<[^>]+>/g, ""))
785 .join("\n");
786 const telegraphMarkdown = (headerText ? `${headerText}\n` : "") + `**Q:**\n${question}\n**A:**\n${answerMarkdown}\n`;
787 const telegraphResult = await this.createTelegraphPage(telegraphMarkdown, question);
788
789 const qBlock = collapseSafe ? `Q:\n<blockquote expandable>${escapeHtml(question)}</blockquote>\n` : `Q:\n${escapeHtml(question)}\n`;
790
791 const linkHtml = `📰内容比较长,Telegraph观感更好喔:\n🔗 <a href="${telegraphResult.url}">点我阅读内容</a>`;
792 const aBlock = collapseSafe ? `A:\n<blockquote expandable>${linkHtml}</blockquote>` : `A:\n${linkHtml}`;
793
794 const header = headerLines.filter(Boolean).join("\n");
795 const body = header ? `${header}\n${qBlock}${aBlock}` : `${qBlock}${aBlock}`;
796 const withSig = body.length + `\n${signature}`.length <= MAX_TG_LEN ? `${body}\n${signature}` : body;
797
798 await MessageSender.sendNew(msg, withSig, "html", replyToId, false);
799 }
800
801 description = async (): Promise<string> => this.helpText();
802

Callers 1

DeepWikiPluginClass · 0.95

Calls 4

createTelegraphPageMethod · 0.95
buildQAHtmlFunction · 0.85
escapeHtmlFunction · 0.70
sendNewMethod · 0.45

Tested by

no test coverage detected