MatteoScript commited on
Commit
863cde7
·
verified ·
1 Parent(s): 16e57e0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +43 -8
main.py CHANGED
@@ -4,9 +4,6 @@ from fastapi.middleware.cors import CORSMiddleware # Importa il middleware CORS
4
  import requests
5
  import time
6
 
7
- TOKEN = "6907051705:AAHZtYuiFTkQBNNw6m3cBVns8BPUw5mvxgU"
8
- BASE_URL = f"https://api.telegram.org/bot{TOKEN}"
9
-
10
  client = httpx.AsyncClient()
11
 
12
  app = FastAPI()
@@ -20,13 +17,51 @@ app.add_middleware(
20
 
21
  #https://api.telegram.org/bot6907051705:AAHZtYuiFTkQBNNw6m3cBVns8BPUw5mvxgU/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/
22
 
 
 
 
 
 
 
 
 
 
 
23
  @app.post("/")
24
- async def webhook(data: dict):
25
  print(data)
26
- print("INIZIO")
27
- time.sleep(20)
28
- print("FINE")
29
- await client.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  #await client.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")
31
  #requests.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")
32
  #requests.get("http://api.telegram.org/bot6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU/sendMessage?chat_id=1738997897&text=Come_Stai_Vez")
 
4
  import requests
5
  import time
6
 
 
 
 
7
  client = httpx.AsyncClient()
8
 
9
  app = FastAPI()
 
17
 
18
  #https://api.telegram.org/bot6907051705:AAHZtYuiFTkQBNNw6m3cBVns8BPUw5mvxgU/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/
19
 
20
+ @app.on_event("startup")
21
+ async def on_startup():
22
+ try:
23
+ response = await client.get(os.getenv('telegramUrlBot') + '/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/OLD')
24
+ response = await client.get(os.getenv('telegramUrlBot') + '/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/')
25
+ response.raise_for_status()
26
+ print("Webhook set successfully")
27
+ except httpx.HTTPError as e:
28
+ print(f"Error setting webhook: {e}")
29
+
30
  @app.post("/")
31
+ async def RispondiMessaggio(data: dict):
32
  print(data)
33
+ if data['message']['chat']['type'] == "group" or data['message']['chat']['type'] == "supergroup":
34
+ chat_id = data['message']['chat']['id']
35
+ else:
36
+ chat_id = data['message']['from']['id']
37
+ text = data['message']['text']
38
+ systemContent = "Tu sei un bot che esegue quello che deve eseguire"
39
+ systemStyle = "Utilizza molte EMOJI; Le parole IMPORTANTI mettile tra * (per esempio: *parola in grassetto*); Le CITAZIONI mettile tra _ (per esempio: _citazione in corsivo_). Usa l'ITALIANO!"
40
+ instruction = ""
41
+ temperature = 0.8
42
+ max_new_tokens = 100
43
+ numeroGenerazioni = 1
44
+ payload = {
45
+ 'input': text,
46
+ 'systemRole': systemContent,
47
+ 'systemStyle': systemStyle,
48
+ 'instruction': instruction,
49
+ 'temperature': temperature,
50
+ 'max_new_tokens': max_new_tokens,
51
+ 'asincrono': True,
52
+ 'NumeroGenerazioni': numeroGenerazioni,
53
+ 'StringaSplit': "&&",
54
+ 'telegramChatId': chat_id,
55
+ 'telegramUrlBot': os.getenv('telegramUrlBot'),
56
+ 'telegramUrlPost': os.getenv('telegramUrlPost')
57
+ }
58
+ headers = {
59
+ 'Content-Type': 'application/json',
60
+ 'Authorization': 'Bearer ' + os.getenv('tokenAPI')
61
+ }
62
+ response = requests.post(os.getenv('urlAPI'), json=payload, headers=headers)
63
+ print("Response Content:", response.text)
64
+ #await client.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")
65
  #await client.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")
66
  #requests.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")
67
  #requests.get("http://api.telegram.org/bot6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU/sendMessage?chat_id=1738997897&text=Come_Stai_Vez")