{"openapi":"3.1.0","paths":{"/api/whatsapp/messages":{"get":{"description":"I 100 messaggi più recenti del workspace, in entrambe le direzioni, dal più nuovo.","operationId":"WhatsappMessagesController_list","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/MessageListItem"}}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"413":{"description":"JSON oltre 100 KiB o file oltre il limite (10 MiB; JPEG/PNG 5 MB).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Ultimi messaggi","tags":["Messaggi"]}},"/api/whatsapp/messages/template":{"post":{"description":"Invio immediato di un template approvato. Unico tipo ammesso fuori dalla finestra di 24 ore.","operationId":"WhatsappMessagesController_sendTemplate","parameters":[{"name":"Prefer","in":"header","description":"`respond-async` equivale a `mode: \"async\"`: risposta `202` con il messaggio `queued`, esito con l'evento `message.status`. La risposta riporta `Preference-Applied: respond-async`. Il campo `mode` del corpo, se presente, prevale.","required":false,"schema":{"type":"string","example":"respond-async"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendTemplateMessageDto"}}}},"responses":{"201":{"description":"Messaggio inviato a Meta (`sent`), o quello già creato con la stessa chiave.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"202":{"description":"Solo con `mode: \"async\"` o `Prefer: respond-async`: messaggio accettato in coda (`queued`), o quello già creato con la stessa chiave nel suo stato attuale. Gli errori di Meta non arrivano qui ma con l'evento `message.status` (`failed`, codice in `failureCode`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"402":{"description":"Il workspace ha finito i crediti messaggi (`WHATSAPP_CREDITS_EXHAUSTED`): nessun messaggio creato, Meta non contattata. Riprovare dopo che lo studio ha acquistato un pacchetto, anche con la stessa chiave.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Account o contatto inesistente nel workspace (`WHATSAPP_ACCOUNT_NOT_FOUND`, `WHATSAPP_CONTACT_NOT_FOUND`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"409":{"description":"Chiave di idempotenza già usata con un altro corpo (`WHATSAPP_IDEMPOTENCY_CONFLICT`), contatto che ha revocato il consenso (`WHATSAPP_CONTACT_OPTED_OUT`), template marketing a un contatto che ha chiesto a WhatsApp di non riceverne da questo numero (`WHATSAPP_CONTACT_MARKETING_STOPPED`), categoria disattivata dallo studio (`WHATSAPP_CONTACT_UTILITY_DISABLED`, `WHATSAPP_CONTACT_MARKETING_DISABLED`), template non approvato (`WHATSAPP_TEMPLATE_NOT_APPROVED`) o numero da riautorizzare (`WHATSAPP_AUTHORIZATION_REQUIRED`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"410":{"description":"Messaggio eliminato dalla retention (`WHATSAPP_MESSAGE_EXPIRED`): nessun nuovo invio.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"JSON oltre 100 KiB o file oltre il limite (10 MiB; JPEG/PNG 5 MB).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"422":{"description":"Meta ha rifiutato il messaggio in modo definitivo (`WHATSAPP_MESSAGE_REJECTED`, codice Meta in `providerCode`, es. `131037` nome visualizzato del numero non approvato). Il messaggio resta registrato `failed`; ripetere non serve finché la causa non è risolta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}},"503":{"description":"Meta o la coda non raggiungibili, o errore temporaneo di Meta (`WHATSAPP_MESSAGING_UNAVAILABLE`, `WHATSAPP_SCHEDULER_UNAVAILABLE`). Il messaggio resta registrato `failed`: la stessa chiave lo restituisce senza reinviarlo. Un nuovo tentativo richiede una nuova chiave; se la causa era un timeout verso Meta, il primo messaggio può essere arrivato comunque, quindi il nuovo invio può produrre un doppione.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Invia un template","tags":["Messaggi"]}},"/api/whatsapp/messages/text":{"post":{"description":"Testo libero, ammesso solo entro 24 ore dall'ultimo messaggio ricevuto dal contatto.","operationId":"WhatsappMessagesController_sendText","parameters":[{"name":"Prefer","in":"header","description":"`respond-async` equivale a `mode: \"async\"`: risposta `202` con il messaggio `queued`, esito con l'evento `message.status`. La risposta riporta `Preference-Applied: respond-async`. Il campo `mode` del corpo, se presente, prevale.","required":false,"schema":{"type":"string","example":"respond-async"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SendTextMessageDto"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"202":{"description":"Solo con `mode: \"async\"` o `Prefer: respond-async`: messaggio accettato in coda (`queued`), o quello già creato con la stessa chiave nel suo stato attuale. Gli errori di Meta non arrivano qui ma con l'evento `message.status` (`failed`, codice in `failureCode`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"402":{"description":"Il workspace ha finito i crediti messaggi (`WHATSAPP_CREDITS_EXHAUSTED`): nessun messaggio creato, Meta non contattata. Riprovare dopo che lo studio ha acquistato un pacchetto, anche con la stessa chiave.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Account o contatto inesistente nel workspace (`WHATSAPP_ACCOUNT_NOT_FOUND`, `WHATSAPP_CONTACT_NOT_FOUND`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"409":{"description":"Chiave di idempotenza già usata con un altro corpo (`WHATSAPP_IDEMPOTENCY_CONFLICT`), contatto che ha revocato il consenso (`WHATSAPP_CONTACT_OPTED_OUT`), template marketing a un contatto che ha chiesto a WhatsApp di non riceverne da questo numero (`WHATSAPP_CONTACT_MARKETING_STOPPED`), categoria disattivata dallo studio (`WHATSAPP_CONTACT_UTILITY_DISABLED`, `WHATSAPP_CONTACT_MARKETING_DISABLED`), template non approvato (`WHATSAPP_TEMPLATE_NOT_APPROVED`) o numero da riautorizzare (`WHATSAPP_AUTHORIZATION_REQUIRED`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"410":{"description":"Messaggio eliminato dalla retention (`WHATSAPP_MESSAGE_EXPIRED`): nessun nuovo invio.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"JSON oltre 100 KiB o file oltre il limite (10 MiB; JPEG/PNG 5 MB).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"422":{"description":"Finestra di 24 ore chiusa: usare un template (`WHATSAPP_OUTSIDE_ALLOWED_WINDOW`). Meta ha rifiutato il messaggio in modo definitivo (`WHATSAPP_MESSAGE_REJECTED`, codice Meta in `providerCode`, es. `131037` nome visualizzato del numero non approvato). Il messaggio resta registrato `failed`; ripetere non serve finché la causa non è risolta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}},"503":{"description":"Meta o la coda non raggiungibili, o errore temporaneo di Meta (`WHATSAPP_MESSAGING_UNAVAILABLE`, `WHATSAPP_SCHEDULER_UNAVAILABLE`). Il messaggio resta registrato `failed`: la stessa chiave lo restituisce senza reinviarlo. Un nuovo tentativo richiede una nuova chiave; se la causa era un timeout verso Meta, il primo messaggio può essere arrivato comunque, quindi il nuovo invio può produrre un doppione.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Invia un testo","tags":["Messaggi"]}},"/api/whatsapp/messages/media":{"post":{"description":"File multipart oppure JSON con mediaId o URL HTTPS; una sola sorgente. Cache file di un’ora per studio e mittente. Solo entro la finestra di 24 ore.","operationId":"WhatsappMessagesController_sendMedia","parameters":[{"name":"Prefer","in":"header","description":"`respond-async` equivale a `mode: \"async\"`: risposta `202` con il messaggio `queued`, esito con l'evento `message.status`. La risposta riporta `Preference-Applied: respond-async`. Il campo `mode` del corpo, se presente, prevale.","required":false,"schema":{"type":"string","example":"respond-async"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"allOf":[{"$ref":"#/components/schemas/SendMediaMessageDto"},{"oneOf":[{"required":["url"],"not":{"anyOf":[{"required":["mediaId"]}]}},{"required":["mediaId"],"not":{"anyOf":[{"required":["url"]}]}}]}]}},"multipart/form-data":{"schema":{"allOf":[{"$ref":"#/components/schemas/SendMediaMessageDto"},{"type":"object","properties":{"file":{"type":"string","format":"binary"}},"oneOf":[{"required":["file"],"not":{"anyOf":[{"required":["mediaId"]},{"required":["url"]}]}},{"required":["mediaId"],"not":{"anyOf":[{"required":["file"]},{"required":["url"]}]}},{"required":["url"],"not":{"anyOf":[{"required":["file"]},{"required":["mediaId"]}]}}]}]}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"202":{"description":"Solo con `mode: \"async\"` o `Prefer: respond-async`: messaggio accettato in coda (`queued`), o quello già creato con la stessa chiave nel suo stato attuale. Gli errori di Meta non arrivano qui ma con l'evento `message.status` (`failed`, codice in `failureCode`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"402":{"description":"Il workspace ha finito i crediti messaggi (`WHATSAPP_CREDITS_EXHAUSTED`): nessun messaggio creato, Meta non contattata. Riprovare dopo che lo studio ha acquistato un pacchetto, anche con la stessa chiave.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Account o contatto inesistente nel workspace (`WHATSAPP_ACCOUNT_NOT_FOUND`, `WHATSAPP_CONTACT_NOT_FOUND`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"409":{"description":"Chiave di idempotenza già usata con un altro corpo (`WHATSAPP_IDEMPOTENCY_CONFLICT`), contatto che ha revocato il consenso (`WHATSAPP_CONTACT_OPTED_OUT`), template marketing a un contatto che ha chiesto a WhatsApp di non riceverne da questo numero (`WHATSAPP_CONTACT_MARKETING_STOPPED`), categoria disattivata dallo studio (`WHATSAPP_CONTACT_UTILITY_DISABLED`, `WHATSAPP_CONTACT_MARKETING_DISABLED`), template non approvato (`WHATSAPP_TEMPLATE_NOT_APPROVED`) o numero da riautorizzare (`WHATSAPP_AUTHORIZATION_REQUIRED`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"410":{"description":"Messaggio eliminato dalla retention (`WHATSAPP_MESSAGE_EXPIRED`): nessun nuovo invio.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"JSON oltre 100 KiB o file oltre il limite (10 MiB; JPEG/PNG 5 MB).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"415":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"422":{"description":"Finestra di 24 ore chiusa (`WHATSAPP_OUTSIDE_ALLOWED_WINDOW`). Meta ha rifiutato il messaggio in modo definitivo (`WHATSAPP_MESSAGE_REJECTED`, codice Meta in `providerCode`, es. `131037` nome visualizzato del numero non approvato). Il messaggio resta registrato `failed`; ripetere non serve finché la causa non è risolta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}},"503":{"description":"Meta o la coda non raggiungibili, o errore temporaneo di Meta (`WHATSAPP_MESSAGING_UNAVAILABLE`, `WHATSAPP_SCHEDULER_UNAVAILABLE`). Il messaggio resta registrato `failed`: la stessa chiave lo restituisce senza reinviarlo. Un nuovo tentativo richiede una nuova chiave; se la causa era un timeout verso Meta, il primo messaggio può essere arrivato comunque, quindi il nuovo invio può produrre un doppione.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Invia un file","tags":["Messaggi"]}},"/api/whatsapp/messages/schedule":{"post":{"description":"Invio di un template approvato a una data futura. Il messaggio resta `scheduled` finché non parte; si annulla con `/cancel`.","operationId":"WhatsappMessagesController_schedule","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ScheduleTemplateMessageDto"}}}},"responses":{"201":{"description":"Messaggio in stato `scheduled`, o quello già esistente nel suo stato corrente per un replay idempotente.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"402":{"description":"Il workspace ha finito i crediti messaggi (`WHATSAPP_CREDITS_EXHAUSTED`): nessun messaggio creato, Meta non contattata. Riprovare dopo che lo studio ha acquistato un pacchetto, anche con la stessa chiave.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Account o contatto inesistente nel workspace (`WHATSAPP_ACCOUNT_NOT_FOUND`, `WHATSAPP_CONTACT_NOT_FOUND`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"409":{"description":"Chiave di idempotenza già usata con un altro corpo (`WHATSAPP_IDEMPOTENCY_CONFLICT`), contatto che ha revocato il consenso (`WHATSAPP_CONTACT_OPTED_OUT`), template marketing a un contatto che ha chiesto a WhatsApp di non riceverne da questo numero (`WHATSAPP_CONTACT_MARKETING_STOPPED`), categoria disattivata dallo studio (`WHATSAPP_CONTACT_UTILITY_DISABLED`, `WHATSAPP_CONTACT_MARKETING_DISABLED`), template non approvato (`WHATSAPP_TEMPLATE_NOT_APPROVED`) o numero da riautorizzare (`WHATSAPP_AUTHORIZATION_REQUIRED`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"410":{"description":"Messaggio eliminato dalla retention (`WHATSAPP_MESSAGE_EXPIRED`): nessun nuovo invio.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"JSON oltre 100 KiB o file oltre il limite (10 MiB; JPEG/PNG 5 MB).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}},"503":{"description":"Meta o la coda non raggiungibili, o errore temporaneo di Meta (`WHATSAPP_MESSAGING_UNAVAILABLE`, `WHATSAPP_SCHEDULER_UNAVAILABLE`). Il messaggio resta registrato `failed`: la stessa chiave lo restituisce senza reinviarlo. Un nuovo tentativo richiede una nuova chiave; se la causa era un timeout verso Meta, il primo messaggio può essere arrivato comunque, quindi il nuovo invio può produrre un doppione.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Programma un template","tags":["Messaggi"]}},"/api/whatsapp/messages/{id}":{"get":{"description":"Stato corrente di un messaggio del workspace.","operationId":"WhatsappMessagesController_get","parameters":[{"name":"id","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"404":{"description":"`WHATSAPP_MESSAGE_NOT_FOUND` (anche per messaggi di altri workspace).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"JSON oltre 100 KiB o file oltre il limite (10 MiB; JPEG/PNG 5 MB).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Leggi un messaggio","tags":["Messaggi"]}},"/api/whatsapp/messages/{id}/cancel":{"post":{"description":"Solo i messaggi ancora `scheduled`. Se non è più `scheduled` risponde 409: leggere lo stato corrente, l'annullamento non è riuscito.","operationId":"WhatsappMessagesController_cancel","parameters":[{"name":"id","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"201":{"description":"Messaggio in stato `cancelled`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"404":{"description":"`WHATSAPP_MESSAGE_NOT_FOUND`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"409":{"description":"Messaggio non più annullabile (`WHATSAPP_MESSAGE_ALREADY_PROCESSED`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"JSON oltre 100 KiB o file oltre il limite (10 MiB; JPEG/PNG 5 MB).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Annulla un programmato","tags":["Messaggi"]}},"/api/whatsapp/templates":{"get":{"description":"Tutti i template del workspace, in ordine di nome. Si inviano solo quelli `approved`.","operationId":"WhatsappTemplatesController_list","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/TemplateResponse"}}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Template","tags":["Template"]}},"/api/whatsapp/templates/sync":{"post":{"operationId":"WhatsappTemplatesController_syncByPhone","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SyncByPhoneDto"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplateSyncResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"404":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Sincronizza i template dal numero dello studio","tags":["Template"]}},"/api/whatsapp/templates/sync/{accountId}":{"post":{"description":"Rilegge da Meta i template di un account e aggiorna lo stato di revisione. Una risposta Meta vuota non marca cancellazioni. In sandbox conta i template locali senza chiamare Meta.","operationId":"WhatsappTemplatesController_sync","parameters":[{"name":"accountId","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"201":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TemplateSyncResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"404":{"description":"`WHATSAPP_ACCOUNT_NOT_FOUND`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Sincronizza da Meta","tags":["Template"]}},"/api/whatsapp/accounts":{"get":{"description":"Account WhatsApp del workspace, dal più recente. `phoneNumber` è il numero E.164 da usare come `from`; gli ID restano compatibili.","operationId":"WhatsappAccountsController_list","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AccountResponse"}}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Numeri collegati","tags":["Account"]}},"/api/whatsapp/accounts/signup-config":{"get":{"description":"Identificativi pubblici dell'app Meta per avviare Embedded Signup dal software partner.","operationId":"WhatsappAccountsController_signupConfig","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SignupConfigResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Configurazione Embedded Signup","tags":["Account"]}},"/api/whatsapp/accounts/coexistence":{"post":{"description":"Completa Embedded Signup con il codice ricevuto da Meta. Il numero deve essere attivo sull'app WhatsApp Business. Non sincronizza i template: chiamare poi `/templates/sync/{accountId}`. Bloccato in sandbox.","operationId":"WhatsappAccountsController_connectCoexistence","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ConnectCoexistenceDto"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AccountResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"409":{"description":"`WHATSAPP_NOT_AVAILABLE_IN_SANDBOX`: non si possono collegare numeri reali a un workspace di prova.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Collega un numero (Coexistence)","tags":["Account"]}},"/api/whatsapp/contacts":{"get":{"description":"I 100 contatti creati più di recente.","operationId":"WhatsappContactsController_list","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/ContactResponse"}}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Ultimi contatti","tags":["Contatti"]},"post":{"description":"Idempotente sul numero: se il numero esiste già nel workspace restituisce il contatto esistente senza modificarlo.","operationId":"WhatsappContactsController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateContactDto"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ContactResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Crea o ritrova un contatto","tags":["Contatti"]}},"/api/whatsapp/sandbox/inbound":{"post":{"description":"Solo nei workspace di prova. Il messaggio viene elaborato come uno vero, in modo asincrono: apre la finestra di 24 ore e genera l'evento `message.received` verso i webhook del workspace.","operationId":"WhatsappSandboxController_inbound","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SimulateInboundDto"}}}},"responses":{"202":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SandboxInboundResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"404":{"description":"Workspace non di prova, o numero di un altro workspace (`WHATSAPP_ACCOUNT_NOT_FOUND`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Simula la risposta di un paziente","tags":["Ambiente di prova"]}},"/api/whatsapp/webhooks":{"get":{"operationId":"WhatsappWebhooksController_list","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/WebhookEndpointResponse"}}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Elenca i webhook attivi del workspace","tags":["Webhook in uscita"]},"post":{"operationId":"WhatsappWebhooksController_create","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateWebhookDto"}}}},"responses":{"200":{"description":"URL già attivo nel workspace. Restituisce l’endpoint esistente senza segreto.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookEndpointResponse"}}}},"201":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreatedWebhookResponse"}}}},"400":{"description":"Campi non validi o destinazione non ammessa (WEBHOOK_URL_NOT_ALLOWED).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"409":{"description":"Limite di cinque endpoint attivi (WEBHOOK_LIMIT_REACHED).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Registra un webhook tramite URL","tags":["Webhook in uscita"]}},"/api/whatsapp/webhooks/{id}":{"delete":{"operationId":"WhatsappWebhooksController_disable","parameters":[{"name":"id","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"204":{"description":""},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"404":{"description":"Webhook attivo non trovato nel workspace (WEBHOOK_NOT_FOUND).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Rimuove il webhook e annulla le consegne in attesa","tags":["Webhook in uscita"]}},"/api/whatsapp/webhooks/{id}/rotate-secret":{"post":{"description":"Per 24 ore le consegne includono anche la firma del segreto precedente.","operationId":"WhatsappWebhooksController_rotate","parameters":[{"name":"id","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/RotatedWebhookSecretResponse"}}}},"400":{"description":"Campi o parametri non validi (elenco in `message`), oppure richiesta rifiutata dal servizio (`WHATSAPP_INVALID_REQUEST`, es. `scheduledAt` nel passato o variabili del template non valide).","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ValidationErrorResponse"},{"$ref":"#/components/schemas/ErrorResponse"}]}}}},"401":{"description":"Chiave mancante, sconosciuta, revocata o scaduta.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthorizedResponse"}}}},"404":{"description":"Webhook attivo non trovato nel workspace (WEBHOOK_NOT_FOUND).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"413":{"description":"Corpo oltre 100 KiB.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PayloadTooLargeResponse"}}}},"429":{"description":"Quota al minuto esaurita (per chiave o per workspace). Attendere `Retry-After` secondi e ripetere con la stessa chiave di idempotenza.","headers":{"Retry-After":{"description":"Secondi da attendere.","schema":{"type":"integer"}}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RateLimitedResponse"}}}}},"security":[{"apiKey":[]}],"summary":"Ruota il segreto del webhook","tags":["Webhook in uscita"]}}},"info":{"title":"Elavya API","description":"API per i software partner che inviano e ricevono messaggi WhatsApp per conto di uno studio.\n\n## Autenticazione\nOgni richiesta porta `Authorization: Bearer elv_…`. La chiave identifica il workspace: non si passa mai un identificativo di tenant. Una chiave revocata o scaduta risponde 401 dalla richiesta successiva. Per ruotare: nuova chiave, aggiornare il software partner, revocare la vecchia.\n\n## Ambiente di prova\nQuesta versione include i workspace sandbox, con numero simulato, template subito approvati e chiavi `elv_test_…`. Si creano dalla console in Settings. Nessuna chiamata a Meta; esiti e risposte simulate passano nelle code e nei webhook firmati. `POST /api/whatsapp/sandbox/inbound` simula un testo entrante (202). La disponibilità della sandbox dipende dalla versione distribuita nell'ambiente; la sua presenza nel codice non certifica un rilascio. Dettagli nella [guida sandbox](/api/docs/guida/sandbox.html).\n\n## Invio asincrono\n`/messages/template`, `/text` e `/media` aspettano Meta e rispondono 201 con `sent` o con l'errore di Meta. Con `mode: \"async\"` nel corpo, oppure con l'header `Prefer: respond-async`, rispondono 202 con il messaggio `queued` subito dopo i controlli di Elavya (crediti, consenso, finestra, template), che restano sincroni. L'invio a Meta passa in coda con ripetizione degli errori temporanei; l'esito arriva con l'evento `message.status`. Il campo `mode` prevale sull'header e non fa parte del corpo confrontato per l'idempotenza.\n\n## Idempotenza\nGli invii (`/messages/template`, `/text`, `/media`, `/schedule`) richiedono `idempotencyKey`, unica per workspace. Ripetere la stessa richiesta con la stessa chiave restituisce il messaggio già creato senza un secondo invio; la stessa chiave con un corpo diverso risponde 409 `WHATSAPP_IDEMPOTENCY_CONFLICT`. Dopo un 503 il messaggio resta registrato `failed`: ripetere con la stessa chiave lo restituisce senza reinviarlo, quindi per un nuovo tentativo serve una nuova chiave. Se la causa era un timeout verso Meta il primo messaggio può essere arrivato comunque: il nuovo invio, in quel caso, è un doppione per il paziente.\n\nIl confronto ordina i campi al primo livello, senza normalizzare ricorsivamente gli oggetti annidati: conservare il corpo originale per i tentativi successivi.\n\n## Limiti\n- 120 richieste al minuto per chiave e 300 per workspace (condivise fra le chiavi dello stesso studio), finestra fissa di un minuto. Contano tutte le richieste autenticate, comprese letture e ripetizioni.\n- Oltre il limite: 429 `API_RATE_LIMITED` con header `Retry-After` e campo `retryAfter` in secondi. Attendere e ripetere con la stessa chiave di idempotenza: la richiesta rifiutata non ha creato nulla.\n- JSON massimo 100 KiB; file multipart su `/messages/media` fino a 10 MiB (JPEG/PNG 5 MB), massimo 4 richieste simultanee e 12 al minuto per workspace. Cache server SHA-256 per 30 giorni dall’upload, senza rinnovo al riuso; nessun hash richiesto al partner. Oltre il limite dimensionale: 413 `PAYLOAD_TOO_LARGE`.\n- Restano in vigore i limiti di invio che Meta applica al numero.\n\n## Errori\nGli errori applicativi hanno la forma `{ statusCode, code, message }`: usare `code`, stabile; `message` può cambiare. Gli errori di validazione (400) hanno invece `message` con l'elenco dei campi non validi.\n\n| HTTP | code |\n| --- | --- |\n| 400 | `WHATSAPP_INVALID_REQUEST`, validazione |\n| 401 | chiave mancante o non valida |\n| 402 | `WHATSAPP_CREDITS_EXHAUSTED`: crediti messaggi esauriti, nulla è stato creato |\n| 404 | `WHATSAPP_ACCOUNT_NOT_FOUND`, `WHATSAPP_CONTACT_NOT_FOUND`, `WHATSAPP_MESSAGE_NOT_FOUND` |\n| 409 | `WHATSAPP_IDEMPOTENCY_CONFLICT`, `WHATSAPP_CONTACT_OPTED_OUT`, `WHATSAPP_CONTACT_MARKETING_STOPPED`, `WHATSAPP_CONTACT_UTILITY_DISABLED`, `WHATSAPP_CONTACT_MARKETING_DISABLED`, `WHATSAPP_TEMPLATE_NOT_APPROVED`, `WHATSAPP_MESSAGE_ALREADY_PROCESSED`, `WHATSAPP_AUTHORIZATION_REQUIRED`, `WHATSAPP_NOT_AVAILABLE_IN_SANDBOX` (collegamento reale bloccato in sandbox) |\n| 413 | `PAYLOAD_TOO_LARGE` |\n| 422 | `WHATSAPP_OUTSIDE_ALLOWED_WINDOW`: fuori dalla finestra di 24 ore serve un template; `WHATSAPP_MESSAGE_REJECTED`: Meta ha rifiutato il messaggio in modo definitivo, codice Meta in `providerCode` |\n| 429 | `API_RATE_LIMITED` |\n| 503 | `WHATSAPP_MESSAGING_UNAVAILABLE`, `WHATSAPP_SCHEDULER_UNAVAILABLE` |\n\n## Flusso tipico\n1. `GET /api/whatsapp/accounts` e `GET /api/whatsapp/templates`: numero e template approvati da usare.\n2. `POST /api/whatsapp/contacts` con il numero del paziente (restituisce il contatto esistente se c'è già).\n3. `POST /api/whatsapp/messages/template` o `/schedule` con una `idempotencyKey` derivata dall'evento del software partner (es. `appuntamento-8812-promemoria`).\n4. Esiti (`delivered`, `read`, `failed`) e risposte dei pazienti arrivano con i webhook in uscita, descritti più sotto; `GET /api/whatsapp/messages/{id}` resta disponibile.\n\n## Compatibilità\nIl contratto cambia solo per aggiunte: nuovi campi, nuovi endpoint, nuovi valori negli eventi. Il client deve ignorare i campi che non conosce. Sono contratto i campi descritti qui; altri campi presenti nelle risposte possono cambiare.","version":"1","contact":{}},"tags":[],"servers":[],"components":{"securitySchemes":{"apiKey":{"scheme":"bearer","bearerFormat":"elv_…","type":"http","description":"Chiave API del workspace, creata dal proprietario in Settings › Chiavi API. Prefisso `elv_` nei workspace reali, `elv_test_` nelle sandbox. Header `Authorization: Bearer <chiave>`."}},"schemas":{"UnauthorizedResponse":{"type":"object","properties":{"statusCode":{"type":"number","example":401},"message":{"type":"string","example":"Unauthorized"}},"required":["statusCode","message"]},"PayloadTooLargeResponse":{"type":"object","properties":{"statusCode":{"type":"number","example":413},"code":{"type":"string","example":"PAYLOAD_TOO_LARGE"},"message":{"type":"string"}},"required":["statusCode","code"]},"RateLimitedResponse":{"type":"object","properties":{"code":{"type":"string","example":"API_RATE_LIMITED","description":"API_RATE_LIMITED per quota generale; MEDIA_RATE_LIMITED per limite upload multipart."},"message":{"type":"string"},"retryAfter":{"type":"number","description":"Secondi da attendere; uguale all'header `Retry-After`.","example":17}},"required":["code","message","retryAfter"]},"ErrorResponse":{"type":"object","properties":{"statusCode":{"type":"number","example":409},"code":{"type":"string","example":"WHATSAPP_IDEMPOTENCY_CONFLICT","description":"Codice stabile, da usare nel codice del software partner."},"message":{"type":"string","description":"Spiegazione per chi legge i log; può cambiare."},"providerCode":{"type":"string","example":"131037","description":"Solo con `WHATSAPP_MESSAGE_REJECTED`: codice di errore di Meta."}},"required":["statusCode","code","message"]},"ValidationErrorResponse":{"type":"object","properties":{"statusCode":{"type":"number","example":400},"message":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}],"example":["idempotencyKey must be shorter than or equal to 255 characters"],"description":"Elenco dei campi non validi (o un solo testo per parametri del percorso)."},"error":{"type":"string","example":"Bad Request"}},"required":["statusCode","message","error"]},"MessageDirection":{"type":"string","enum":["inbound","outbound"]},"MessageType":{"type":"string","enum":["text","template","media","unknown"]},"MessageStatus":{"type":"string","enum":["created","scheduled","queued","sending","sent","delivered","read","failed","cancelled"],"description":"Gli stati successivi all'invio (`delivered`, `read`, `failed`) arrivano da Meta, oppure dal simulatore in sandbox: per riceverli senza polling usare i webhook in uscita."},"MessageListItem":{"type":"object","properties":{"from":{"type":["string","null"]},"to":{"type":["string","null"]},"mediaId":{"type":["string","null"],"format":"uuid"},"mediaExpiresAt":{"type":["string","null"],"format":"date-time"},"id":{"type":"string","format":"uuid"},"whatsappAccountId":{"type":"string","format":"uuid"},"conversationId":{"type":["string","null"],"format":"uuid"},"contactId":{"type":"string","format":"uuid"},"providerMessageId":{"type":["string","null"],"description":"Identificativo `wamid` assegnato da Meta (simulato in sandbox) all'invio."},"idempotencyKey":{"type":["string","null"]},"direction":{"allOf":[{"$ref":"#/components/schemas/MessageDirection"}]},"type":{"allOf":[{"$ref":"#/components/schemas/MessageType"}]},"status":{"description":"Gli stati successivi all'invio (`delivered`, `read`, `failed`) arrivano da Meta, oppure dal simulatore in sandbox: per riceverli senza polling usare i webhook in uscita.","allOf":[{"$ref":"#/components/schemas/MessageStatus"}]},"templateId":{"type":["string","null"],"format":"uuid"},"payload":{"type":"object","additionalProperties":true,"description":"Contenuto inviato: `kind` vale `template` (name, language, variables), `text` (text) o `media` (mediaType, url oppure mediaId/mediaExpiresAt, caption, filename)."},"scheduledAt":{"type":["string","null"],"format":"date-time"},"sentAt":{"type":["string","null"],"format":"date-time"},"deliveredAt":{"type":["string","null"],"format":"date-time"},"readAt":{"type":["string","null"],"format":"date-time"},"failedAt":{"type":["string","null"],"format":"date-time"},"failureCode":{"type":["string","null"]},"failureMessage":{"type":["string","null"]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"},"contactPhone":{"type":"string","description":"Numero del contatto (E.164)."},"accountPhone":{"type":"string","description":"Numero dell'account che ha inviato o ricevuto."}},"required":["from","to","mediaId","mediaExpiresAt","id","whatsappAccountId","conversationId","contactId","providerMessageId","idempotencyKey","direction","type","status","templateId","payload","scheduledAt","sentAt","deliveredAt","readAt","failedAt","failureCode","failureMessage","createdAt","updatedAt","contactPhone","accountPhone"]},"TemplateHeaderValueDto":{"type":"object","properties":{"text":{"type":"string","maxLength":60,"description":"Valore di `{{1}}` per un'intestazione di testo con variabile."},"mediaType":{"type":"string","enum":["image","document","video"],"description":"Facoltativo: se indicato deve coincidere con il tipo di intestazione del template."},"url":{"type":"string","format":"uri","maxLength":2048,"description":"File dell'intestazione, indirizzo HTTPS raggiungibile da Meta."},"mediaId":{"type":"string","format":"uuid","description":"Riferimento `mediaId` di un file già caricato per lo stesso numero (risposta di `POST /messages/media`), valido 30 giorni."},"filename":{"type":"string","maxLength":240,"description":"Nome mostrato per un documento."}}},"TemplateButtonValueDto":{"type":"object","properties":{"index":{"type":"number","minimum":0,"maximum":9,"description":"Posizione del pulsante nel template, da 0."},"value":{"type":"string","maxLength":2000,"description":"Link dinamico: la parte finale dell'indirizzo. «Copia codice»: il codice (1-15 lettere o cifre). Risposta rapida: il payload restituito nel webhook `message.received` come `reply.id`."}},"required":["index","value"]},"SendTemplateMessageDto":{"type":"object","properties":{"accountId":{"type":"string","format":"uuid","description":"Alternativa compatibile: usare la coppia accountId/contactId oppure from/to."},"contactId":{"type":"string","format":"uuid"},"from":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","example":"+390212345678","description":"Numero dello studio già collegato al workspace."},"to":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","example":"+393401234567","description":"Destinatario già presente nei contatti; altrimenti creare prima con POST /contacts."},"templateId":{"type":"string","format":"uuid","description":"Template approvato dello stesso account."},"variables":{"type":"object","description":"Compilare tutti i segnaposto del corpo del template, usando esattamente le loro chiavi numeriche (`1`, `2`…). Ogni valore deve essere una stringa non vuota di al massimo 1024 caratteri. Se il corpo è fisso, omettere `variables` o passare `{}`.","additionalProperties":{"type":"string","minLength":1,"maxLength":1024},"example":{"1":"Mario","2":"mercoledì 21 ottobre alle 15:30"}},"header":{"description":"Solo per template con intestazione di testo con `{{1}}` o con intestazione immagine, documento o video. Per i file si può omettere quando il template ha un file salvato in Elavya: si usa quello.","allOf":[{"$ref":"#/components/schemas/TemplateHeaderValueDto"}]},"buttons":{"maxItems":10,"description":"Obbligatorio per i pulsanti con link dinamico e «copia codice»; facoltativo per le risposte rapide (payload).","type":"array","items":{"$ref":"#/components/schemas/TemplateButtonValueDto"}},"mode":{"type":"string","enum":["sync","async"],"default":"sync","description":"`sync` (predefinito): la risposta arriva dopo la chiamata a Meta, con lo stato `sent` o l'errore di Meta. `async`: la risposta è `202` con lo stato `queued` subito dopo i controlli di Elavya; l'invio a Meta avviene in coda, con ripetizione automatica degli errori temporanei, e l'esito arriva con l'evento `message.status`. Equivale all'header `Prefer: respond-async`; se presente, questo campo prevale sull'header. Non fa parte del corpo confrontato per l'idempotenza."},"idempotencyKey":{"type":"string","description":"Chiave scelta dal software partner, unica per workspace. Stessa chiave e stesso corpo: risponde con il messaggio già creato, senza un secondo invio. Stessa chiave e corpo diverso: 409 `WHATSAPP_IDEMPOTENCY_CONFLICT`. Storico di 30 giorni; dopo la cancellazione il replay risponde 410 `WHATSAPP_MESSAGE_EXPIRED`. La protezione dura almeno 90 giorni dalla creazione e 60 dalla cancellazione: non ripetere eventi oltre questa finestra.","maxLength":255,"pattern":"^\\S+$","example":"appuntamento-8812-promemoria"}},"required":["templateId","idempotencyKey"],"oneOf":[{"required":["from","to"],"not":{"anyOf":[{"required":["accountId"]},{"required":["contactId"]}]}},{"required":["accountId","contactId"],"not":{"anyOf":[{"required":["from"]},{"required":["to"]}]}}]},"MessageResponse":{"type":"object","properties":{"from":{"type":["string","null"]},"to":{"type":["string","null"]},"mediaId":{"type":["string","null"],"format":"uuid"},"mediaExpiresAt":{"type":["string","null"],"format":"date-time"},"id":{"type":"string","format":"uuid"},"whatsappAccountId":{"type":"string","format":"uuid"},"conversationId":{"type":["string","null"],"format":"uuid"},"contactId":{"type":"string","format":"uuid"},"providerMessageId":{"type":["string","null"],"description":"Identificativo `wamid` assegnato da Meta (simulato in sandbox) all'invio."},"idempotencyKey":{"type":["string","null"]},"direction":{"allOf":[{"$ref":"#/components/schemas/MessageDirection"}]},"type":{"allOf":[{"$ref":"#/components/schemas/MessageType"}]},"status":{"description":"Gli stati successivi all'invio (`delivered`, `read`, `failed`) arrivano da Meta, oppure dal simulatore in sandbox: per riceverli senza polling usare i webhook in uscita.","allOf":[{"$ref":"#/components/schemas/MessageStatus"}]},"templateId":{"type":["string","null"],"format":"uuid"},"payload":{"type":"object","additionalProperties":true,"description":"Contenuto inviato: `kind` vale `template` (name, language, variables), `text` (text) o `media` (mediaType, url oppure mediaId/mediaExpiresAt, caption, filename)."},"scheduledAt":{"type":["string","null"],"format":"date-time"},"sentAt":{"type":["string","null"],"format":"date-time"},"deliveredAt":{"type":["string","null"],"format":"date-time"},"readAt":{"type":["string","null"],"format":"date-time"},"failedAt":{"type":["string","null"],"format":"date-time"},"failureCode":{"type":["string","null"]},"failureMessage":{"type":["string","null"]},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"required":["from","to","mediaId","mediaExpiresAt","id","whatsappAccountId","conversationId","contactId","providerMessageId","idempotencyKey","direction","type","status","templateId","payload","scheduledAt","sentAt","deliveredAt","readAt","failedAt","failureCode","failureMessage","createdAt","updatedAt"]},"SendTextMessageDto":{"type":"object","properties":{"accountId":{"type":"string","format":"uuid","description":"Alternativa compatibile: usare la coppia accountId/contactId oppure from/to."},"contactId":{"type":"string","format":"uuid"},"from":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","example":"+390212345678","description":"Numero dello studio già collegato al workspace."},"to":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","example":"+393401234567","description":"Destinatario già presente nei contatti; altrimenti creare prima con POST /contacts."},"text":{"type":"string","maxLength":4096,"description":"Ammesso solo entro 24 ore dall'ultimo messaggio del contatto; altrimenti 422."},"conversationId":{"type":"string","format":"uuid"},"mode":{"type":"string","enum":["sync","async"],"default":"sync","description":"`sync` (predefinito): la risposta arriva dopo la chiamata a Meta, con lo stato `sent` o l'errore di Meta. `async`: la risposta è `202` con lo stato `queued` subito dopo i controlli di Elavya; l'invio a Meta avviene in coda, con ripetizione automatica degli errori temporanei, e l'esito arriva con l'evento `message.status`. Equivale all'header `Prefer: respond-async`; se presente, questo campo prevale sull'header. Non fa parte del corpo confrontato per l'idempotenza."},"idempotencyKey":{"type":"string","description":"Chiave scelta dal software partner, unica per workspace. Stessa chiave e stesso corpo: risponde con il messaggio già creato, senza un secondo invio. Stessa chiave e corpo diverso: 409 `WHATSAPP_IDEMPOTENCY_CONFLICT`. Storico di 30 giorni; dopo la cancellazione il replay risponde 410 `WHATSAPP_MESSAGE_EXPIRED`. La protezione dura almeno 90 giorni dalla creazione e 60 dalla cancellazione: non ripetere eventi oltre questa finestra.","maxLength":255,"pattern":"^\\S+$","example":"appuntamento-8812-promemoria"}},"required":["text","idempotencyKey"],"oneOf":[{"required":["from","to"],"not":{"anyOf":[{"required":["accountId"]},{"required":["contactId"]}]}},{"required":["accountId","contactId"],"not":{"anyOf":[{"required":["from"]},{"required":["to"]}]}}]},"SendMediaMessageDto":{"type":"object","properties":{"accountId":{"type":"string","format":"uuid","description":"Alternativa compatibile: usare la coppia accountId/contactId oppure from/to."},"contactId":{"type":"string","format":"uuid"},"from":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","example":"+390212345678","description":"Numero dello studio già collegato al workspace."},"to":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","example":"+393401234567","description":"Destinatario già presente nei contatti; altrimenti creare prima con POST /contacts."},"mediaType":{"type":"string","enum":["image","document","audio","video"]},"url":{"type":"string","format":"uri","maxLength":2048,"description":"URL https pubblico da cui Meta scarica il file."},"mediaId":{"type":"string","format":"uuid","description":"Riferimento Elavya riutilizzabile per 30 giorni dall’upload originale sullo stesso numero mittente. Alternativo a file e url."},"caption":{"type":"string","maxLength":1024},"filename":{"type":"string","maxLength":255},"conversationId":{"type":"string","format":"uuid"},"mode":{"type":"string","enum":["sync","async"],"default":"sync","description":"`sync` (predefinito): la risposta arriva dopo la chiamata a Meta, con lo stato `sent` o l'errore di Meta. `async`: la risposta è `202` con lo stato `queued` subito dopo i controlli di Elavya; l'invio a Meta avviene in coda, con ripetizione automatica degli errori temporanei, e l'esito arriva con l'evento `message.status`. Equivale all'header `Prefer: respond-async`; se presente, questo campo prevale sull'header. Non fa parte del corpo confrontato per l'idempotenza."},"idempotencyKey":{"type":"string","description":"Chiave scelta dal software partner, unica per workspace. Stessa chiave e stesso corpo: risponde con il messaggio già creato, senza un secondo invio. Stessa chiave e corpo diverso: 409 `WHATSAPP_IDEMPOTENCY_CONFLICT`. Storico di 30 giorni; dopo la cancellazione il replay risponde 410 `WHATSAPP_MESSAGE_EXPIRED`. La protezione dura almeno 90 giorni dalla creazione e 60 dalla cancellazione: non ripetere eventi oltre questa finestra.","maxLength":255,"pattern":"^\\S+$","example":"appuntamento-8812-promemoria"}},"required":["mediaType","idempotencyKey"],"oneOf":[{"required":["from","to"],"not":{"anyOf":[{"required":["accountId"]},{"required":["contactId"]}]}},{"required":["accountId","contactId"],"not":{"anyOf":[{"required":["from"]},{"required":["to"]}]}}]},"ScheduleTemplateMessageDto":{"type":"object","properties":{"accountId":{"type":"string","format":"uuid","description":"Alternativa compatibile: usare la coppia accountId/contactId oppure from/to."},"contactId":{"type":"string","format":"uuid"},"from":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","example":"+390212345678","description":"Numero dello studio già collegato al workspace."},"to":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","example":"+393401234567","description":"Destinatario già presente nei contatti; altrimenti creare prima con POST /contacts."},"templateId":{"type":"string","format":"uuid","description":"Template approvato dello stesso account."},"variables":{"type":"object","description":"Compilare tutti i segnaposto del corpo del template, usando esattamente le loro chiavi numeriche (`1`, `2`…). Ogni valore deve essere una stringa non vuota di al massimo 1024 caratteri. Se il corpo è fisso, omettere `variables` o passare `{}`.","additionalProperties":{"type":"string","minLength":1,"maxLength":1024},"example":{"1":"Mario","2":"mercoledì 21 ottobre alle 15:30"}},"header":{"description":"Solo per template con intestazione di testo con `{{1}}` o con intestazione immagine, documento o video. Per i file si può omettere quando il template ha un file salvato in Elavya: si usa quello.","allOf":[{"$ref":"#/components/schemas/TemplateHeaderValueDto"}]},"buttons":{"maxItems":10,"description":"Obbligatorio per i pulsanti con link dinamico e «copia codice»; facoltativo per le risposte rapide (payload).","type":"array","items":{"$ref":"#/components/schemas/TemplateButtonValueDto"}},"scheduledAt":{"type":"string","format":"date-time","description":"Momento dell'invio, nel futuro (ISO 8601 con fuso).","example":"2026-10-20T08:00:00+02:00"},"idempotencyKey":{"type":"string","description":"Chiave scelta dal software partner, unica per workspace. Stessa chiave e stesso corpo: risponde con il messaggio già creato, senza un secondo invio. Stessa chiave e corpo diverso: 409 `WHATSAPP_IDEMPOTENCY_CONFLICT`. Storico di 30 giorni; dopo la cancellazione il replay risponde 410 `WHATSAPP_MESSAGE_EXPIRED`. La protezione dura almeno 90 giorni dalla creazione e 60 dalla cancellazione: non ripetere eventi oltre questa finestra.","maxLength":255,"pattern":"^\\S+$","example":"appuntamento-8812-promemoria"}},"required":["templateId","scheduledAt","idempotencyKey"],"oneOf":[{"required":["from","to"],"not":{"anyOf":[{"required":["accountId"]},{"required":["contactId"]}]}},{"required":["accountId","contactId"],"not":{"anyOf":[{"required":["from"]},{"required":["to"]}]}}]},"TemplateCategory":{"type":"string","enum":["utility","marketing","authentication"]},"TemplateStatus":{"type":"string","enum":["approved","pending","rejected","paused","disabled","deleted"],"description":"Solo i template `approved` si possono inviare."},"TemplateResponse":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"whatsappAccountId":{"type":"string","format":"uuid"},"metaTemplateId":{"type":["string","null"]},"name":{"type":"string","example":"promemoria_appuntamento"},"language":{"type":"string","example":"it"},"category":{"allOf":[{"$ref":"#/components/schemas/TemplateCategory"}]},"status":{"description":"Solo i template `approved` si possono inviare.","allOf":[{"$ref":"#/components/schemas/TemplateStatus"}]},"components":{"type":["array","null"],"items":{"type":"object","additionalProperties":true},"description":"Componenti come restituiti da Meta (testata, corpo, piè di pagina, pulsanti)."},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"required":["id","whatsappAccountId","metaTemplateId","name","language","category","status","components","createdAt","updatedAt"]},"SyncByPhoneDto":{"type":"object","properties":{"from":{"type":"string","example":"+390212345678","pattern":"^\\+[1-9]\\d{7,14}$"}},"required":["from"]},"TemplateSyncResponse":{"type":"object","properties":{"synced":{"type":"number","description":"Template letti da Meta e salvati; in sandbox, numero dei template locali."},"removed":{"type":"number","description":"Template non più presenti su Meta, marcati `deleted`."}},"required":["synced","removed"]},"ConnectionMode":{"type":"string","enum":["cloud_api","coexistence"]},"AccountStatus":{"type":"string","enum":["active","disconnected","suspended","reauthorization_required"],"description":"`reauthorization_required`: il proprietario deve riautorizzare il numero dal pannello; gli invii rispondono 409."},"AccountResponse":{"type":"object","properties":{"phoneNumber":{"type":["string","null"],"description":"Numero E.164 utilizzabile come from; null se la mappatura storica richiede verifica."},"id":{"type":"string","format":"uuid"},"wabaId":{"type":"string"},"phoneNumberId":{"type":"string"},"displayPhoneNumber":{"type":"string","example":"+39 06 1234 5678"},"connectionMode":{"allOf":[{"$ref":"#/components/schemas/ConnectionMode"}]},"status":{"description":"`reauthorization_required`: il proprietario deve riautorizzare il numero dal pannello; gli invii rispondono 409.","allOf":[{"$ref":"#/components/schemas/AccountStatus"}]},"createdAt":{"type":"string","format":"date-time"}},"required":["phoneNumber","id","wabaId","phoneNumberId","displayPhoneNumber","connectionMode","status","createdAt"]},"SignupConfigResponse":{"type":"object","properties":{"appId":{"type":"string"},"configId":{"type":"string"}},"required":["appId","configId"]},"ConnectCoexistenceDto":{"type":"object","properties":{"code":{"type":"string","maxLength":2048,"description":"Codice restituito da Embedded Signup."},"wabaId":{"type":"string","pattern":"^\\d{5,30}$"},"phoneNumberId":{"type":"string","pattern":"^\\d{5,30}$"}},"required":["code","wabaId","phoneNumberId"]},"ContactResponse":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"phoneNumber":{"type":"string","example":"+393401234567"},"whatsappUserId":{"type":["string","null"]},"externalContactId":{"type":["string","null"]},"optInAt":{"type":["string","null"],"format":"date-time"},"optOutAt":{"type":["string","null"],"format":"date-time","description":"Se valorizzato, gli invii al contatto rispondono 409."},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"required":["id","phoneNumber","whatsappUserId","externalContactId","optInAt","optOutAt","createdAt","updatedAt"]},"CreateContactDto":{"type":"object","properties":{"phoneNumber":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","description":"Numero in formato E.164.","example":"+393401234567"},"optedIn":{"type":"boolean","description":"Il paziente ha dato il consenso a ricevere messaggi WhatsApp: registra la data del consenso."}},"required":["phoneNumber"]},"SimulateInboundDto":{"type":"object","properties":{"accountId":{"type":"string","format":"uuid","description":"Numero di prova del workspace che riceve il messaggio."},"to":{"type":"string","example":"+390212345678"},"from":{"type":"string","pattern":"^\\+[1-9]\\d{7,14}$","description":"Numero del paziente simulato (E.164). Se non è ancora un contatto, viene creato.","example":"+393401234567"},"text":{"type":"string","minLength":1,"maxLength":4096,"example":"Confermo, grazie"}},"required":["from","text"],"oneOf":[{"required":["to"],"not":{"required":["accountId"]}},{"required":["accountId"],"not":{"required":["to"]}}]},"SandboxInboundResponse":{"type":"object","properties":{"providerMessageId":{"type":"string","example":"wamid.sandbox.in.4f1c…","description":"Identificativo del messaggio simulato; ritorna come `providerMessageId` nell'evento `message.received`."}},"required":["providerMessageId"]},"WebhookEndpointResponse":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"url":{"type":"string","format":"uri"},"events":{"type":"array","items":{"type":"string","enum":["message.status","message.received"]}},"description":{"type":["string","null"]},"createdAt":{"type":"string","format":"date-time"}},"required":["id","url","events","description","createdAt"]},"CreateWebhookDto":{"type":"object","properties":{"url":{"type":"string","format":"uri","maxLength":2048,"description":"URL HTTPS pubblico."},"description":{"type":"string","maxLength":80},"events":{"type":"array","minItems":1,"maxItems":2,"items":{"type":"string","enum":["message.status","message.received"]}}},"required":["url","events"]},"CreatedWebhookResponse":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"url":{"type":"string","format":"uri"},"events":{"type":"array","items":{"type":"string","enum":["message.status","message.received"]}},"description":{"type":["string","null"]},"createdAt":{"type":"string","format":"date-time"},"secret":{"type":"string","description":"Segreto di firma mostrato una sola volta."}},"required":["id","url","events","description","createdAt","secret"]},"RotatedWebhookSecretResponse":{"type":"object","properties":{"secret":{"type":"string","description":"Nuovo segreto di firma, mostrato una sola volta."}},"required":["secret"]},"MessageStatusEventData":{"type":"object","required":["from","to","messageId","providerMessageId","accountId","contactId","externalContactId","contactPhone","status","idempotencyKey","failure"],"properties":{"from":{"type":["string","null"]},"to":{"type":["string","null"]},"messageId":{"type":"string","format":"uuid"},"providerMessageId":{"type":["string","null"],"description":"Identificativo `wamid` di Meta, simulato in sandbox."},"accountId":{"type":"string","format":"uuid"},"contactId":{"type":"string","format":"uuid"},"externalContactId":{"type":["string","null"]},"contactPhone":{"type":"string","description":"Numero del contatto (E.164)."},"status":{"type":"string","enum":["sent","delivered","read","failed","cancelled"]},"idempotencyKey":{"type":["string","null"],"description":"La chiave usata all'invio: collega l'evento alla richiesta del software partner."},"failure":{"oneOf":[{"type":"null"},{"type":"object","properties":{"code":{"type":["string","null"]},"message":{"type":["string","null"]}}}],"description":"Solo con `status: failed`."}}},"MessageReceivedEventData":{"type":"object","required":["from","to","messageId","providerMessageId","accountId","contactId","externalContactId","contactPhone","type","text","media"],"properties":{"from":{"type":["string","null"]},"to":{"type":["string","null"]},"messageId":{"type":"string","format":"uuid"},"providerMessageId":{"type":["string","null"],"description":"Identificativo `wamid` di Meta, simulato in sandbox."},"accountId":{"type":"string","format":"uuid"},"contactId":{"type":"string","format":"uuid"},"externalContactId":{"type":["string","null"]},"contactPhone":{"type":"string","description":"Numero del contatto (E.164)."},"type":{"type":"string","description":"Tipo WhatsApp: `text`, `image`, `document`, `audio`, `video`, … o `unknown`."},"text":{"type":["string","null"],"description":"Solo per `type: text`."},"media":{"oneOf":[{"type":"null"},{"type":"object","properties":{"mimeType":{"type":["string","null"]},"caption":{"type":["string","null"]},"filename":{"type":["string","null"]}}}],"description":"Descrizione del file; il file resta su Meta."}}}}},"webhooks":{"message.status":{"post":{"summary":"Stato di un messaggio inviato","description":"Un messaggio in uscita inviato da API o pannello diventa `sent`, `delivered`, `read`, `failed` o `cancelled`. Esclude i messaggi scritti nell’app WhatsApp Business. Gli esiti regressivi vengono scartati; le consegne già registrate possono arrivare fuori ordine. Inviato all'URL configurato in Settings › Webhook per gli eventi scelti. Consegna almeno una volta: fino a 9 tentativi in circa 23 ore, poi la consegna resta «non riuscita» nel pannello, da cui si può ripetere. Le consegne concluse si cancellano dopo 30 giorni.","tags":["Webhook in uscita"],"parameters":[{"name":"Elavya-Signature","in":"header","required":true,"schema":{"type":"string","example":"t=1760600000,v1=5d2c…"},"description":"`t` = secondi Unix, `v1` = HMAC-SHA256 esadecimale di `\"<t>.<corpo grezzo>\"` con il segreto del webhook. Durante la rotazione per 24 ore ci sono due valori `v1`, prima il nuovo segreto e poi il precedente. Accettare una qualsiasi firma valida e rifiutare se `t` dista più di 5 minuti."},{"name":"Elavya-Event-Id","in":"header","required":true,"schema":{"type":"string"}},{"name":"Elavya-Event-Type","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["id","type","occurredAt","data"],"properties":{"id":{"type":"string","description":"Uguale a ogni tentativo e per ogni endpoint: deduplicare su questo valore."},"type":{"const":"message.status"},"occurredAt":{"type":"string","format":"date-time","description":"Quando è avvenuto il fatto, non quando parte la richiesta. Gli eventi possono arrivare fuori ordine."},"data":{"$ref":"#/components/schemas/MessageStatusEventData"}}}}}},"responses":{"2XX":{"description":"Ricevuto. Qualsiasi altra risposta, o nessuna entro il timeout, fa ripetere la consegna."}}}},"message.received":{"post":{"summary":"Messaggio ricevuto","description":"Un paziente ha scritto al numero dello studio. Inviato all'URL configurato in Settings › Webhook per gli eventi scelti. Consegna almeno una volta: fino a 9 tentativi in circa 23 ore, poi la consegna resta «non riuscita» nel pannello, da cui si può ripetere. Le consegne concluse si cancellano dopo 30 giorni.","tags":["Webhook in uscita"],"parameters":[{"name":"Elavya-Signature","in":"header","required":true,"schema":{"type":"string","example":"t=1760600000,v1=5d2c…"},"description":"`t` = secondi Unix, `v1` = HMAC-SHA256 esadecimale di `\"<t>.<corpo grezzo>\"` con il segreto del webhook. Durante la rotazione per 24 ore ci sono due valori `v1`, prima il nuovo segreto e poi il precedente. Accettare una qualsiasi firma valida e rifiutare se `t` dista più di 5 minuti."},{"name":"Elavya-Event-Id","in":"header","required":true,"schema":{"type":"string"}},{"name":"Elavya-Event-Type","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["id","type","occurredAt","data"],"properties":{"id":{"type":"string","description":"Uguale a ogni tentativo e per ogni endpoint: deduplicare su questo valore."},"type":{"const":"message.received"},"occurredAt":{"type":"string","format":"date-time","description":"Quando è avvenuto il fatto, non quando parte la richiesta. Gli eventi possono arrivare fuori ordine."},"data":{"$ref":"#/components/schemas/MessageReceivedEventData"}}}}}},"responses":{"2XX":{"description":"Ricevuto. Qualsiasi altra risposta, o nessuna entro il timeout, fa ripetere la consegna."}}}},"ping":{"post":{"summary":"Prova","description":"Inviato dal pulsante «Prova» del pannello, a un solo endpoint. `data` è vuoto.","tags":["Webhook in uscita"],"parameters":[{"name":"Elavya-Signature","in":"header","required":true,"schema":{"type":"string","example":"t=1760600000,v1=5d2c…"},"description":"`t` = secondi Unix, `v1` = HMAC-SHA256 esadecimale di `\"<t>.<corpo grezzo>\"` con il segreto del webhook. Durante la rotazione per 24 ore ci sono due valori `v1`, prima il nuovo segreto e poi il precedente. Accettare una qualsiasi firma valida e rifiutare se `t` dista più di 5 minuti."},{"name":"Elavya-Event-Id","in":"header","required":true,"schema":{"type":"string"}},{"name":"Elavya-Event-Type","in":"header","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["id","type","occurredAt","data"],"properties":{"id":{"type":"string","description":"Uguale a ogni tentativo e per ogni endpoint: deduplicare su questo valore."},"type":{"const":"ping"},"occurredAt":{"type":"string","format":"date-time","description":"Quando è avvenuto il fatto, non quando parte la richiesta. Gli eventi possono arrivare fuori ordine."},"data":{"type":"object"}}}}}},"responses":{"2XX":{"description":"Ricevuto. Qualsiasi altra risposta, o nessuna entro il timeout, fa ripetere la consegna."}}}}}}