Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,11 +1,6 @@
|
|
1 |
-
import httpx
|
2 |
from fastapi import FastAPI, Request
|
3 |
from fastapi.middleware.cors import CORSMiddleware
|
4 |
import requests
|
5 |
-
import time
|
6 |
-
import os
|
7 |
-
|
8 |
-
client = httpx.AsyncClient()
|
9 |
|
10 |
app = FastAPI()
|
11 |
app.add_middleware(
|
@@ -16,61 +11,16 @@ app.add_middleware(
|
|
16 |
allow_headers=["*"],
|
17 |
)
|
18 |
|
19 |
-
#https://api.telegram.org/bot6907051705:AAHZtYuiFTkQBNNw6m3cBVns8BPUw5mvxgU/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/
|
20 |
-
|
21 |
-
@app.on_event("startup")
|
22 |
-
def on_startup():
|
23 |
-
print('start up')
|
24 |
-
response = client.get(os.getenv('telegramUrlBot') + '/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/OLD')
|
25 |
-
response = client.get(os.getenv('telegramUrlBot') + '/setWebhook?url=https://matteoscript-TelegramBotSimple.hf.space/')
|
26 |
-
print('webhook settato')
|
27 |
-
|
28 |
@app.post("/")
|
29 |
-
async def
|
30 |
print(data)
|
31 |
-
if data['message']['chat']['type'] == "group" or data['message']['chat']['type'] == "supergroup":
|
32 |
-
chat_id = data['message']['chat']['id']
|
33 |
-
else:
|
34 |
-
chat_id = data['message']['from']['id']
|
35 |
-
text = data['message']['text']
|
36 |
-
systemContent = "Tu sei un bot che esegue quello che deve eseguire"
|
37 |
-
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!"
|
38 |
-
instruction = ""
|
39 |
-
temperature = 0.8
|
40 |
-
max_new_tokens = 100
|
41 |
-
numeroGenerazioni = 1
|
42 |
-
payload = {
|
43 |
-
'input': text,
|
44 |
-
'systemRole': systemContent,
|
45 |
-
'systemStyle': systemStyle,
|
46 |
-
'instruction': instruction,
|
47 |
-
'temperature': temperature,
|
48 |
-
'max_new_tokens': max_new_tokens,
|
49 |
-
'asincrono': True,
|
50 |
-
'NumeroGenerazioni': numeroGenerazioni,
|
51 |
-
'StringaSplit': "&&",
|
52 |
-
'telegramChatId': chat_id,
|
53 |
-
'telegramUrlBot': os.getenv('telegramUrlBot'),
|
54 |
-
'telegramUrlPost': os.getenv('telegramUrlPost')
|
55 |
-
}
|
56 |
headers = {
|
57 |
'Content-Type': 'application/json',
|
58 |
'Authorization': 'Bearer ' + os.getenv('tokenAPI')
|
59 |
}
|
60 |
-
response = requests.post(os.getenv('urlAPI'), json=
|
61 |
print("Response Content:", response.text)
|
62 |
-
#await client.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")
|
63 |
-
#await client.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")
|
64 |
-
#requests.get("https://script.google.com/macros/s/AKfycbxa8wXSr1ynlEONQ99s3WF5a9OTHSYWH7NkKsYI9Z2SeWRoU5c0-WzjY5Gn2iDhSgj5/exec")
|
65 |
-
#requests.get("http://api.telegram.org/bot6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU/sendMessage?chat_id=1738997897&text=Come_Stai_Vez")
|
66 |
-
#chat_id = data['message']['chat']['id']
|
67 |
-
#text = data['message']['text']
|
68 |
-
#resp = requests.get("https://api.telegram.org/bot6770617809:AAEhytQUOl3uZOFINVE7-o0KkIoAz8perGU/sendMessage?chat_id=1738997897&text=Come_Stai_Vez")
|
69 |
-
#resp = requests.get(f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}")
|
70 |
-
#print(resp)
|
71 |
-
#await client.get(f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}")
|
72 |
-
return {"response": "ok"}
|
73 |
|
74 |
@app.get("/")
|
75 |
def read_general():
|
76 |
-
return {"response": "Started"}
|
|
|
|
|
1 |
from fastapi import FastAPI, Request
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
import requests
|
|
|
|
|
|
|
|
|
4 |
|
5 |
app = FastAPI()
|
6 |
app.add_middleware(
|
|
|
11 |
allow_headers=["*"],
|
12 |
)
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
@app.post("/")
|
15 |
+
async def webhook(data: dict):
|
16 |
print(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
headers = {
|
18 |
'Content-Type': 'application/json',
|
19 |
'Authorization': 'Bearer ' + os.getenv('tokenAPI')
|
20 |
}
|
21 |
+
response = requests.post(os.getenv('urlAPI'), json=data, headers=headers)
|
22 |
print("Response Content:", response.text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
@app.get("/")
|
25 |
def read_general():
|
26 |
+
return {"response": "Webhook Started"}
|