সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
অ্যাডভান্সড চ্যাট পরিষেবা আপনাকে অ্যাপস স্ক্রিপ্টে Google Chat API ব্যবহার করতে দেয়। এই API স্ক্রিপ্টগুলিকে চ্যাট স্পেসগুলি খুঁজে বের করতে, তৈরি করতে এবং সংশোধন করতে, স্পেসগুলিতে সদস্যদের যোগ বা সরাতে এবং পাঠ্য, কার্ড, সংযুক্তি এবং প্রতিক্রিয়া সহ বার্তাগুলি পড়তে বা পোস্ট করতে দেয়৷
পূর্বশর্ত
Google ক্লাউড কনসোলে চ্যাট API কনফিগারেশন পৃষ্ঠায় কনফিগার করা একটি Apps Script Google Chat অ্যাপ। অ্যাপের অ্যাপস স্ক্রিপ্ট প্রোজেক্টকে অ্যাপস স্ক্রিপ্ট প্রোজেক্টের জন্য স্বয়ংক্রিয়ভাবে তৈরি ডিফল্টের পরিবর্তে একটি স্ট্যান্ডার্ড Google ক্লাউড প্রজেক্ট ব্যবহার করতে হবে। একটি সামঞ্জস্যপূর্ণ Google Chat অ্যাপ তৈরি করতে, Google Apps Script দিয়ে একটি Google Chat অ্যাপ তৈরি করুন দেখুন।
এই পরিষেবা সম্পর্কে আরও তথ্যের জন্য, চ্যাট API রেফারেন্স ডকুমেন্টেশন দেখুন। অ্যাপস স্ক্রিপ্টের সমস্ত উন্নত পরিষেবাগুলির মতো, চ্যাট পরিষেবাটি পাবলিক API হিসাবে একই বস্তু, পদ্ধতি এবং পরামিতিগুলি ব্যবহার করে৷
নমুনা কোড
এই নমুনাগুলি আপনাকে দেখায় কিভাবে উন্নত পরিষেবা ব্যবহার করে সাধারণ Google Chat API অ্যাকশনগুলি সম্পাদন করতে হয়।
ব্যবহারকারীর শংসাপত্র সহ একটি বার্তা পোস্ট করুন
নিম্নলিখিত উদাহরণটি প্রদর্শন করে যে কীভাবে ব্যবহারকারীর পক্ষে একটি চ্যাট স্পেসে একটি বার্তা পোস্ট করতে হয়।
Apps Script প্রকল্পের appsscript.json ফাইলে chat.messages.create অনুমোদনের সুযোগ যোগ করুন:
/** * Posts a new message to the specified space on behalf of the user. * @param {string} spaceName The resource name of the space. */functionpostMessageWithUserCredentials(spaceName){try{constmessage={'text':'Hello world!'};Chat.Spaces.Messages.create(message,spaceName);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed to create message with error %s',err.message);}}
অ্যাপের শংসাপত্র সহ একটি বার্তা পোস্ট করুন
নিম্নলিখিত উদাহরণটি দেখায় যে কীভাবে অ্যাপের হয়ে চ্যাট স্পেসে একটি বার্তা পোস্ট করতে হয়। একটি পরিষেবা অ্যাকাউন্টের সাথে উন্নত চ্যাট পরিষেবা ব্যবহার করার জন্য আপনাকে appsscript.json এ অনুমোদনের সুযোগ নির্দিষ্ট করতে হবে না। পরিষেবা অ্যাকাউন্টগুলির সাথে প্রমাণীকরণ সম্পর্কে বিশদ বিবরণের জন্য, একটি Google চ্যাট অ্যাপ হিসাবে প্রমাণীকরণ দেখুন৷
/** * Posts a new message to the specified space on behalf of the app. * @param {string} spaceName The resource name of the space. */functionpostMessageWithAppCredentials(spaceName){try{// See https://developers.google.com/chat/api/guides/auth/service-accounts// for details on how to obtain a service account OAuth token.constappToken=getToken_();constmessage={'text':'Hello world!'};Chat.Spaces.Messages.create(message,spaceName,{},// Authenticate with the service account token.{'Authorization':'Bearer '+appToken});}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed to create message with error %s',err.message);}}
একটি স্থান পান
নিচের উদাহরণটি দেখায় কিভাবে একটি চ্যাট স্পেস সম্পর্কে তথ্য পেতে হয়।
Apps Script প্রকল্পের appsscript.json ফাইলে chat.spaces.readonly অনুমোদনের সুযোগ যোগ করুন:
/** * Gets information about a Chat space. * @param {string} spaceName The resource name of the space. */functiongetSpace(spaceName){try{constspace=Chat.Spaces.get(spaceName);console.log('Space display name: %s',space.displayName);console.log('Space type: %s',space.spaceType);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed to get space with error %s',err.message);}}
একটি স্থান তৈরি করুন
নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি চ্যাট স্পেস তৈরি করতে হয়।
Apps Script প্রকল্পের appsscript.json ফাইলে chat.spaces.create অনুমোদনের সুযোগ যোগ করুন:
/** * Creates a new Chat space. */functioncreateSpace(){try{constspace={'displayName':'New Space','spaceType':'SPACE'};Chat.Spaces.create(space);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed to create space with error %s',err.message);}}
সদস্যপদ তালিকা
নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি চ্যাট স্পেসের সমস্ত সদস্যকে তালিকাভুক্ত করতে হয়।
Apps Script প্রকল্পের appsscript.json ফাইলে chat.memberships.readonly অনুমোদনের সুযোগ যোগ করুন:
/** * Lists all the members of a Chat space. * @param {string} spaceName The resource name of the space. */functionlistMemberships(spaceName){letresponse;letpageToken=null;try{do{response=Chat.Spaces.Members.list(spaceName,{pageSize:10,pageToken:pageToken});if(!response.memberships||response.memberships.length===0){pageToken=response.nextPageToken;continue;}response.memberships.forEach((membership)=>console.log('Member resource name: %s (type: %s)',membership.name,membership.member.type));pageToken=response.nextPageToken;}while(pageToken);}catch(err){// TODO (developer) - Handle exceptionconsole.log('Failed with error %s',err.message);}}
সমস্যা সমাধান
আপনি যদি Error 400: invalid_scope ত্রুটি বার্তার সম্মুখীন হন Some requested scopes cannot be shown , এর মানে আপনি Apps Script প্রকল্পের appsscript.json ফাইলে কোনো অনুমোদনের সুযোগ নির্দিষ্ট করেননি। বেশিরভাগ ক্ষেত্রে, অ্যাপস স্ক্রিপ্ট স্বয়ংক্রিয়ভাবে নির্ধারণ করে যে কোন স্ক্রিপ্টের কোন স্কোপের প্রয়োজন, কিন্তু আপনি যখন চ্যাট উন্নত পরিষেবা ব্যবহার করেন, তখন আপনাকে অবশ্যই ম্যানুয়ালি অনুমোদনের সুযোগ যোগ করতে হবে যা আপনার স্ক্রিপ্ট আপনার অ্যাপস স্ক্রিপ্ট প্রকল্পের ম্যানিফেস্ট ফাইলে ব্যবহার করে। সুস্পষ্ট স্কোপ সেট করা দেখুন।
ত্রুটিটি সমাধান করতে, oauthScopes অ্যারের অংশ হিসাবে Apps Script প্রকল্পের appsscript.json ফাইলে যথাযথ অনুমোদনের সুযোগ যোগ করুন। উদাহরণস্বরূপ, spaces.messages.create পদ্ধতিতে কল করতে, নিম্নলিখিত যোগ করুন:
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-08-04 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eThe Advanced Chat service enables Apps Script to interact with the Google Chat API, allowing scripts to manage spaces, members, and messages.\u003c/p\u003e\n"],["\u003cp\u003eUtilizing this service requires setting up a Google Chat app in the Google Cloud console and configuring proper authentication (user or app).\u003c/p\u003e\n"],["\u003cp\u003eSample code snippets demonstrate common actions like posting messages and managing spaces using user or app credentials.\u003c/p\u003e\n"],["\u003cp\u003eThe service mirrors the Chat API's objects and methods but has limitations, such as not supporting media downloads or Developer Preview methods.\u003c/p\u003e\n"],["\u003cp\u003eTroubleshooting steps and workarounds are provided for potential issues like scope errors.\u003c/p\u003e\n"]]],[],null,["# Advanced Chat Service\n\nThe Advanced Chat service lets you use the\n[Google Chat API](/chat/api/guides) in\nApps Script. This API allows scripts to find, create, and modify\nChat spaces, add or remove members to spaces, and read or post\nmessages with text, cards, attachments, and reactions.\n\nPrerequisites\n-------------\n\n- An Apps Script Google Chat app configured on the Chat API configuration page in the Google Cloud console. The app's Apps Script project must use a standard Google Cloud project instead of the default one created automatically for Apps Script projects. To create a compatible Google Chat app, see [Build a Google Chat app with Google Apps Script](/workspace/add-ons/chat/quickstart-apps-script).\n- Authentication configured for the Chat app. Performing an action on behalf of a user requires [user authentication](/chat/api/guides/auth/users). Performing an action as the Chat app requires [app authentication with a service account](/chat/api/guides/auth/service-accounts). To check which form of authentication a Chat API method supports, see [Types of required authentication for Google Chat API calls](/chat/api/guides/auth#asynchronous-chat-calls).\n\n| **Note:** This is an advanced service that you must [turn on before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor more information about this service, see the\n[Chat API reference documentation](/chat/api/reference/rest).\nLike all advanced services in Apps Script, the\nChat service uses the same objects, methods, and parameters as\nthe public API.\n\nSample code\n-----------\n\nThese samples show you how to perform common\n[Google Chat API](/chat/api/guides)\nactions using the advanced service.\n\n### Post a message with user credentials\n\nThe following example demonstrates how to post a message to a\nChat space on behalf of the user.\n\n1. Add the `chat.messages.create` authorization scope to the\n Apps Script project's `appsscript.json` file:\n\n \"oauthScopes\": [\n \"https://www.googleapis.com/auth/chat.messages.create\"\n ]\n\n2. Add a function like this one to the Apps Script project's\n code:\n\n advanced/chat.gs \n [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/chat.gs) \n\n ```javascript\n /**\n * Posts a new message to the specified space on behalf of the user.\n * @param {string} spaceName The resource name of the space.\n */\n function postMessageWithUserCredentials(spaceName) {\n try {\n const message = {'text': 'Hello world!'};\n Chat.Spaces.Messages.create(message, spaceName);\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed to create message with error %s', err.message);\n }\n }\n ```\n\n### Post a message with app credentials\n\nThe following example demonstrates how to post a message to a\nChat space on behalf of the app. Using the advanced\nChat service with a service account doesn't require you to\nspecify authorization scopes in `appsscript.json`. For details about\nauthentication with service accounts, see\n[Authenticate as a Google Chat app](/chat/api/guides/auth/service-accounts). \nadvanced/chat.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/chat.gs) \n\n```javascript\n/**\n * Posts a new message to the specified space on behalf of the app.\n * @param {string} spaceName The resource name of the space.\n */\nfunction postMessageWithAppCredentials(spaceName) {\n try {\n // See https://developers.google.com/chat/api/guides/auth/service-accounts\n // for details on how to obtain a service account OAuth token.\n const appToken = getToken_();\n const message = {'text': 'Hello world!'};\n Chat.Spaces.Messages.create(\n message,\n spaceName,\n {},\n // Authenticate with the service account token.\n {'Authorization': 'Bearer ' + appToken});\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed to create message with error %s', err.message);\n }\n}\n```\n\n### Get a space\n\nThe following example demonstrates how to get information about a\nChat space.\n\n1. Add the `chat.spaces.readonly` authorization scope to the\n Apps Script project's `appsscript.json` file:\n\n \"oauthScopes\": [\n \"https://www.googleapis.com/auth/chat.spaces.readonly\"\n ]\n\n2. Add a function like this one to the Apps Script project's\n code:\n\n advanced/chat.gs \n [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/chat.gs) \n\n ```javascript\n /**\n * Gets information about a Chat space.\n * @param {string} spaceName The resource name of the space.\n */\n function getSpace(spaceName) {\n try {\n const space = Chat.Spaces.get(spaceName);\n console.log('Space display name: %s', space.displayName);\n console.log('Space type: %s', space.spaceType);\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed to get space with error %s', err.message);\n }\n }\n ```\n\n### Create a space\n\nThe following example demonstrates how to create a Chat space.\n\n1. Add the `chat.spaces.create` authorization scope to the\n Apps Script project's `appsscript.json` file:\n\n \"oauthScopes\": [\n \"https://www.googleapis.com/auth/chat.spaces.create\"\n ]\n\n2. Add a function like this one to the Apps Script project's\n code:\n\n advanced/chat.gs \n [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/chat.gs) \n\n ```javascript\n /**\n * Creates a new Chat space.\n */\n function createSpace() {\n try {\n const space = {'displayName': 'New Space', 'spaceType': 'SPACE'};\n Chat.Spaces.create(space);\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed to create space with error %s', err.message);\n }\n }\n ```\n\n### List memberships\n\nThe following example demonstrates how to list all the members of a\nChat space.\n\n1. Add the `chat.memberships.readonly` authorization scope to the\n Apps Script project's `appsscript.json` file:\n\n \"oauthScopes\": [\n \"https://www.googleapis.com/auth/chat.memberships.readonly\"\n ]\n\n2. Add a function like this one to the Apps Script project's\n code:\n\n advanced/chat.gs \n [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/chat.gs) \n\n ```javascript\n /**\n * Lists all the members of a Chat space.\n * @param {string} spaceName The resource name of the space.\n */\n function listMemberships(spaceName) {\n let response;\n let pageToken = null;\n try {\n do {\n response = Chat.Spaces.Members.list(spaceName, {\n pageSize: 10,\n pageToken: pageToken\n });\n if (!response.memberships || response.memberships.length === 0) {\n pageToken = response.nextPageToken;\n continue;\n }\n response.memberships.forEach((membership) =\u003e console.log(\n 'Member resource name: %s (type: %s)',\n membership.name,\n membership.member.type));\n pageToken = response.nextPageToken;\n } while (pageToken);\n } catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n }\n }\n ```\n\nTroubleshoot\n------------\n\nIf you encounter `Error 400: invalid_scope` with the error message\n`Some requested scopes cannot be shown`,\nit means you haven't specified any authorization scopes in the\nApps Script project's `appsscript.json` file. In most cases,\nApps Script automatically determines what scopes a script needs,\nbut when you use the Chat advanced service, you must manually add\nthe authorization scopes that your script uses to your\nApps Script project's manifest file. See\n[Setting explicit scopes](/apps-script/concepts/scopes#setting_explicit_scopes).\n\nTo resolve the error, add the appropriate authorization scopes\nto the Apps Script project's `appsscript.json` file as part of\nthe `oauthScopes` array. For example, to call the\n[`spaces.messages.create`](/chat/api/reference/rest/v1/spaces.messages/create)\nmethod, add the following: \n\n \"oauthScopes\": [\n \"https://www.googleapis.com/auth/chat.messages.create\"\n ]\n\nLimits and considerations\n-------------------------\n\nThe Advanced Chat service doesn't support:\n\n- The Chat API method [`media.download`](/chat/api/reference/rest/v1/media/download).\n- Chat API methods available in [Developer Preview](/workspace/preview)\n\nTo download a message attachment or call a developer preview method, use\n[`UrlFetchApp`](/apps-script/reference/url-fetch/url-fetch-app) instead."]]