(
msg: Api.Message,
replyToId: number | undefined,
headerLines: string[],
question: string,
answerMarkdown: string,
collapseSafe: boolean
)
| 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 |
no test coverage detected