Google Apps 脚本将我 URL 中的“&”转换为“&”

Google Apps Script converts "&" in my URL to "& "

我的 google 应用程序脚本获取网络钩子地址、日历 ID、事件 ID 和一个字符串 (EventPrefix),将它们全部组合成一个 URL,这样我就可以用来将数据传递给 Integromat用于自动化。

URL 应符合以下语法(除非我误解了什么):https://SOMEWEBHOOKADDRESS?EventPrefix=STRING&CalendarID=CALENDARID&EventID=EVENTID

然而,结果URL是https://SOMEWEBHOOKADDRESS?EventPrefix=STRING&CalendarID=CALENDARID&EventID=EVENTID

因此,Integromat 获得:

amp;CalendarID 而不是 CalendarID
amp;EventID 而不是 EventID

我该怎么做才能按照上面的语法到达 URL? 谢谢

获取 URL:

位的代码

    var items = Calendar.Events.list('abc123@group.calendar.google.com', { timeMin: CurrentDate.toISOString(), timeMax: RangeEnd.toISOString(), maxResults: 2500 }).items;
  items.forEach(e => {
    var EventTitle = e.summary;
    var EventCreatedDate = new Date(e.created);
    var EventStartDate = new Date(e.start.dateTime || e.start.date);
    var EventEndDate = new Date(e.end.dateTime || e.end.date);
    var EventCreator = e.creator.email; //Gets the creator of the event to email notificaiton to
    var EventID = e.id;
    var CalendarID = FamilyCalendar.getId();
    var EventURL = e.htmlLink; 


    //Check if an event was created today AND does not have our names or "FYI" in its title
    if(EventCreatedDate.valueOf() <= CurrentDate.valueOf() && EventTitle.indexOf('Name1')<0 && EventTitle.indexOf('Name2')<0 && EventTitle.indexOf('Name3')<0 && EventTitle.indexOf('Name4')<0 && EventTitle.indexOf('Name5')<0 && EventTitle.indexOf('FYI')<0) 
      {
        //Creates variables for the HTML body of the email notification. The same variables are referenced in the body of the HTML template.
        var EmailMessage = HtmlService.createTemplateFromFile("EmailMessage"); //"EmailMessage" is the name of the HTML file in this script.
            EmailMessage.recepient = EventCreator;
            EmailMessage.eventTitle = EventTitle;
            EmailMessage.eventStartDate = EventStartDate;
            EmailMessage.eventEndDate = EventEndDate;
            EmailMessage.calendarID = CalendarID;
            EmailMessage.eventID = EventID;

构建 HTML 要发送的电子邮件消息,其中包含日历详细信息和超链接以触发 Integromat 自动化:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <p>Hi <?= recepient ?>,</p>

    <p>You just created an event in the Family Calendar but did not specify who this event is for:</p>

    <p><b>Event</b>: <?= eventTitle ?><br>
    <b>Starts</b>: <?= eventStartDate ?><br>
    <b>End</b>: <?= eventEndDate ?></p>

    <p>Please click on a link below to add it to the title of the event:</p>

    <p><b><a href="https://hook.integromat.com/p3uunmm7co9k11c5bdpni85k239a7e8x?EventPrefix=FYI&CalendarID=<?= calendarID ?>&EventID=<?= eventID ?>">FYI</a><br></p>

    <p>Thank you</p>
  </body>
</html>

当标签中包含&的值时,当EmailMessage.evaluate().getContent()检索到HTML数据时,&转换为&amp; .我认为当 &amp; 作为 HTML 正文的电子邮件发送时, URL 可以正确用作 &.

但是如果你想在你的脚本中检索 HTML 数据时看到 &amp;&,那么下面的修改怎么样?

修改后的脚本:

var htmlBody = EmailMessage.evaluate().getContent().replace(/&amp;/g, "&");
  • 如果您使用的是EmailMessage.evaluate().getContent(),请按上述修改。