-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathset_webhook.py
33 lines (26 loc) · 1006 Bytes
/
set_webhook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
import argparse
import configparser
import os
import requests
config = configparser.ConfigParser()
configpath = os.path.dirname(os.path.realpath(__file__)) + '/config.ini'
config.read(configpath)
token = config.get('telegram', 'token')
parser = argparse.ArgumentParser()
parser.add_argument('action', default='set')
parser.add_argument('--url', default=config.get('global', 'url') + 'telegram')
parser.add_argument('--max_connections', default=config.get('telegram', 'max_connections'))
args = parser.parse_args()
print(args)
if args.action == 'set':
url = "https://api.telegram.org/bot{0}/setWebhook?url={1}&max_connections={2}".format(
token, args.url, args.max_connections)
elif args.action == 'delete':
url = "https://api.telegram.org/bot{0}/deleteWebhook".format(token)
elif args.action == 'get':
url = "https://api.telegram.org/bot{0}/getWebhookInfo".format(token)
else:
exit('unknown action.')
response = requests.get(url)
print(response.text)