The URL Type

Botfather has an inbuild Url type, that can be used to represent urls like The Url type provides methods to retrieve and modify individual parts of the url.
Representing urls as strings is fine, but if you want to access idividual parts of more complex urls using the Url type is recommended.

Table of contents

Url terminology

Complex urls consist of different parts, each has it’s own name. To use the url types methods you need to know how the parts are called. Consider those two example urls:

scheme: ftp
username: uname
password: pword
host: sharing .example .com
port: 2021
query: something=cool&color=blue
fragment: fragment
topleveldomain: .com
authority: uname:pword@sharing .example .com:2021

Url type instanciation

New Url objects can be created providing either nothing or the urls string representation:

  • var simple_url = new Url("");
  • var full_url = new Url("");
  • var invalid_url = new Url();

Url type methods


Returns true if the URL has no data; otherwise returns false.


Returns true if the URL is non-empty and valid; otherwise returns false.


Returns the scheme of the URL. If an empty string is returned, this means the scheme is undefined and the URL is then relative.

  • scheme (string): The urls new scheme (“https”, “http”).

Sets the scheme of the URL to scheme.


Returns the user name of the URL if it is defined; otherwise an empty string is returned.

  • username (string): The urls new username part.

Sets the URL’s user name to `.


Returns the password of the URL if it is defined; otherwise an empty string is returned.

  • password (string): The urls new password part.

Sets the URL’s password to password.


Returns the host of the URL if it is defined; otherwise an empty string is returned.

  • host (string): The urls new host.

Sets the host of the URL to host. The host is part of the authority.


Returns the port of the URL, or -1 if the port is unspecified.

  • port (number): The urls new port number.

Sets the port of the URL to port.


Returns the path of the URL.

  • path (string): The urls new path.

Sets the path of the URL to path. The path is the part of the URL that comes after the authority but before the query string.


Returns true if this URL contains a Query (i.e., if ? was seen on it).


Returns the query string of the URL if there’s a query string, or an empty result if not.

  • query (string): The urls query part.

Sets the query string of the URL to query.


Returns true if this URL contains a fragment (i.e., if # was seen on it).


Returns the fragment of the URL.

  • fragment (string): The urls new fragment.

Sets the fragment of the URL to fragment.


Returns the TLD (Top-Level Domain) of the URL, (e.g., .net).


Returns the authority of the URL if it is defined; otherwise an empty string is returned.

  • child_url (Url): Well, a potential child url of this url object.

Returns true if this URL is a parent of child_url. child_url is a child of this URL if the two URLs share the same scheme and authority, and this URL’s path is a parent of the path of child_url.

  • relative (string): A relative path to this Url objects url. (i.e. “../../image”)

Returns the result of the merge of this URL with relative. This URL is used as a base to convert relative to an absolute URL. If relative is not a relative URL, this function will return relative directly.


Returns the urls string representation.