Function buildFormDataFor

  • Build a FormData object based on the given a Method

    This allows you to have autocomplete and type-checking when using the client.request function, while still being able to upload files to the Telegram API.

    The rules work as follows:

    • string parameters will be appended to the FormData using their name.
    • File parameters will be appended with their name and filename (new File(...).name)
    • Other parameters will be JSON.stringifyed and appended with their name.

    Type Parameters

    Parameters

    Returns FormData

    Example

    const params = buildFormDataFor<"sendDocument">({
    chat_id: 123,
    document: new File(["hello"], "hello.txt")
    });

    const response = await client.request("sendDocument", params);