Skip to content

API For Python Script

Hirbod Behnam edited this page Dec 5, 2019 · 6 revisions

API usage of the python script

In the latest update of the python proxy installer script I added the API support. In this page we will learn how to use it and which commands can be executed as API.

Why API?

Good question. Imagine you are writing a MTProto bot or website. You need to continuously add and revoke secrets. And you do not want to write a wrapper for it. In this case you can use the API that this scripts provides for you.

API calls are just running this script with specific arguments.

How to use API

Return object

The script always return this result on any api call:

{
	"ok":boolen,
	"msg":object
}

Listing the users

With this method you can list all of the users and secrets.

How to use

bash MTProtoProxyInstall.sh list

Sample result

{
	"ok":true,
	"msg":{
		"User1":"secret of the User1",
		"User2" : "secret of the User2"
	}
}

Errors

Script will return this result if no secrets exist:

{
	"ok":false,
	"msg":"You have no secrets"
}

Getting the secret for a user

To get a secret run script with list <username> argument.

How to use

For example if you want to get the secret of a user named user1, run script like this:

bash MTProtoProxyInstall.sh list user1

Sample result

{  
	"ok":true,  
	"msg":"the base secret of user"  
}

Errors

The script will return an error if the username does not exists, or there are no secrets at all.

Add a user

How to use

bash MTProtoProxyInstall.sh 4 <USERNAME> <SECRET>

If you do not pass the <SECRET> then the script will generate a random secret for you.

Sample result

{  
	"ok":true,  
	"msg":{  
		"link":"tg://proxy?server=ip&port=Port&secret=TheSecretInFakeTLSFormat", 
		"secret":"the secret" 
	}  
}

Note that the tg link is always in fake tls format.

Errors

This method returns an error message if the secret you provided is not a valid secret.

Revoke a user

How to use

bash MTProtoProxyInstall.sh 5 <USERNAME>

Sample result

{  
	"ok":true,  
	"msg":"" 
}

Errors

This method returns error if the username does not exists.

Connection limits

How to use

bash MTProtoProxyInstall.sh 6 <USERNAME> <LIMIT>

Where the limit is a the number of allowed users.

Example of usage

You either gotta remove the limits of a user or set/change limits of a user.

If you want to remove the limit, just omit the limit parameter when running the script. For example if you want to remove the limits of the user1, run the script like this:

bash MTProtoProxyInstall.sh 6 user1

If you want to declare a limit, pass the number of allowed users to the script. For example if you want to limit the user2, that only 3 people can connect to it, run the script like this:

bash MTProtoProxyInstall.sh 6 user2 3

Sample result

{  
	"ok":true,  
	"msg":"" 
}

Expiry date

How to use

bash MTProtoProxyInstall.sh 7 <USERNAME> <DATE>

Date must be in format of dd/mm/yyyy

Example of usage

You can either remove the expiry date or set/change it.

To change the expiry date of the user u1 to 29/11/2020 run the script like this:

bash MTProtoProxyInstall.sh 7 u1 "29/11/2020"

To remove the expiry date of the user u2 run the script like this:

bash MTProtoProxyInstall.sh 7 u2

Sample result

{  
	"ok":true,  
	"msg":"" 
}