如何将上下文菜单项添加到 Gmail 附加组件中的省略号菜单?
How to add contextual menu items to the ellipsis menu in a Gmail Add-on?
我正在使用 Google Apps 脚本构建 Gmail 插件。
如何根据上下文更改通用菜单项,如下面的 Evernote 附加组件示例所示?据我所知,这些菜单项是在清单中设置的,我找不到更改它们的方法。
您需要的是清单中定义的 CardAction
. They are not menu items per se, but effectively function as such, forming the ellipsis menu together with universal actions。
注意(见official guide) that CardAction
s differ from Actions
,因为前者不向Card
UI添加任何内容,将操作放在省略号菜单下:
Note: Don't confuse Action objects with CardAction objects. CardAction objects are card header menu items, while Action objects define responses to user interactions with the UI.
目前,CardActions
可以发起的动作类型有:
- 开始授权流程(
setAuthorizationAction
)
- 创建消息草稿(
setComposeAction
)
- 单击时执行函数 (
setOnClickAction
)
- 打开一个指定的link(
setOnClickOpenLinkAction
),可选地生成side-effects
- 使用全屏或弹出对话框打开 link(
setOpenLink
)
您可以为 Card
创建一个菜单生成器实用程序,它看起来像这样(示例在 TypeScript 中):
declare interface ActionOptions {
text: string;
action: GoogleAppsScript.Card_Service.Action;
}
const buildMenu = (
builder: GoogleAppsScript.Card_Service.CardBuilder,
items: ActionOptions[] = []
) => {
items.forEach(({ text, action }) => {
const ca = CardService.newCardAction();
ca.setText(text);
//assign a specific action type, i.e.:
//ca.setOnClickAction(action);
builder.addCardAction(ca);
});
//if used as pass-through, return the builder
return builder.build();
};
我正在使用 Google Apps 脚本构建 Gmail 插件。
如何根据上下文更改通用菜单项,如下面的 Evernote 附加组件示例所示?据我所知,这些菜单项是在清单中设置的,我找不到更改它们的方法。
您需要的是清单中定义的 CardAction
. They are not menu items per se, but effectively function as such, forming the ellipsis menu together with universal actions。
注意(见official guide) that CardAction
s differ from Actions
,因为前者不向Card
UI添加任何内容,将操作放在省略号菜单下:
Note: Don't confuse Action objects with CardAction objects. CardAction objects are card header menu items, while Action objects define responses to user interactions with the UI.
目前,CardActions
可以发起的动作类型有:
- 开始授权流程(
setAuthorizationAction
) - 创建消息草稿(
setComposeAction
) - 单击时执行函数 (
setOnClickAction
) - 打开一个指定的link(
setOnClickOpenLinkAction
),可选地生成side-effects - 使用全屏或弹出对话框打开 link(
setOpenLink
)
您可以为 Card
创建一个菜单生成器实用程序,它看起来像这样(示例在 TypeScript 中):
declare interface ActionOptions {
text: string;
action: GoogleAppsScript.Card_Service.Action;
}
const buildMenu = (
builder: GoogleAppsScript.Card_Service.CardBuilder,
items: ActionOptions[] = []
) => {
items.forEach(({ text, action }) => {
const ca = CardService.newCardAction();
ca.setText(text);
//assign a specific action type, i.e.:
//ca.setOnClickAction(action);
builder.addCardAction(ca);
});
//if used as pass-through, return the builder
return builder.build();
};