28 lines
861 B
Python
28 lines
861 B
Python
# pxy_bots/api/views.py
|
|
import json
|
|
from django.http import JsonResponse, HttpResponse
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
def health(request):
|
|
return JsonResponse({"ok": True, "service": "pxy_bots", "schema_ready": ["req.v1", "render.v1"]})
|
|
|
|
@csrf_exempt
|
|
def echo_render(request):
|
|
try:
|
|
data = json.loads(request.body.decode("utf-8") or "{}")
|
|
except Exception:
|
|
data = {}
|
|
|
|
text = (((data.get("input") or {}).get("text")) or "Hola 👋")
|
|
who = (((data.get("user") or {}).get("id")) or "user")
|
|
cmd = (((data.get("command") or {}).get("name")) or "none")
|
|
|
|
spec = {
|
|
"schema_version": "render.v1",
|
|
"messages": [
|
|
{"type": "text", "text": f"echo: user={who} cmd={cmd}"},
|
|
{"type": "text", "text": f"you said: {text}"},
|
|
],
|
|
}
|
|
return JsonResponse(spec)
|