First Push
This commit is contained in:
commit
cb46b5ce9f
BIN
__pycache__/main.cpython-314.pyc
Normal file
BIN
__pycache__/main.cpython-314.pyc
Normal file
Binary file not shown.
40
main.py
Normal file
40
main.py
Normal file
@ -0,0 +1,40 @@
|
||||
from fastapi import FastAPI, Request
|
||||
from mastodon import Mastodon
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# Configure from environment variables (recommended)
|
||||
MASTODON_API_BASE_URL = "https://mastodon.versi-tech.com"
|
||||
MASTODON_ACCESS_TOKEN = "xQUR-poG42E_PVqYs6-vZ9WmWngfcG_h9vzXPJVlqQY"
|
||||
|
||||
# Initialize Mastodon client
|
||||
mastodon = Mastodon(
|
||||
access_token=MASTODON_ACCESS_TOKEN,
|
||||
api_base_url=MASTODON_API_BASE_URL
|
||||
)
|
||||
|
||||
@app.post("/bookstack")
|
||||
async def receive_bookstack_webhook(request: Request):
|
||||
payload = await request.json()
|
||||
print("Received payload:", payload)
|
||||
|
||||
event = payload.get('event', 'BookStack update')
|
||||
url = payload.get('url', None)
|
||||
summary = payload.get('summary', '')
|
||||
actor = payload.get('initiator', {}).get('name', 'Someone')
|
||||
text = payload.get('text', 'Someone triggered on event on the Bookstack')
|
||||
|
||||
status = f"{text}.\n\n"
|
||||
if summary:
|
||||
status += f"Summary: {summary}\n"
|
||||
if url:
|
||||
status += f"{url}"
|
||||
|
||||
try:
|
||||
mastodon.status_post(status)
|
||||
pass
|
||||
except Exception as ex:
|
||||
print("Error posting to Mastodon:", ex)
|
||||
return {"success": False, "error": str(ex)}
|
||||
|
||||
return {"success": True}
|
||||
Loading…
x
Reference in New Issue
Block a user