En este episodio **355 - ¿Para qué he hecho mi primera automatización con Zapier?** https://creators.spotify.com/pod/profile/al-daily-podcast/episodes/355---Para-qu-he-hecho-mi-primera-automatizacin-con-Zapier-e3bdk1e/a-acasp1u
Te contaba que había hecho mi primera automatización de zapier como complemento a un script y que me había ayudado para ello de chatGPT.
Al final estuve indagando si era posible que el script ejecutara todo el flujo sin necesidad de automatización.
Este es el script final:
```
const CALENDAR_ID = '[ID del calendario]
const EVENT_TITLE = 'KS - Title - speaker';
const FORM_EMAIL_FIELD = 'EMAIL';
const FORM_NAME_FIELD = 'NAME';
const EVENT_START = new Date(2026, 1, 18, 17, 0);
const EVENT_DURATION_MINUTES = 45;
function onFormSubmit(e) {
console.log("Script iniciado...");
let guestEmail;
try {
guestEmail = e.namedValues[FORM_EMAIL_FIELD][0].trim();
console.log("Email detectado: " + guestEmail);
} catch (err) {
console.error("ERROR crítico: No se pudo leer el email. ¿La columna se llama EMAIL?");
return;
}
try {
const calendar = CalendarApp.getCalendarById(CALENDAR_ID);
const start = new Date(EVENT_START);
const end = new Date(start.getTime() + EVENT_DURATION_MINUTES * 60 * 1000);
const events = calendar.getEvents(start, end);
const event = events.find(ev => ev.getTitle() === EVENT_TITLE) || events[0];
if (event) {
console.log("Evento encontrado: " + event.getTitle());
event.addGuest(guestEmail);
console.log("Invitado añadido al calendario.");
const userName = e.namedValues[FORM_NAME_FIELD] ? "Hi, " + e.namedValues[FORM_NAME_FIELD][0].trim() : "Hi.";
console.log("Intentando enviar correo a " + guestEmail + "...");
const asunto = "Confirmación: " + EVENT_TITLE;
const cuerpo = userName + ".\n\nThanks for registering for the next training! Check your calendar, we sent an invite there.\n\nAccept the event and join us on the day of our Knowledge sharing. See you there";
GmailApp.sendEmail(guestEmail, asunto, cuerpo, {
name: 'Nombre Apellidos '
});
console.log("¡Correo enviado con éxito!");
} else {
console.warn("No se encontró ningún evento.");
}
} catch (error) {
console.error("Error técnico durante la ejecución: " + error.toString());
}
}
function autorizarGmail() {
GmailApp.sendEmail(Session.getActiveUser().getEmail(), "Autorización completada", "Ahora el script tiene permiso para enviar mails.");
console.log("Permisos de Gmail concedidos.");
}
```
Dime qué te ha parecido este capitulo y deja un comentario en ivoox o Spotify.
Si lo prefieres, envíame un correo electrónico a la dirección de gmail almadailypodcast.
En redes soy @almajefi y me encuentras en X / Twitter, Bluesky, Threads, Instagram y Telegram.
Y ahora también puedes seguirme en substack: https://substack.com/@almajefi