Configuring CatraProto
CatraProto requires some user-provided configuration data such as API credentials to work.
API Settings
The ApiSettings constructor takes configuration data to be transmitted to Telegram regarding the app.
apiIdandapiHash, which can be retrieved by following these instructions.langPackis the language pack used by the client. Allowed values are: desktop, android, ios, macos and android_x.deviceModel,appVersionandsystemVersionare custom parameters shown to the user in its devices tab. They do not follow any standard.langCodeandsystemLangCodeshould follow the ISO 639-1 standard.
Example:
var apiSettings = new ApiSettings(45654, "63h4ofskqp045jsl204h", "Raspberry Pi", "1.0", "en", "tdesktop", "en", "1.0");
Session Settings
Session settings are used by CatraProto to know where to store both the session and data received by Telegram.
-
The
sessionSerializerparameter takes an instance of IAsyncSessionSerializer and uses it to serialize the session.CatraProto provides a FileSerializer. It only requires a parameter:
filePathwhere the session will be saved. You can also implement your own IAsyncSessionSerializer.
-
The
databaseSettingsparameter takes an instance of DatabaseSettings.DatabaseSettings’ constructor requires two parameters:
pathwhich specifies a path where the persistent cache will be created.peerCacheSizewhich is the maximum number of elements for the in-memory peer cache.
-
The
sessionNameparameters takes a string specifying the name of the session which will be used to write logs.
To not create confusion, it is recommended to give the session a .catra extension and a .db extension to the database.
Example:
var sessionSettings = new SessionSettings(new FileSerializer("data/accountSession.catra"), new DatabaseSettings($"data/accountData.db", 50), "Private account");
Connection Settings
Connection settings are used to specify the default MTProto server, PFS key duration and other connection settings.
- The
defaultDatacenterparameter takes an instance of ConnectionInfo.
ConnectionInfo takes the following parameters:IPAddresstakes an instance of IPAddress. It is used to specify the IP of the default datacenter. You can get information about your default datacenter by following these instructions.portspecifies the port to be used in order to connect to the datacenter. You can find it in your app’s configuration. You can find it right after the “:” in the IP address.dcIdused to specify which DC we are connecting to. You can find what DC has been assigned to your app just under the IP address. If this value is incorrect the library won’t be able to perform many operations such as logging in correctly.testspecifies whether the DC we are connecting to is a test DC. It is very important to make sure this parameter is correct otherwise CatraProto won’t be able to communicate with the API.
- The
pfsKeyDurationparameter specifies in seconds how long the PFS Key should last. When expired, the library will automatically generated a new one. This does not mean you will lose access to your session. One usually doesn’t need to change this parameter. - The
connectionTimeoutparameter specifies in seconds how much time must elapse before reconnecting if the server does not reply. - The
connectionRetryparameter specifies in seconds how much the library must wait before trying to connect again after a failed attempt. - The
ipv6Allowedparameter specifies whether IPv6 is allowed or not. - The
ipv6Onlyparameter specifies whether only IPv6 must be used or not. This works only for connections that are not the default connection as Telegram only provides IPv4s.
Example:
var connectionInfo = new ConnectionInfo(IPAddress.Parse("149.154.167.50"), 443, 2, false);
var connectionSettings = new ConnectionSettings(connectionInfo, 86400, 25, 15, false, false);
Updates settings
This is an optional parameter, you can skip this part if you’re not interested.
Currently, the only property exposed by the UpdatesSettings class is queueUpdates and when false it disables this behaviour.
Example:
var updatesSettings = new UpdatesSettings(false);
Combining every setting together
After having specified our configuration data and behaviour preferences we must put everything together.
To do this, we use the ClientSettings class. It simply takes the settings we have just created as parameters in the following order: SessionSettings, ApiSettings, ConnectionSettings. Optionally, UpdatesSettings are also accepted as last parameter.
Example:
var clientSettings = new ClientSettings(sessionSettings, apiSettings, connectionSettings);