37 lines
1.2 KiB
Python
37 lines
1.2 KiB
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"]})
|
||
|
||
# pxy_bots/api/views.py
|
||
import json
|
||
from django.http import JsonResponse
|
||
|
||
def echo_render(request):
|
||
"""
|
||
Accepts req.v1 and returns a simple render_spec so you can validate the router.
|
||
"""
|
||
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}"},
|
||
],
|
||
"buttons": [
|
||
{"label": "Abrir Dashboard", "kind": "open_url", "url": "https://app.polisplexity.tech/"},
|
||
{"label": "Re-ejecutar 10’", "kind": "callback_api", "action": "rerun", "params": {"minutes": 10}},
|
||
],
|
||
}
|
||
return JsonResponse(spec) |