Files
avatar/plugins/messaggi.py
T
lucianoandClaude Fable 5.1 ff79832c30 AvatarPy: assistente personale con volto 3D, voce, memoria e plugin
Riscrittura in Python dell'assistente Avatar con interfaccia HUD (derivata da Mark LIV, CC BY-NC 4.0, vedi NOTICE.md).
Tre motori (Claude API, server locale OpenAI-compatibile, Claude Code), voce Kokoro/macOS, Whisper MLX,
avatar 3D con sincronizzazione labiale, memoria per categorie, allegati con OCR, monitor con avvisi,
plugin per Calendario, Mail, Promemoria, Note, Musica, app, Mac, timer, meteo, contatti, Messaggi,
file, Comandi Rapidi, browser, Telegram, WhatsApp (archivio e tempo reale).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-23 16:21:39 +02:00

42 lines
1.7 KiB
Python

"""Messaggi (iMessage/SMS): invia un messaggio a un numero o a un contatto, con conferma."""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from avatar.macos import osa, confirm_or_param, CONFERMATO # noqa: E402
SEND = '''on run argv
tell application "Messages"
set svc to 1st account whose service type = iMessage
set b to participant (item 1 of argv) of svc
send (item 2 of argv) to b
end tell
return "ok"
end run'''
def invia(params: dict, ctx: dict) -> str:
a = str(params.get("a", "")).strip()
testo = str(params.get("testo", "")).strip()
if not a or not testo:
return "Errore: servono destinatario (numero con prefisso, es. +39…, o email iMessage) e testo."
if "@" not in a and not a.replace("+", "").replace(" ", "").isdigit():
return "Il destinatario deve essere un numero di telefono o un'email: cerca il contatto con contatti_cerca."
def do() -> str:
osa(SEND, a.replace(" ", ""), testo, timeout=30)
msg = f"Messaggio inviato a {a}."
if ctx.get("say"):
ctx["say"](msg)
return msg
return confirm_or_param(ctx, params, "messaggi_invia", "Inviare questo messaggio?", f"A: {a}\n{testo[:200]}", do)
TOOLS = [
{"name": "messaggi_invia", "description": "Invia un iMessage a un numero di telefono (con prefisso) o a un'email. Azione irreversibile con conferma sullo schermo; con [CONFIRMATION_PENDING] di' all'utente di confermare e non dire che è inviato. Per i nomi usa prima contatti_cerca.",
"parameters": {"type": "object", "properties": {"a": {"type": "string"}, "testo": {"type": "string"}, "confermato": CONFERMATO}, "required": ["a", "testo"]}, "run": invia},
]