Google Calendar API添加新参会者时仅通知新用户的实现问题
Google Calendar API添加新参会者时仅通知新用户的实现问题
嗨,这个问题我之前也碰到过,确实挺闹心的——每次加人老参会者都收到重复邮件,关掉通知又连新用户都收不到。别担心,咱们可以通过给参会者单独设置通知权限来解决这个问题!
核心思路是:给原有参会者标记“不发送本次更新通知”,只让新添加的参会者收到通知。具体修改你的代码就行:
evento = Calendar.Events.get(calendarId, configuracion['EventId']); // 处理参会者列表,给老参会者加上不通知的设置 let invitados = []; if ('attendees' in evento) { // 遍历原有参会者,给每个都添加sendNotifications: false invitados = evento.attendees.map(attendee => ({ ...attendee, sendNotifications: false })); } // 添加新参会者,显式设置发送通知(也可以不写,默认是true) const nuevoInvitado = { email: respuestas['Dirección de correo electrónico'], sendNotifications: true }; invitados.push(nuevoInvitado); const recurso = { attendees: invitados }; // 这里sendUpdates设为"all",但因为老参会者的sendNotifications是false,只有新用户会收到邮件 const args = { sendUpdates: "all" }; Calendar.Events.patch(recurso, calendarId, evento.id, args);
为什么这样管用?因为Google Calendar API允许你给每个参会者单独设置sendNotifications属性,这个属性会覆盖全局的sendUpdates参数。当你把老参会者的这个属性设为false,即使全局sendUpdates是"all",他们也不会收到本次更新的邮件;而新参会者的sendNotifications是true,就会正常收到邀请通知啦。
另外还有个小细节:如果你的原有参会者里有之前已经设置过sendNotifications的,用map遍历覆盖成false也没关系,毕竟咱们只是不想让他们收到这次加人的通知,后续的其他更新还是会正常收到的。
备注:内容来源于stack exchange,提问作者Carlos Medina Gallego
相关产品推荐
相关产品推荐

