Make a request to the Telegram API.
the method to call. This should be inferred from usage. See example below.
The method to call
The parameters to pass to the method. If you want to call a Method that accepts a file,
like sendDocument
, you can pass a File
object by sending a FormData object instead of a plain object.
See buildFormDataFor for a type-safe way to build a FormData object for a specific Telegram API method.
The result of the method call
const response = await client.request("sendMessage", { chat_id: 123, text: "Hello" });
if (response.ok) {
console.log(response.result.message_id);
}
const response = await client.request(
"sendDocument",
buildFormDataFor<"sendDocument">({
chat_id: 123,
document: new File(["hello"], "hello.txt")
})
);
if (response.ok) {
console.log(response.result.message_id);
}
A Telegram client that is bounded to a token/url.