RequestData

final class telegram.request.RequestData(parameters=None)[source]

Bases: object

Instances of this class collect the data needed for one request to the Bot API, including all parameters and files to be sent along with the request.

Added in version 20.0.

Warning

How exactly instances of this are created should be considered an implementation detail and not part of PTBs public API. Users should exclusively rely on the documented attributes, properties and methods.

contains_files[source]

Whether this object contains files to be uploaded via multipart/form-data.

Type:

bool

property json_parameters[source]

Gives the parameters as mapping of parameter name to the respective JSON encoded value.

Tip

By default, this property uses the standard library’s json.dumps(). To use a custom library for JSON encoding, you can directly encode the keys of parameters - note that string valued keys should not be JSON encoded.

Returns:

Dict[str, str]

property json_payload[source]

The parameters as UTF-8 encoded JSON payload.

Tip

By default, this property uses the standard library’s json.dumps(). To use a custom library for JSON encoding, you can directly encode the keys of parameters - note that string valued keys should not be JSON encoded.

Returns:

bytes

property multipart_data[source]

Gives the files contained in this object as mapping of part name to encoded content.

Changed in version 21.5: Content may now be a file handle.

property parameters[source]

Gives the parameters as mapping of parameter name to the parameter value, which can be a single object of type int, float, str or bool or any (possibly nested) composition of lists, tuples and dictionaries, where each entry, key and value is of one of the mentioned types.

Returns:

Dict[str, Union[str, int, List[any], Dict[any, any]]]

parametrized_url(url, encode_kwargs=None)[source]

Shortcut for attaching the return value of url_encoded_parameters() to the url.

Parameters:
Returns:

str

url_encoded_parameters(encode_kwargs=None)[source]

Encodes the parameters with urllib.parse.urlencode().

Parameters:

encode_kwargs (Dict[str, any], optional) – Additional keyword arguments to pass along to urllib.parse.urlencode().

Returns:

str