এই নির্দেশিকায় ব্যাখ্যা করা হয়েছে কীভাবে ব্যবহারকারীর বিভিন্ন কার্যকলাপ, যেমন কোনো বোতামে ক্লিক করা বা মেনু থেকে কোনো আইটেম নির্বাচন করার প্রতিক্রিয়ায় একটি কনফিগারেশন কার্ডকে গতিশীলভাবে আপডেট করা যায়।
ব্যবহারকারীর ইনপুটের সাথে খাপ খাইয়ে নিতে পারে এমন রেসপন্সিভ ইন্টারফেস তৈরি করার জন্য আপনি কার্ডের অংশ এবং উইজেট যোগ, অপসারণ বা প্রতিস্থাপন করতে পারেন। উদাহরণস্বরূপ, আপনি একটি কার্ড ইন্টারফেস আপডেট করে এমন ব্যবহারকারীকে একটি ভ্যালিডেশন ত্রুটির বার্তা দেখাতে পারেন, যিনি একটি পূর্ণসংখ্যার ইনপুট ফিল্ডে স্ট্রিং প্রবেশ করান; এবং তারপর ব্যবহারকারী একটি পূর্ণসংখ্যা প্রবেশ করানোর পর বার্তাটি লুকানোর জন্য ইন্টারফেসটি আবার আপডেট করতে পারেন।
কার্ডের বিভাগ এবং উইজেটগুলি পরিবর্তন করুন
একটি কার্ড আপডেট করতে, আপনার উইজেট অ্যাকশন (যেমন onClickAction ) অবশ্যই এমন একটি ফাংশনকে কল করবে যা পরিবর্তনের নির্দেশাবলী সম্বলিত একটি RenderActions অবজেক্ট রিটার্ন করে।
কার্ড সেকশনগুলোতে আপনি নিম্নলিখিত পরিবর্তনগুলো করতে পারেন:
- একটি সেকশন যোগ করুন:
setInsertSectionব্যবহার করে কার্ডের উপরে অথবা ID দ্বারা নির্দিষ্ট কোনো বিদ্যমান সেকশনের নিচে একটি সেকশন যোগ করুন। - একটি সেকশন অপসারণ করুন:
setRemoveSectionব্যবহার করে ID দ্বারা নির্দিষ্ট একটি সেকশন অপসারণ করুন। - সেকশন প্রতিস্থাপন করুন:
setReplaceSectionব্যবহার করে ID দ্বারা নির্দিষ্ট একটি নতুন সেকশন দিয়ে বিদ্যমান সেকশনটি প্রতিস্থাপন করুন।
কার্ড উইজেটগুলিতে, আপনি নিম্নলিখিত পরিবর্তনগুলি করতে পারেন:
- উইজেট যোগ করুন:
setInsertWidgetব্যবহার করে ID দ্বারা নির্দিষ্ট কোনো বিদ্যমান উইজেটের আগে বা পরে একটি উইজেট যোগ করুন। - উইজেট অপসারণ করুন:
setRemoveWidgetব্যবহার করে ID দ্বারা নির্দিষ্ট উইজেটটি অপসারণ করুন। - উইজেট প্রতিস্থাপন করুন:
setReplaceWidgetব্যবহার করে বিদ্যমান উইজেটের পরিবর্তে একটি নতুন উইজেট স্থাপন করুন।
উদাহরণ: সেকশন এবং উইজেট যোগ ও অপসারণ করুন
নিম্নলিখিত উদাহরণটি একটি কনফিগারেশন কার্ড তৈরি করে, যাতে এমন বাটন রয়েছে যা উইজেট ও সেকশন যোগ বা অপসারণ করার মাধ্যমে কার্ডটি পরিবর্তন করার জন্য ফাংশন কল করে।
JSON
{
"timeZone": "America/Los_Angeles",
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"addOns": {
"common": {
"name": "Test Project",
"logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
"useLocaleFromApp": true
},
"flows": {
"workflowElements": [
{
"id": "modify_card",
"state": "ACTIVE",
"name": "Modify Card",
"workflowAction": {
"inputs": [
{
"id": "value1",
"description": "The first input",
"cardinality": "SINGLE",
"dataType": {
"basicType": "STRING"
}
},
{
"id": "value2",
"description": "The second number",
"cardinality": "SINGLE",
"dataType": {
"basicType": "STRING"
}
},
{
"id": "value3",
"description": "The third number",
"cardinality": "SINGLE",
"dataType": {
"basicType": "STRING"
}
}
],
"outputs": [
{
"id": "result",
"description": "Modify Card result",
"cardinality": "SINGLE",
"dataType": {
"basicType": "STRING"
}
}
],
"onConfigFunction": "onConfig",
"onExecuteFunction": "onExecute"
}
}
]
}
}
}
অ্যাপস স্ক্রিপ্ট
// Return a configuration Card for the step.
function onConfig() {
const textInput_1 = CardService.newTextInput()
.setFieldName("value1")
.setTitle("First Value!")
.setId("text_input_1")
.setHostAppDataSource(
CardService.newHostAppDataSource()
.setWorkflowDataSource(
CardService.newWorkflowDataSource()
.setIncludeVariables(true)
)
);
const textInput_2 = CardService.newTextInput()
.setFieldName("value2")
.setTitle("Second Value!")
.setId("text_input_2")
.setHostAppDataSource(
CardService.newHostAppDataSource()
.setWorkflowDataSource(
CardService.newWorkflowDataSource()
.setIncludeVariables(true)
)
);
// Create buttons that call functions to modify the card.
const buttonSet = CardService.newButtonSet()
.setId("card_modification_buttons")
.addButton(
CardService.newTextButton()
.setAltText("Insert Card Section")
.setText("Insert Card Section")
.setOnClickAction(
CardService.newAction()
.setFunctionName('insertSection')
)
)
.addButton(
CardService.newTextButton()
.setAltText("Insert Text Widget")
.setText("Insert Text Widget")
.setOnClickAction(
CardService.newAction()
.setFunctionName('insertWidget')
)
);
var firstSection =
CardService.newCardSection()
.setId("card_section_1")
.addWidget(textInput_1)
.addWidget(textInput_2)
.addWidget(buttonSet);
var card = CardService.newCardBuilder()
.addSection(firstSection)
.build();
var navigation = AddOnsResponseService.newNavigation()
.pushCard(card);
var action = AddOnsResponseService.newAction()
.addNavigation(navigation);
return AddOnsResponseService.newRenderActionBuilder()
.setAction(action)
.build();
}
// If the step runs, return output variables.
function onExecute(event) {
var value1 = event.workflow.actionInvocation.inputs["value1"].stringValues[0];
var value2 = event.workflow.actionInvocation.inputs["value2"].stringValues[0];
var value3; // Declare value3
var result;
// Check if the "value3" key exists in the inputs, which only exists if
// the third text input is inserted to the Card.
if (event.workflow.actionInvocation.inputs["value3"]) {
value3 = event.workflow.actionInvocation.inputs["value3"].stringValues[0];
result = value1 + "\n" + value2 + "\n" + value3;
} else {
result = value1 + "\n" + value2;
}
// Output the file ID through a variableData, which can be used by
// later steps in a workflow.
const variableData = AddOnsResponseService.newVariableData()
.addStringValue(result);
let textFormatElement = AddOnsResponseService.newTextFormatElement()
.setText("Output: " + JSON.stringify(variableData));
let workflowTextFormat = AddOnsResponseService.newWorkflowTextFormat()
.addTextFormatElement(textFormatElement);
// The string key for each variableData must match with the IDs of the
// outputs defined in the manifest.
let returnAction = AddOnsResponseService.newReturnOutputVariablesAction()
.setVariables({ "result": variableData })
.setLog(workflowTextFormat);
let hostAppAction = AddOnsResponseService.newHostAppAction()
.setWorkflowAction(returnAction);
return AddOnsResponseService.newRenderActionBuilder()
.setHostAppAction(hostAppAction).build();
}
/**
* Inserts a new CardSection with several widgets.
*/
function insertSection(event) {
console.log("event: " + JSON.stringify(event, null, 3));
const optionalSection = CardService.newCardSection().setId("card_section_2")
.addWidget(
CardService.newTextParagraph().setText("This is a text paragraph inside the new card section")
)
.addWidget(
CardService.newButtonSet().addButton(
CardService.newTextButton().setText("Remove Card Section").setOnClickAction(CardService.newAction().setFunctionName("removeSection"))))
.addWidget(
CardService.newButtonSet().addButton(
CardService.newTextButton().setText("Replace Card Section").setOnClickAction(CardService.newAction().setFunctionName("replaceSection"))));
// Insert the new section beneath section "card_section_1".
// You can also insert at the top of a Card.
const sectionInsertion = AddOnsResponseService.newInsertSection().insertBelowSection("card_section_1").setSection(optionalSection);
const modifyAction = AddOnsResponseService.newAction()
.addModifyCard(AddOnsResponseService.newModifyCard().setInsertSection(sectionInsertion));
return AddOnsResponseService.newRenderActionBuilder().setAction(modifyAction).build();
}
/**
* Replaces an existing CardSection with a new CardSection with the same ID.
*/
function replaceSection(event) {
console.log("event: " + JSON.stringify(event, null, 3));
const replacementSection = CardService.newCardSection().setId("card_section_2")
.addWidget(
CardService.newTextParagraph().setText("Card Section replaced!")
)
.addWidget(
CardService.newButtonSet().addButton(
CardService.newTextButton().setText("Remove Card Section").setOnClickAction(CardService.newAction().setFunctionName("removeSection"))));
const modifyAction = AddOnsResponseService.newAction()
.addModifyCard(AddOnsResponseService.newModifyCard().setReplaceSection(replacementSection));
return AddOnsResponseService.newRenderActionBuilder().setAction(modifyAction).build();
}
/**
* Replaces an existing CardWidget with a new CardWidget with the same ID.
*/
function replaceWidget(event) {
console.log("event: " + JSON.stringify(event, null, 3));
const replacementWidget = CardService.newTextParagraph().setText("This is a replacement widget!").setId("text_input_3");
const modifyAction = AddOnsResponseService.newAction()
.addModifyCard(AddOnsResponseService.newModifyCard().setReplaceWidget(replacementWidget));
return AddOnsResponseService.newRenderActionBuilder().setAction(modifyAction).build();
}
/**
* Inserts an additional text input widget and a button that can remove it.
*/
function insertWidget(event) {
console.log("event: " + JSON.stringify(event, null, 3));
const buttonSet = CardService.newButtonSet().setId("widget_1")
.addButton(
CardService.newTextButton()
.setAltText("Remove Widget")
.setText("Remove Widget")
.setOnClickAction(
CardService.newAction().setFunctionName('removeWidget')
))
.addButton(
CardService.newTextButton()
.setAltText("Replace Widget")
.setText("Replace Widget")
.setOnClickAction(
CardService.newAction().setFunctionName('replaceWidget')
));
const textInput_3 = CardService.newTextInput().setFieldName("value3").setTitle("Third Value").setId("text_input_3");
// Widgets can be inserted either before or after another widget.
// This example inserts a button below a text input, then inserts
// another text input between the existing text input and the new button.
const buttonSetInsertion = AddOnsResponseService.newInsertWidget().insertBelowWidget("text_input_2").setWidget(buttonSet);
const textInputInsertion = AddOnsResponseService.newInsertWidget().insertAboveWidget("widget_1").setWidget(textInput_3);
const modifyAction = AddOnsResponseService.newAction()
.addModifyCard(AddOnsResponseService.newModifyCard().setInsertWidget(buttonSetInsertion))
.addModifyCard(AddOnsResponseService.newModifyCard().setInsertWidget(textInputInsertion));
return AddOnsResponseService.newRenderActionBuilder().setAction(modifyAction).build();
}
/**
* Removes one or more existing widgets by ID.
*/
function removeWidget(event) {
console.log("event: " + JSON.stringify(event, null, 3));
const textInputDeletion = AddOnsResponseService.newRemoveWidget().setWidgetId("text_input_3");
const buttonSetDeletion = AddOnsResponseService.newRemoveWidget().setWidgetId("widget_1");
const modifyAction = AddOnsResponseService.newAction()
.addModifyCard(
AddOnsResponseService.newModifyCard().setRemoveWidget(textInputDeletion)
)
.addModifyCard(
AddOnsResponseService.newModifyCard().setRemoveWidget(buttonSetDeletion)
);
return AddOnsResponseService.newRenderActionBuilder().setAction(modifyAction).build();
}
/**
* Removes an existing card section by ID.
*/
function removeSection(event) {
console.log("event: " + JSON.stringify(event, null, 3));
const sectionDeletion = AddOnsResponseService.newRemoveSection().setSectionId('card_section_2');
const modifyAction = AddOnsResponseService.newAction()
.addModifyCard(
AddOnsResponseService.newModifyCard().setRemoveSection(sectionDeletion)
);
return AddOnsResponseService.newRenderActionBuilder().setAction(modifyAction).build();
}