javascript - 无法向访客发送新日历事件的通知 - Google Apps

标签 javascript google-apps-script google-calendar-api

在我的第一个单独实用应用程序的最后阶段,我似乎无法获得最后一 block 。

下面是我的代码,它将用户添加到特定的日历事件。 addGuest 正在工作 - 当它运行时,它们将被添加到该事件中。

但是,他们需要收到电子邮件,以便确认事件。旧的自动生成的 g-cal 邀请电子邮件就可以了。

据我所知,这应该可行,但它只添加访客,测试时不会发送电子邮件:

function assignToCal() {
  var row = scheduled.getLastRow();
  var timePicked = scheduled.getRange(row, 2).getValue();
  var email = scheduled.getRange(row, 3).getValue();
  var calId;

  for(var i = 0; i < slotTimes.length; i++)
  {
    if(slotTimes[i] == timePicked)
    {
      calId = slotIds[i];
    }
  }

  var session = calendar.getEventSeriesById(calId);
  session.addGuest(email);


  function sendInvite(calendar, calId, email) {
    var event = Calendar.Events.get(calendar, calId);
    event.attendees.push({
      email: email
    });
    event = Calendar.Events.patch(event, calendarId, eventId, {
      sendNotifications: true
    });
  }

  Logger.log(timePicked);
  Logger.log(calId);
};

另一个选项似乎是 using this POST request to update sendNotifications为客人。然而,说实话,我从来没有做过http请求,并且在过去的几天里也一直在尝试这样做,但我只是感到困惑。如果有人提出建议来完成这里需要做的事情,那也很酷。

谢谢!

最佳答案

作为 issue #574 中给出的给定解决方案在 Google Apps 脚本问题跟踪器中,您还可以尝试使用 Advanced Calendar service 。如前所述,

You can use Calendar.Events.patch() to add attendees, and if you set the optional parameter sendNotifications to "true" the attendees will get an invite.

示例代码实现:

function sendInvite(calendarId, eventId, email) {
  var event = Calendar.Events.get(calendarId, eventId);
  if(event.attendees) {
    event.attendees.push({
      email: email
    });
  } else {
    event.attendees = new Array({email: email});
  }
  event = Calendar.Events.patch(event, calendarId, eventId, {
    sendNotifications: true
  });
}

重要注意事项:如果您是事件所有者并且尝试添加自己的电子邮件地址,则不会收到电子邮件通知。

为了更好地理解如何实现这一点,还请查看 Issue #574 中的附加说明。希望有帮助!

关于javascript - 无法向访客发送新日历事件的通知 - Google Apps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40077139/

相关文章:

python - 使用 Google 日历 API 的 Web 应用程序

javascript - AngularJS JavaScript 解析 JSON 的一部分

javascript - 在 Google 表格中使用 Google Apps 脚本时如何防止日期变成字符串?

javascript - 阻止 onEdit 在某些选项卡上运行

java - 将 CalendarEvent 插入到 "primary"以外的其他日历

node.js - 将事件插入谷歌日历nodejs

javascript - Firefox - 如何在使用双击时获取选定的文本

javascript - 比较我的数组直到数组中有多个值

javascript - 如何在电子邮件中接收单选按钮按钮和其他值

javascript - 添加两个持续时间值