ইন্টারেক্টিভ কার্ড তৈরি করা
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
বেশিরভাগ অ্যাড-অন, ডেটা উপস্থাপনের পাশাপাশি, ব্যবহারকারীকে তথ্য প্রবেশ করতে হবে। আপনি যখন একটি কার্ড-ভিত্তিক অ্যাড-অন তৈরি করেন, তখন আপনি ইন্টারেক্টিভ উইজেটগুলি ব্যবহার করতে পারেন যেমন বোতাম, টুলবার মেনু আইটেম, বা চেকবক্সগুলি ব্যবহারকারীকে আপনার অ্যাড-অনের প্রয়োজন এমন ডেটার জন্য জিজ্ঞাসা করতে বা অন্যান্য ইন্টারঅ্যাকশন নিয়ন্ত্রণগুলি প্রদান করতে।
বেশিরভাগ অংশে, আপনি উইজেটগুলিকে নির্দিষ্ট কর্মের সাথে লিঙ্ক করে এবং একটি কলব্যাক ফাংশনে প্রয়োজনীয় আচরণ প্রয়োগ করে ইন্টারেক্টিভ করে তোলেন। বিস্তারিত জানার জন্য অ্যাড-অন অ্যাকশন দেখুন।
বেশিরভাগ ক্ষেত্রে, আপনি নির্বাচিত বা আপডেট করার সময় একটি নির্দিষ্ট পদক্ষেপ নিতে একটি উইজেট কনফিগার করতে এই সাধারণ পদ্ধতি অনুসরণ করতে পারেন:
- একটি
Action
অবজেক্ট তৈরি করুন, কলব্যাক ফাংশনটি নির্দিষ্ট করে যা কার্যকর করা উচিত, যেকোনো প্রয়োজনীয় পরামিতি সহ। - উপযুক্ত উইজেট হ্যান্ডলার ফাংশন কল করে
Action
সাথে উইজেট লিঙ্ক করুন। - প্রয়োজনীয় আচরণ কার্যকর করতে কলব্যাক ফাংশন প্রয়োগ করুন।
উদাহরণ
নিম্নলিখিত উদাহরণটি একটি বোতাম সেট করে যা ক্লিক করার পরে ব্যবহারকারীর বিজ্ঞপ্তি প্রদর্শন করে। ক্লিকটি notifyUser()
কলব্যাক ফাংশনটিকে একটি আর্গুমেন্ট সহ ট্রিগার করে যা বিজ্ঞপ্তির পাঠ্য নির্দিষ্ট করে। একটি নির্মিত ActionResponse
প্রত্যাবর্তন একটি প্রদর্শিত বিজ্ঞপ্তি ফলাফল.
/**
* Build a simple card with a button that sends a notification.
* @return {Card}
*/
function buildSimpleCard() {
var buttonAction = CardService.newAction()
.setFunctionName('notifyUser')
.setParameters({'notifyText': 'Button clicked!'});
var button = CardService.newTextButton()
.setText('Notify')
.setOnClickAction(buttonAction);
// ...continue creating widgets, then create a Card object
// to add them to. Return the built Card object.
}
/**
* Callback function for a button action. Constructs a
* notification action response and returns it.
* @param {Object} e the action event object
* @return {ActionResponse}
*/
function notifyUser(e) {
var parameters = e.parameters;
var notificationText = parameters['notifyText'];
return CardService.newActionResponseBuilder()
.setNotification(CardService.newNotification()
.setText(notificationText))
.build(); // Don't forget to build the response!
}
কার্যকর মিথস্ক্রিয়া ডিজাইন করুন
ইন্টারেক্টিভ কার্ড ডিজাইন করার সময়, নিম্নলিখিতগুলি মনে রাখবেন:
ইন্টারেক্টিভ উইজেটগুলির সাধারণত তাদের আচরণ সংজ্ঞায়িত করার জন্য কমপক্ষে একটি হ্যান্ডলার পদ্ধতির প্রয়োজন হয়।
আপনার কাছে URL থাকলে setOpenLink()
উইজেট হ্যান্ডলার ফাংশনটি ব্যবহার করুন এবং শুধুমাত্র একটি ট্যাবে এটি খুলতে চান। এটি একটি Action
অবজেক্ট এবং কলব্যাক ফাংশন সংজ্ঞায়িত করার প্রয়োজনীয়তা এড়ায়। আপনি যদি প্রথমে ইউআরএল তৈরি করতে চান, বা ইউআরএল খোলার আগে অন্য কোনো অতিরিক্ত পদক্ষেপ নিতে চান, তাহলে একটি Action
সংজ্ঞায়িত করুন এবং পরিবর্তে setOnClickOpenLinkAction()
ব্যবহার করুন।
setOpenLink()
বা setOnClickOpenLinkAction()
উইজেট হ্যান্ডলার ফাংশন ব্যবহার করার সময়, কোন URL খুলতে হবে তা নির্ধারণ করতে আপনাকে একটি OpenLink
অবজেক্ট প্রদান করতে হবে। আপনি OpenAs
এবং OnClose
enums ব্যবহার করে খোলার এবং বন্ধ করার আচরণ নির্দিষ্ট করতে এই বস্তুটি ব্যবহার করতে পারেন।
একাধিক উইজেটের জন্য একই Action
অবজেক্ট ব্যবহার করা সম্ভব। যাইহোক, যদি আপনি কলব্যাক ফাংশন বিভিন্ন পরামিতি প্রদান করতে চান তবে আপনাকে বিভিন্ন Action
অবজেক্টকে সংজ্ঞায়িত করতে হবে।
আপনার কলব্যাক ফাংশন সহজ রাখুন. অ্যাড-অনগুলিকে প্রতিক্রিয়াশীল রাখতে, কার্ড পরিষেবা কলব্যাক ফাংশনগুলিকে কার্যকর করার সময় সর্বাধিক 30 সেকেন্ডের মধ্যে সীমাবদ্ধ করে। যদি এক্সিকিউশন এর চেয়ে বেশি সময় নেয়, তাহলে আপনার অ্যাড-অন UI Action
প্রতিক্রিয়ায় তার কার্ড ডিসপ্লে সঠিকভাবে আপডেট নাও করতে পারে।
যদি আপনার অ্যাড-অন UI-এর সাথে ব্যবহারকারীর ইন্টারঅ্যাকশনের ফলে তৃতীয়-পক্ষের ব্যাকএন্ডে একটি ডেটা স্থিতি পরিবর্তিত হয়, তাহলে এটি সুপারিশ করা হয় যে অ্যাড-অন একটি 'স্টেট পরিবর্তিত' বিটকে true
সেট করুন যাতে বিদ্যমান ক্লায়েন্ট সাইড ক্যাশে সাফ অতিরিক্ত বিবরণের জন্য ActionResponseBuilder.setStateChanged()
পদ্ধতির বিবরণ দেখুন।
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2024-12-22 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2024-12-22 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eCard-based add-ons use interactive widgets like buttons and menus to collect user input and enhance user interactions.\u003c/p\u003e\n"],["\u003cp\u003eWidgets are made interactive by linking them to actions, which trigger callback functions to execute specific behaviors when interacted with.\u003c/p\u003e\n"],["\u003cp\u003eWhen defining widget actions, you can specify a callback function and any necessary parameters using the \u003ccode\u003eAction\u003c/code\u003e object and appropriate handler functions.\u003c/p\u003e\n"],["\u003cp\u003eFor opening URLs, \u003ccode\u003esetOpenLink()\u003c/code\u003e or \u003ccode\u003esetOnClickOpenLinkAction()\u003c/code\u003e can be used with an \u003ccode\u003eOpenLink\u003c/code\u003e object to define the URL and behavior.\u003c/p\u003e\n"],["\u003cp\u003eKeep callback functions concise, as they have execution time limits, and consider using \u003ccode\u003esetStateChanged()\u003c/code\u003e to update the UI when backend data changes due to user interactions.\u003c/p\u003e\n"]]],["Card-based add-ons use interactive widgets like buttons to gather user input or provide controls. Widgets are made interactive by linking them to actions via a callback function. To configure a widget, create an `Action` object with the callback function and parameters, link it using a widget handler function, and implement the callback function. For opening URLs directly, `setOpenLink()` avoids defining an `Action`. Ensure callbacks are simple (under 30 seconds), and for backend data changes, use `setStateChanged()`.\n"],null,["# Building interactive cards\n\nMost add-ons, in addition to presenting data, require the user to enter\ninformation. When you build a card-based add-on, you can use\ninteractive [widgets](/workspace/add-ons/concepts/widgets) such as buttons,\ntoolbar menu items, or checkboxes to ask the user for data that your add-on\nneeds or provide other interaction controls.\n\nAdding actions to widgets\n-------------------------\n\nFor the most part, you make widgets interactive by linking them to\nspecific *actions* and implementing the required behavior in a callback\nfunction. See [add-on actions](/workspace/add-ons/concepts/actions) for details.\n\nIn most cases, you can follow this general procedure to configure a widget to\ntake a specific action when selected or updated:\n\n1. Create an [`Action`](/apps-script/reference/card-service/action) object, specifing the callback function that should execute, along with any required parameters.\n2. Link the widget to the `Action` by calling the appropriate [widget handler function](/workspace/add-ons/concepts/actions#widget_handler_functions).\n3. Implement the [callback function](/workspace/add-ons/concepts/actions#callback_functions) to enact the required behavior.\n\nExample\n-------\n\nThe following example sets a button that displays a user notification\nafter it is clicked. The click triggers the `notifyUser()` callback function\nwith an argument that specifies the notification text. Returning a built\n[`ActionResponse`](/apps-script/reference/card-service/action-response)\nresults in a displayed notification. \n\n /**\n * Build a simple card with a button that sends a notification.\n * @return {Card}\n */\n function buildSimpleCard() {\n var buttonAction = CardService.newAction()\n .setFunctionName('notifyUser')\n .setParameters({'notifyText': 'Button clicked!'});\n var button = CardService.newTextButton()\n .setText('Notify')\n .setOnClickAction(buttonAction);\n\n // ...continue creating widgets, then create a Card object\n // to add them to. Return the built Card object.\n }\n\n /**\n * Callback function for a button action. Constructs a\n * notification action response and returns it.\n * @param {Object} e the action event object\n * @return {ActionResponse}\n */\n function notifyUser(e) {\n var parameters = e.parameters;\n var notificationText = parameters['notifyText'];\n return CardService.newActionResponseBuilder()\n .setNotification(CardService.newNotification()\n .setText(notificationText))\n .build(); // Don't forget to build the response!\n }\n\nDesign effective interactions\n-----------------------------\n\nWhen designing interactive cards, keep the following in mind:\n\n- Interactive widgets usually need at least one handler method to define their\n behavior.\n\n- Use the [`setOpenLink()`](/workspace/add-ons/concepts/actions#setOpenLink) widget\n handler function when you have a URL and just want to open it in a tab.\n This avoids the need to define an\n [`Action`](/apps-script/reference/card-service/action) object and callback\n function. If you need to build the URL first, or take any other additional\n steps before opening the URL, define an\n [`Action`](/apps-script/reference/card-service/action) and use\n [`setOnClickOpenLinkAction()`](/workspace/add-ons/concepts/actions#setOnClickOpenLinkAction)\n instead.\n\n- When using the [`setOpenLink()`](/workspace/add-ons/concepts/actions#setOpenLink)\n or [`setOnClickOpenLinkAction()`](/workspace/add-ons/concepts/actions#setOnClickOpenLinkAction)\n widget handler functions, you need to provide an\n [`OpenLink`](/apps-script/reference/card-service/open-link)\n object to define which URL to open. You can also use this object\n to specify opening and closing behavior using the\n [`OpenAs`](/apps-script/reference/card-service/open-as) and\n [`OnClose`](/apps-script/reference/card-service/on-close) enums.\n\n- It is possible for more than one widget to use the same\n [`Action`](/apps-script/reference/card-service/action) object.\n However, you need to define different\n [`Action`](/apps-script/reference/card-service/action) objects if you want\n to provide the callback function different parameters.\n\n- Keep your callback functions simple. To keep the add-ons responsive, the\n [Card service](/apps-script/reference/card-service/card-service) limits callback functions to a maximum of 30 seconds of\n execution time. If the execution takes longer than that, your add-on UI may\n not update its card display properly in response to the\n [`Action`](/apps-script/reference/card-service/action) .\n\n- If a data status on a third-party backend changes as the result of a user\n interaction with your add-on UI, it is recommended that the add-on set\n a 'state changed' bit to `true` so that any existing client side cache is\n cleared. See the\n [`ActionResponseBuilder.setStateChanged()`](/apps-script/reference/card-service/action-response-builder#setStateChanged(Boolean))\n method description for additional details."]]