Action
オブジェクトを使用すると、インタラクティブな
Google Workspace アドオンにも反映されます。定義
ユーザーが Google Chat でウィジェット(ボタンなど)を
表示されます。
アクションは、 ウィジェット ハンドラ関数 アクションをトリガーする条件も定義します。トリガーされると、 アクションは、指定された Pod に コールバック関数を使用します。 コールバック関数には イベント オブジェクト。 ユーザーのクライアント側の操作に関する情報。実装する必要があります。 特定のレスポンス オブジェクトを返すように設定することもできます。
たとえば、必要なときに新しいカードを作成して表示するボタンを作成するとします。
クリックします。そのためには、新しいボタン ウィジェットを作成し、そのボタン ウィジェットを
ハンドラ関数
setOnClickAction(action)
カード作成 Action
を設定します。「
定義した Action
で Apps Script を指定
ボタンがクリックされたときに実行されるコールバック関数です。今回は
コールバック関数を実装して必要なカードを作成し、
ActionResponse
渡されます。応答オブジェクトはアドオンに対し、コールバックをカードに表示するよう指示します。
構築しました。
このページでは、 できます。
カレンダーの操作
カレンダーを拡張する Google Workspace アドオン には、カレンダー固有のウィジェット アクションをいくつか含めることができます。これらのアクション 関連するアクションのコールバック関数が必要 特殊なレスポンス オブジェクトを返します。
アクションを試行しました | コールバック関数は |
---|---|
参加者を追加する | CalendarEventActionResponse |
会議データの設定 | CalendarEventActionResponse |
添付ファイルの追加 | CalendarEventActionResponse |
ウィジェットのアクションとレスポンス オブジェクトを利用するには、 次の条件を満たしている必要があります。
- この操作は、ユーザーがカレンダーの予定を開いているときにトリガーされます。
- アドオンの
addOns.calendar.currentEventAccess
マニフェスト フィールドがWRITE
またはREAD_WRITE
に設定されている。 - このアドオンには
https://www.googleapis.com/auth/calendar.addons.current.event.write
カレンダーのスコープ。
また、アクション コールバック関数で行った変更は、次の時点まで ユーザーがカレンダーの予定を保存します。
コールバック関数を使用して参加者を追加する
次の例は、特定の Google サービスを追加するボタンの作成方法を示しています。 追加するには:
/**
* Build a simple card with a button that sends a notification.
* This function is called as part of the eventOpenTrigger that builds
* a UI when the user opens an event.
*
* @param e The event object passed to eventOpenTrigger function.
* @return {Card}
*/
function buildSimpleCard(e) {
var buttonAction = CardService.newAction()
.setFunctionName('onAddAttendeesButtonClicked');
var button = CardService.newTextButton()
.setText('Add new attendee')
.setOnClickAction(buttonAction);
// Check the event object to determine if the user can add
// attendees and disable the button if not.
if (!e.calendar.capabilities.canAddAttendees) {
button.setDisabled(true);
}
// ...continue creating card sections and widgets, then create a Card
// object to add them to. Return the built Card object.
}
/**
* Callback function for a button action. Adds attendees to the
* Calendar event being edited.
*
* @param {Object} e The action event object.
* @return {CalendarEventActionResponse}
*/
function onAddAttendeesButtonClicked (e) {
return CardService.newCalendarEventActionResponseBuilder()
.addAttendees(["aiko@example.com", "malcom@example.com"])
.build();
}
コールバック関数を使用して会議データを設定する
この操作により、開始イベントの会議データが設定されます。この会議データには アクションが適用されていないため、会議ソリューション ID を指定する必要があります。 トリガーされるトリガーです
次の例は、会議データを設定するボタンを作成する方法を示しています。 追加することもできます。
/**
* Build a simple card with a button that sends a notification.
* This function is called as part of the eventOpenTrigger that builds
* a UI when the user opens a Calendar event.
*
* @param e The event object passed to eventOpenTrigger function.
* @return {Card}
*/
function buildSimpleCard(e) {
var buttonAction = CardService.newAction()
.setFunctionName('onSaveConferenceOptionsButtonClicked')
.setParameters(
{'phone': "1555123467", 'adminEmail': "joyce@example.com"});
var button = CardService.newTextButton()
.setText('Add new attendee')
.setOnClickAction(buttonAction);
// Check the event object to determine if the user can set
// conference data and disable the button if not.
if (!e.calendar.capabilities.canSetConferenceData) {
button.setDisabled(true);
}
// ...continue creating card sections and widgets, then create a Card
// object to add them to. Return the built Card object.
}
/**
* Callback function for a button action. Sets conference data for the
* Calendar event being edited.
*
* @param {Object} e The action event object.
* @return {CalendarEventActionResponse}
*/
function onSaveConferenceOptionsButtonClicked(e) {
var parameters = e.commonEventObject.parameters;
// Create an entry point and a conference parameter.
var phoneEntryPoint = ConferenceDataService.newEntryPoint()
.setEntryPointType(ConferenceDataService.EntryPointType.PHONE)
.setUri('tel:' + parameters['phone']);
var adminEmailParameter = ConferenceDataService.newConferenceParameter()
.setKey('adminEmail')
.setValue(parameters['adminEmail']);
// Create a conference data object to set to this Calendar event.
var conferenceData = ConferenceDataService.newConferenceDataBuilder()
.addEntryPoint(phoneEntryPoint)
.addConferenceParameter(adminEmailParameter)
.setConferenceSolutionId('myWebScheduledMeeting')
.build();
return CardService.newCalendarEventActionResponseBuilder()
.setConferenceData(conferenceData)
.build();
}
コールバック関数を使用して添付ファイルを追加する
次の例は、添付ファイルを 編集中のカレンダーの予定:
/**
* Build a simple card with a button that creates a new attachment.
* This function is called as part of the eventAttachmentTrigger that
* builds a UI when the user goes through the add-attachments flow.
*
* @param e The event object passed to eventAttachmentTrigger function.
* @return {Card}
*/
function buildSimpleCard(e) {
var buttonAction = CardService.newAction()
.setFunctionName('onAddAttachmentButtonClicked');
var button = CardService.newTextButton()
.setText('Add a custom attachment')
.setOnClickAction(buttonAction);
// Check the event object to determine if the user can add
// attachments and disable the button if not.
if (!e.calendar.capabilities.canAddAttachments) {
button.setDisabled(true);
}
// ...continue creating card sections and widgets, then create a Card
// object to add them to. Return the built Card object.
}
/**
* Callback function for a button action. Adds attachments to the Calendar
* event being edited.
*
* @param {Object} e The action event object.
* @return {CalendarEventActionResponse}
*/
function onAddAttachmentButtonClicked(e) {
return CardService.newCalendarEventActionResponseBuilder()
.addAttachments([
CardService.newAttachment()
.setResourceUrl("https://example.com/test")
.setTitle("Custom attachment")
.setMimeType("text/html")
.setIconUrl("https://example.com/test.png")
])
.build();
}
添付ファイル アイコンの設定
添付ファイルのアイコンは、Google のインフラストラクチャでホストする必要があります。詳細については、 添付ファイル アイコン をご覧ください。