MCPcopy Index your code
hub / github.com/CopilotKit/OpenTag / tgApi

Function tgApi

e2e/telegram-api.ts:76–98  ·  view source on GitHub ↗
(
  token: string,
  method: string,
  params: Record<string, unknown> = {},
)

Source from the content-addressed store, hash-verified

74const TELEGRAM_API = "https://api.telegram.org/bot";
75
76async function tgApi<T = Record<string, unknown>>(
77 token: string,
78 method: string,
79 params: Record<string, unknown> = {},
80): Promise<T> {
81 const url = `${TELEGRAM_API}${token}/${method}`;
82 const res = await fetch(url, {
83 method: "POST",
84 headers: { "Content-Type": "application/json" },
85 body: JSON.stringify(params),
86 });
87 const json = (await res.json()) as {
88 ok: boolean;
89 result?: T;
90 description?: string;
91 };
92 if (!json.ok) {
93 throw new Error(
94 `Telegram ${method} failed: ${json.description ?? JSON.stringify(json)}`,
95 );
96 }
97 return json.result as T;
98}
99
100// ── Types ─────────────────────────────────────────────────────────────────────
101

Callers 2

sendMessageAsSenderBotFunction · 0.85
getUpdatesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected