当我在Gmail正文(客户端)中点击超链接时,如何在服务器端脚本:Google App脚本中调用该函数? [英] How do I call the function in server side script : Google App Script when I hit a hyperlink in Gmail body (client side)?
问题描述
- 我通过将超链接作为HTML正文类型发送来在Gmail中发送批准请求. -成功
- 我没有调用页面,而是引用了链接来调用服务器端脚本中的函数. -成功
-
一旦电子邮件到达收件人,它将自动调用该功能. - 失败. 据说,当接收者单击批准"超链接时,只有应该触发的功能.
- I send an approval request in Gmail by sending hyperlink as HTML Body type. - Successful
- Instead of calling a page, I referred the link to call a function inside server side script. -Successful
It calls the function automatically as soon as the email reaches the recipient. - Failure. Supposedly when the recipient clicks the Approve hyperlink, then only the function supposed to triggered.
我创建了index.html,使用了HTMLService.createoutputfromfile和其他HTMLService功能,但失败了. 我不知道如何建立从客户端到服务器端脚本的通信.从Gmail到Google App脚本.
I created a index.html, used HTMLService.createoutputfromfile and other HTMLService features, it failed. I do not know how do I establish a communication from Client Side to Server Side script; from Gmail to Google App Script.
Google App脚本
function sendEmailToApproverOne(emailAdd, action, trackSheet,rowNumber){
var form_Name = FormApp.getActiveForm().getTitle();//Get the Name of this specific Form
var btnAction = "";//---gets the button name(Approve/Acknowledge) when the recipient receives the email ----
if(action == "Approval"){
btnAction = "Approve";
}
else if(action == "Acknowledgement"){
btnAction = "Acknowledge";
}
var message = getMessage(btnAction,trackSheet,rowNumber);//----calls a function to create the email body----
GmailApp.sendEmail(emailAdd, form_Name +': For your perusal to '+ btnAction , '', {htmlBody:message});
}
function getMessage(buttonLabel,trackSheet,rowNumber) {
var htmlOutput = HtmlService.createHtmlOutputFromFile('emailBody');
var message = htmlOutput.getContent()
message = message.replace("##LINK##", pressedApprove(trackSheet,rowNumber));
message = message.replace('##BUTTONLABEL##',buttonLabel);
return message;
}
//This function: pressedApprove() is triggered when the Approver presses approve in Email button
function pressedApprove(trackSheet,rowNumber){
Logger.log("This button is clicked");
//====some code to do with tracksheet and rownumber.
}
<a href="##LINK##" id="myLink" >##BUTTONLABEL##</a>
预计将看到此功能:仅当在Gmail中单击超链接时,才会触发PressedApprove(). 当我运行发送Gmail的代码时,我不希望每次都自动拨打电话.
Expected to see the function: pressedApprove() only triggered when the hyperlink is clicked inside the Gmail. Not expecting to auto calls every time when I run the code to send Gmail.
如何设置仅在Gmail正文中按下超链接时才触发功能的限制.
How do I set the restriction that the function only triggered when the hyperlink pressed in Gmail body.
推荐答案
-
发布您的Web应用程序:
Publish your web app:
- 以我"身份运行
- 访问权限:任何人,包括匿名
使用查询参数打开您的网络应用
Use query params to open your web-app
message = message.replace( '##LINK##', ScriptApp.getService().getUrl() + encodeURI( '?func=pressedApprove&trackSheet=' + trackSheet.getId() + //use a unique id string of sheet '&rowNumber=' + rowNumber ) );
- 使用
doGet()
来接收超链接并运行所需的功能:
function doGet(e){ var params = e.parameter; if(params.func === 'pressedApprove'){ return pressedApprove(params.trackSheet, params.rowNumber); } }
这篇关于当我在Gmail正文(客户端)中点击超链接时,如何在服务器端脚本:Google App脚本中调用该函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!