This class sets webhooks and listens to a given url and port. :param listen: IP address to listen to. Defaults to 0.0.0.0 :param port: A port which will be used to listen to webhooks. :param url_path: Path to the webhook. Defaults to /token :param certificat
(self,
listen: Optional[str]="127.0.0.1",
port: Optional[int]=443,
url_path: Optional[str]=None,
certificate: Optional[str]=None,
certificate_key: Optional[str]=None,
webhook_url: Optional[str]=None,
max_connections: Optional[int]=None,
allowed_updates: Optional[List]=None,
ip_address: Optional[str]=None,
drop_pending_updates: Optional[bool] = None,
timeout: Optional[int]=None,
secret_token: Optional[str]=None,
secret_token_length: Optional[int]=20,
debug: Optional[bool]=False)
| 2954 | |
| 2955 | |
| 2956 | async def run_webhooks(self, |
| 2957 | listen: Optional[str]="127.0.0.1", |
| 2958 | port: Optional[int]=443, |
| 2959 | url_path: Optional[str]=None, |
| 2960 | certificate: Optional[str]=None, |
| 2961 | certificate_key: Optional[str]=None, |
| 2962 | webhook_url: Optional[str]=None, |
| 2963 | max_connections: Optional[int]=None, |
| 2964 | allowed_updates: Optional[List]=None, |
| 2965 | ip_address: Optional[str]=None, |
| 2966 | drop_pending_updates: Optional[bool] = None, |
| 2967 | timeout: Optional[int]=None, |
| 2968 | secret_token: Optional[str]=None, |
| 2969 | secret_token_length: Optional[int]=20, |
| 2970 | debug: Optional[bool]=False): |
| 2971 | """ |
| 2972 | This class sets webhooks and listens to a given url and port. |
| 2973 | |
| 2974 | :param listen: IP address to listen to. Defaults to 0.0.0.0 |
| 2975 | :param port: A port which will be used to listen to webhooks. |
| 2976 | :param url_path: Path to the webhook. Defaults to /token |
| 2977 | :param certificate: Path to the certificate file. |
| 2978 | :param certificate_key: Path to the certificate key file. |
| 2979 | :param webhook_url: Webhook URL. |
| 2980 | :param max_connections: Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput. |
| 2981 | :param allowed_updates: A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used. |
| 2982 | :param ip_address: The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS |
| 2983 | :param drop_pending_updates: Pass True to drop all pending updates |
| 2984 | :param timeout: Integer. Request connection timeout |
| 2985 | :param secret_token: Secret token to be used to verify the webhook request. |
| 2986 | :param secret_token_length: Length of a secret token, defaults to 20 |
| 2987 | :param debug: Debug mode, defaults to False |
| 2988 | :return: |
| 2989 | """ |
| 2990 | |
| 2991 | # generate secret token if not set |
| 2992 | if not secret_token: |
| 2993 | secret_token = ''.join(random.choices(string.ascii_uppercase + string.digits, k=secret_token_length)) |
| 2994 | |
| 2995 | if not url_path: |
| 2996 | url_path = self.token + '/' |
| 2997 | if url_path[-1] != '/': url_path += '/' |
| 2998 | |
| 2999 | protocol = "https" if certificate else "http" |
| 3000 | if not webhook_url: |
| 3001 | webhook_url = "{}://{}:{}/{}".format(protocol, listen, port, url_path) |
| 3002 | |
| 3003 | if certificate and certificate_key: |
| 3004 | ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) |
| 3005 | ssl_ctx.load_cert_chain(certificate, certificate_key) |
| 3006 | |
| 3007 | # open certificate if it exists |
| 3008 | cert_file = open(certificate, 'rb') if certificate else None |
| 3009 | await self.set_webhook( |
| 3010 | url=webhook_url, |
| 3011 | certificate=cert_file, |
| 3012 | max_connections=max_connections, |
| 3013 | allowed_updates=allowed_updates, |
nothing calls this directly
no test coverage detected