bennitoti commited on
Commit
3311c28
·
verified ·
1 Parent(s): a3620fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -18,16 +18,14 @@ def send_telegram_message(arg1:str)-> str: #it's import to specify the return ty
18
  """A tool that send message to telegram chat
19
  Args:
20
  arg1: the message which will send to telegram chat
21
- arg2: the second argument
22
  """
23
 
24
- data = urllib.parse.urlencode({"chat_id": CHAT_ID, "text": arg1}).encode()
25
- req = urllib.request.Request(
26
- url=f"https://api.telegram.org/bot{TOKEN}/sendMessage",
27
- data=data)
28
 
29
- with urllib.request.urlopen(req, timeout=10) as resp:
30
- return (json.load(resp))
 
31
 
32
 
33
  @tool
 
18
  """A tool that send message to telegram chat
19
  Args:
20
  arg1: the message which will send to telegram chat
 
21
  """
22
 
23
+ url = f"https://api.telegram.org/bot{TOKEN}/sendMessage"
24
+ payload = {"chat_id": CHAT_ID, "text": arg1}
 
 
25
 
26
+ resp = requests.post(url, data=payload, timeout=10)
27
+ resp.raise_for_status() # ↳ кинет исключение, если Telegram вернул ошибку
28
+ return (resp.json())
29
 
30
 
31
  @tool