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

Method createTelegraphPage

ai/ai.ts:1218–1251  ·  view source on GitHub ↗
(
    markdown: string,
    titleSource?: string,
    token?: AbortToken,
  )

Source from the content-addressed store, hash-verified

1216 }
1217
1218 async createTelegraphPage(
1219 markdown: string,
1220 titleSource?: string,
1221 token?: AbortToken,
1222 ): Promise<TelegraphItem> {
1223 const configManager = await this.configManagerPromise;
1224 const config = configManager.getConfig();
1225
1226 const tgToken = await this.ensureTGToken(config, token);
1227 const rawTitle = (titleSource || "").replace(/\s+/g, " ").trim();
1228 const shortTitle =
1229 rawTitle.length > 24 ? `${rawTitle.slice(0, 24)}…` : rawTitle;
1230 const title = shortTitle || `Telegraph - ${new Date().toLocaleString()}`;
1231 const nodes = TelegraphFormatter.toNodes(markdown);
1232
1233 const response = await this.httpClient.request(
1234 {
1235 url: "https://api.telegra.ph/createPage",
1236 method: "POST",
1237 data: {
1238 access_token: tgToken,
1239 title,
1240 content: nodes,
1241 return_content: false,
1242 },
1243 },
1244 token,
1245 );
1246
1247 const url = response.data?.result?.url;
1248 if (!url) throw new Error(response.data?.error || "Telegraph 页面创建失败");
1249
1250 return { url, title, createdAt: new Date().toISOString() };
1251 }
1252
1253 async sendLongMessage(
1254 msg: Api.Message,

Callers 2

executeMethod · 0.45

Calls 3

ensureTGTokenMethod · 0.95
getConfigMethod · 0.45
requestMethod · 0.45

Tested by

no test coverage detected