Update readme

This commit is contained in:
Jimmy 2021-07-06 22:30:51 +12:00
parent 98d66528b9
commit 0a6e12b04f
2 changed files with 54 additions and 0 deletions

View File

@ -1,2 +1,22 @@
# telegramapi
```pipenv sync```
```cp config.json.sample config.json```
Create a Telegram account if you don't have one
https://telegram.org/
Search users for ```BotFather```
Click start
Type ```/newbot``` and follow the prompts
Take the token under ```Use this token to access the HTTP API:``` and put it into config.json
Search users for ```userinfobot @userinfobot```
Put you id in config.json
Run
```pipenv run prod```

34
main.py Normal file
View File

@ -0,0 +1,34 @@
try:
import urequests as requests
except :
import requests
import json
with open("config.json", 'r') as f:
config = json.load(f)
offset = "0"
while True:
querry = "limit=1&offset={}&timeout=10".format(offset)
#long poll for response
try:
resp = requests.get(url='https://api.telegram.org/bot{}/{}?{}'.format(config["token"], "getUpdates" ,querry))
json = resp.json()
resp.close()
if json.get("result"):
#get latest message
offset = json.get("result")[0].get("update_id") + 1
text = json["result"][0]["message"]["text"]
print(text)
#send acknowledgement
querry = "chat_id={}&text={}".format(config["recipient"], text)
requests.get(url='https://api.telegram.org/bot{}/{}?{}'.format(config["token"], "sendMessage" ,querry))
except Exception as e:
print(e)
resp.close()