Spaces:
Sleeping
Sleeping
Webhooks works but sending message to Telegram is not allowed.
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
-
#import httpx
|
| 5 |
import os
|
| 6 |
|
| 7 |
|
|
@@ -10,26 +9,17 @@ HF_API_KEY = API_TOKEN
|
|
| 10 |
|
| 11 |
TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN')
|
| 12 |
BASE_URL = f"https://api.telegram.org/bot{TOKEN}"
|
| 13 |
-
#BASE_URL = f"https://149.154.167.220/bot{TOKEN}"
|
| 14 |
|
| 15 |
CUSTOM_PATH = "/gradio"
|
| 16 |
app = FastAPI()
|
| 17 |
|
| 18 |
-
#client = httpx.AsyncClient()
|
| 19 |
-
|
| 20 |
@app.get("/")
|
| 21 |
async def read_main():
|
| 22 |
-
|
| 23 |
-
text = "main"
|
| 24 |
-
msg = f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}"
|
| 25 |
-
print(msg)
|
| 26 |
-
response = requests.get(msg)
|
| 27 |
-
print(response.text)
|
| 28 |
-
return {"message": "This is your main app"}
|
| 29 |
|
| 30 |
@app.post("/")
|
| 31 |
async def read_main():
|
| 32 |
-
return {"message": "This is webhook"}
|
| 33 |
|
| 34 |
@app.post("/webhook")
|
| 35 |
async def webhook(req: Request):
|
|
@@ -38,12 +28,8 @@ async def webhook(req: Request):
|
|
| 38 |
text = data['message']['text']
|
| 39 |
|
| 40 |
msg = f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}"
|
| 41 |
-
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
#response = requests.get(msg, verify=False)
|
| 45 |
-
response = requests.get("https://git.io/JJkYN")
|
| 46 |
-
print(response.text)
|
| 47 |
|
| 48 |
return data
|
| 49 |
|
|
@@ -65,5 +51,3 @@ with gr.Blocks() as demo:
|
|
| 65 |
input.change(fn=flip_text, inputs=input, outputs=output)
|
| 66 |
|
| 67 |
gr.mount_gradio_app(app, demo, path=CUSTOM_PATH)
|
| 68 |
-
|
| 69 |
-
#uvicorn.run(app, port=8443)
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
|
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
|
|
|
|
| 9 |
|
| 10 |
TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN')
|
| 11 |
BASE_URL = f"https://api.telegram.org/bot{TOKEN}"
|
|
|
|
| 12 |
|
| 13 |
CUSTOM_PATH = "/gradio"
|
| 14 |
app = FastAPI()
|
| 15 |
|
|
|
|
|
|
|
| 16 |
@app.get("/")
|
| 17 |
async def read_main():
|
| 18 |
+
return {"message": "/webhook is for Telegram webhook and works. But respond message cannot be sent because Huggingface space does not support connection to https://api.telegram.org/."}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
@app.post("/")
|
| 21 |
async def read_main():
|
| 22 |
+
return {"message": "This is for dummy webhook"}
|
| 23 |
|
| 24 |
@app.post("/webhook")
|
| 25 |
async def webhook(req: Request):
|
|
|
|
| 28 |
text = data['message']['text']
|
| 29 |
|
| 30 |
msg = f"{BASE_URL}/sendMessage?chat_id={chat_id}&text={text}"
|
| 31 |
+
# Sending message to api.telegram.org fails for "No address associated with hostname"
|
| 32 |
+
#response = requests.get(msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
return data
|
| 35 |
|
|
|
|
| 51 |
input.change(fn=flip_text, inputs=input, outputs=output)
|
| 52 |
|
| 53 |
gr.mount_gradio_app(app, demo, path=CUSTOM_PATH)
|
|
|
|
|
|