Google Chat অ্যাপ কমান্ডের উত্তর দেওয়া

Google Chat অ্যাপ হিসেবে কীভাবে কমান্ড সেট-আপ করতে ও উত্তর দিতে হয় তা এই পৃষ্ঠায় ব্যাখ্যা করা হয়েছে।

কমান্ড ব্যবহারকারীদের Chat অ্যাপের মূল ফিচারগুলি খুঁজে পেতে এবং ব্যবহার করতে সাহায্য করে। শুধুমাত্র Chat অ্যাপই কমান্ডের কন্টেন্ট দেখতে পারে। যেমন, কোনও ব্যবহারকারী স্ল্যাশ কমান্ড সহ মেসেজ পাঠালে, মেসেজটি শুধু ব্যবহারকারী এবং Chat অ্যাপ দেখতে পাবে।

আপনি কমান্ড তৈরি করবেন কিনা তা স্থির করতে এবং ব্যবহারকারীর ইন্টার‍্যাকশন কীভাবে ডিজাইন করবেন তা বুঝতে, ব্যবহারকারীর সব অভিজ্ঞতা সংজ্ঞায়িত করুন দেখুন।

Chat অ্যাপ কমান্ডের ধরন

আপনি Chat অ্যাপ কমান্ডকে স্ল্যাশ কমান্ড, দ্রুত কমান্ড বা মেসেজ অ্যাকশন হিসেবে তৈরি করতে পারেন। প্রতিটি ধরনের কমান্ড ব্যবহার করতে, ব্যবহারকারীরা নিম্নলিখিত কাজ করতে পারেন:
  1. স্ল্যাশ কমান্ড: ব্যবহারকারীরা মেনু থেকে স্ল্যাশ কমান্ড বেছে নিতে পারেন অথবা স্ল্যাশ (/) এবং তারপরে পূর্বনির্ধারিত টেক্সট টাইপ করতে পারেন, যেমন /about। চ্যাট অ্যাপে সাধারণত স্ল্যাশ কমান্ডের জন্য আর্গুমেন্ট টেক্সট প্রয়োজন হয়।

    আপনার Chat অ্যাপের জন্য ব্যবহারকারীর থেকে অতিরিক্ত ইনপুটের প্রয়োজন হলে, স্ল্যাশ কমান্ড তৈরি করুন। যেমন, আপনি /search নামের একটি স্ল্যাশ কমান্ড তৈরি করতে পারেন যা ব্যবহারকারী সার্চ করার জন্য কোনও শব্দগুচ্ছ লেখার পরে রান করে, যেমন /search receipts।

  2. কুইক কমান্ড: ব্যবহারকারীরা Chat মেসেজের উত্তর দেওয়ার জায়গা থেকে মেনু খুলে কমান্ড ব্যবহার করেন। কোনও কমান্ড ব্যবহার করতে, তারা যোগ করুন বিকল্পে ক্লিক করেন এবং মেনু থেকে একটি কমান্ড বেছে নেন।

    আপনার Chat অ্যাপ অতিরিক্ত ইনপুটের জন্য অপেক্ষা না করে ব্যবহারকারীকে অবিলম্বে উত্তর দিতে পারলে, একটি দ্রুত কমান্ড তৈরি করুন। যেমন, আপনি র‍্যান্ডম ছবি নামে একটি দ্রুত কমান্ড তৈরি করতে পারেন যা অবিলম্বে একটি ছবি দিয়ে উত্তর দেয়।

  3. মেসেজ অ্যাকশন: ব্যবহারকারীরা কোনও মেসেজের উপর মাউস নিয়ে গিয়ে এবং তিন-ডট মেনুতে ক্লিক করে মেসেজ অ্যাকশন ব্যবহার করেন। কোনও কমান্ড ব্যবহার করতে, তারা তিন-ডট মেনু খুলে মেনু থেকে একটি কমান্ড বেছে নেন।

    আপনার Chat অ্যাপ যদি কোনও মেসেজের প্রসঙ্গের উপর ভিত্তি করে অ্যাকশন পারফর্ম করতে পারে, তাহলে একটি মেসেজ অ্যাকশন তৈরি করুন।

নিম্নলিখিত ছবিগুলি দেখায় যে কীভাবে ব্যবহারকারীরা স্ল্যাশ এবং দ্রুত কমান্ড এবং মেসেজ অ্যাকশনের জন্য মেনু খুঁজে পান:

পূর্বশর্ত

HTTP

একটি Google Chat অ্যাপ যা ব্যবহারকারীর ইন্টার‍্যাকশন গ্রহণ করে এবং তার উত্তর দেয়। একটি তৈরি করতে, HTTP ক্যুইকস্টার্ট সম্পূর্ণ করুন।

Apps Script

একটি Google Chat অ্যাপ যা ব্যবহারকারীর ইন্টার‍্যাকশন গ্রহণ করে এবং তার উত্তর দেয়। একটি তৈরি করতে, Apps Script ক্যুইকস্টার্ট সম্পূর্ণ করুন।

কমান্ড সেট-আপ করুন

এই বিভাগে ব্যাখ্যা করা হয়েছে যে কীভাবে নিম্নলিখিত ধাপগুলি সম্পূর্ণ করে একটি কমান্ড সেট-আপ করতে হয়:

  1. কমান্ডের জন্য নাম ও বিবরণ তৈরি করুন।
  2. Google Cloud কনসোলে কমান্ড কনফিগার করুন।
  3. ঐচ্ছিক: স্টার্টার প্রম্পটে কমান্ড ম্যাপ করুন।

কমান্ডের নাম ও বিবরণ লিখুন

Chat অ্যাপ চালু করার জন্য ব্যবহারকারী যে নাম টাইপ বা বেছে নেন, সেটিই হল কমান্ডের নাম। কমান্ড কীভাবে ব্যবহার করতে হবে সেই বিষয়ে ব্যবহারকারীকে আরও প্রম্পট করতে, নামের নিচে একটি সংক্ষিপ্ত বিবরণও দেখানো হয়:

স্ল্যাশ কমান্ডের নাম ও বিবরণ
স্ল্যাশ কমান্ডের নাম ও বিবরণ।

আপনার কমান্ডের জন্য নাম ও বিবরণ বেছে নেওয়ার সময়, নিম্নলিখিত সাজেশনগুলি বিবেচনা করুন:

কমান্ডের নাম দিতে:

  • ব্যবহারকারীর কাছে কমান্ড স্পষ্ট করতে ছোট, বর্ণনামূলক এবং অ্যাকশনেবল শব্দ বা বাক্যাংশ ব্যবহার করুন। যেমন, Create a reminder নামের পরিবর্তে, Remind me ব্যবহার করুন।
  • আপনার কমান্ডের জন্য একটি অনন্য বা সাধারণ নাম ব্যবহার করার কথা বিবেচনা করুন। আপনার কমান্ড যদি কোনও সাধারণ ইন্টার‍্যাকশন বা ফিচারের বর্ণনা দেয়, তাহলে আপনি এমন কোনও সাধারণ নাম ব্যবহার করতে পারেন যা ব্যবহারকারীরা চেনেন এবং আশা করেন, যেমন Settings বা Feedback। অন্যথায়, অনন্য কমান্ডের নাম ব্যবহার করার চেষ্টা করুন, কারণ আপনার কমান্ডের নাম অন্য Chat অ্যাপের মতো হলে, ব্যবহারকারীকে আপনার কমান্ড খুঁজে পেতে এবং ব্যবহার করতে একই ধরনের কমান্ডের মাধ্যমে ফিল্টার করতে হবে।

কোনও কমান্ডের বিবরণ দিতে:

  • বিবরণটি ছোট এবং স্পষ্ট রাখুন যাতে ব্যবহারকারীরা কমান্ড ব্যবহার করার সময় কী আশা করতে হবে তা জানতে পারেন।
  • কমান্ডের জন্য কোনও ফর্ম্যাটিং সংক্রান্ত প্রয়োজনীয়তা থাকলে ব্যবহারকারীদের তা জানান। যেমন, আপনি যদি এমন স্ল্যাশ কমান্ড তৈরি করেন যার জন্য আর্গুমেন্ট টেক্সট প্রয়োজন, তাহলে বিবরণটি Remind me to do [something] at [time]-এর মতো কিছুতে সেট করুন।
  • Chat অ্যাপ স্পেসের সবাইকে উত্তর দেয় নাকি যে ব্যবহারকারী কমান্ডটি চালু করেছেন তাকে ব্যক্তিগতভাবে উত্তর দেয় তা ব্যবহারকারীদের জানান। যেমন, কুইক কমান্ড About-এর জন্য, আপনি এটিকে Learn about this app (Only visible to you) হিসেবে বর্ণনা করতে পারেন।

Google Cloud কনসোলে কমান্ড কনফিগার করুন

স্ল্যাশ কমান্ড, কুইক কমান্ড বা মেসেজ অ্যাকশন তৈরি করতে, আপনি Google Chat API-এর জন্য আপনার Chat অ্যাপের কনফিগারেশনে কমান্ড বা অ্যাকশন সম্পর্কে তথ্য উল্লেখ করেন।

Google Chat API-তে কমান্ড কনফিগার করতে, নিম্নলিখিত ধাপগুলি সম্পূর্ণ করুন:

  1. Google Cloud কনসোলে, 'মেনু' > API ও পরিষেবা > চালু করা API ও পরিষেবা > Google Chat API বিকল্পে ক্লিক করুন

    Google Chat API পৃষ্ঠায় যান

  2. কনফিগারেশন বিকল্পে ক্লিক করুন।

  3. কানেকশন সেটিংস-এর অধীনে, ট্রিগার-এ যান এবং আপনার এন্ডপয়েন্টের বিবরণ নির্দিষ্ট করুন। কমান্ডের উত্তর দিতে আপনাকে নিম্নলিখিত বিভাগে এই ট্রিগার ব্যবহার করতে হবে।

    1. HTTP এন্ডপয়েন্ট URL: আপনি এখানে একটি সাধারণ HTTP এন্ডপয়েন্ট URL নির্দিষ্ট করতে পারেন। বিকল্প হিসেবে, বিভিন্ন ট্রিগারের জন্য বিভিন্ন HTTP এন্ডপয়েন্ট ব্যবহার করতে, সরাসরি অ্যাপ কমান্ড ফিল্ডে এন্ডপয়েন্ট উল্লেখ করুন।
    2. Apps Script: Apps Script ডিপ্লয়মেন্ট আইডি লিখুন। ডিফল্ট হিসেবে, onAppCommand ফাংশন চালু করা হবে। অন্য কোনও Apps Script ফাংশন ব্যবহার করতে, অ্যাপ কমান্ড ফিল্ডে কাস্টম ফাংশনের নাম উল্লেখ করুন।
  4. কমান্ড বিকল্পের মধ্যে, কমান্ড যোগ করুন বিকল্পে ক্লিক করুন।

  5. কমান্ড সম্পর্কে নিম্নলিখিত তথ্য লিখুন:

    1. কমান্ড আইডি: ১ থেকে ১০০০ পর্যন্ত একটি নম্বর যা আপনার Chat অ্যাপ কমান্ড শনাক্ত করতে এবং উত্তর দিতে ব্যবহার করে।
    2. বিবরণ: কমান্ড কীভাবে ব্যবহার ও ফর্ম্যাট করতে হবে তা বর্ণনা করে। বিবরণ সর্বাধিক ৫০ অক্ষরের হতে পারে।
    3. কমান্ডের ধরন: কুইক কমান্ড, স্ল্যাশ কমান্ড অথবা মেসেজ অ্যাকশন বিকল্পের মধ্যে থেকে যেকোনও একটি বেছে নিন।
    4. কমান্ডের জন্য একটি নাম উল্লেখ করুন:
      • কুইক কমান্ডের নাম: কমান্ড চালু করার জন্য ব্যবহারকারীরা মেনু থেকে যে ডিসপ্লে নাম বেছে নেন। সর্বাধিক ৫০টি অক্ষর থাকতে পারে এবং বিশেষ অক্ষর অন্তর্ভুক্ত থাকতে পারে। যেমন, Remind me
      • স্ল্যাশ কমান্ডের নাম: মেসেজে কমান্ড চালু করার জন্য ব্যবহারকারী যে টেক্সট টাইপ করেন। অবশ্যই স্ল্যাশ দিয়ে শুরু হতে হবে, শুধু টেক্সট থাকতে হবে এবং ৫০টি অক্ষর পর্যন্ত হতে পারে। যেমন, /remindMe
      • মেসেজ অ্যাকশনের নাম: মেসেজ অ্যাকশন চালু করার জন্য ব্যবহারকারীরা মেনু থেকে যে নাম বেছে নেন। সর্বাধিক ৫০টি অক্ষর থাকতে পারে এবং বিশেষ অক্ষর অন্তর্ভুক্ত করতে পারে। যেমন, Remind me
  6. ঐচ্ছিক: বিজ্ঞপ্তি মেসেজ লোড করা হচ্ছে: মেসেজ অ্যাকশন কার্যকর করার সময় ব্যবহারকারীকে দেখানোর জন্য একটি টোস্ট বিজ্ঞপ্তি মেসেজ। শুধুমাত্র মেসেজ অ্যাকশনের জন্য উপলভ্য যা ডায়ালগ খোলে না।

  7. ঐচ্ছিক: আপনি যদি চান যে আপনার Chat অ্যাপ কমান্ডের উত্তর ডায়ালগের মাধ্যমে দিক, তাহলে ডায়ালগ খুলুন চেকবক্স বেছে নিন।

  8. সেভ করুন বিকল্পে ক্লিক করুন।

কমান্ডটি এখন Chat অ্যাপের জন্য কনফিগার করা হয়েছে।

স্টার্টার প্রম্পটে কমান্ড ম্যাপ করুন

আপনি নিজের কমান্ডকে স্টার্টার প্রম্পট হিসেবে ফিচার করতে পারেন যাতে ব্যবহারকারীরা আপনার Chat অ্যাপের সাথে খালি ১:১ সরাসরি মেসেজ শুরু করার সময় সেগুলিকে ইন্টার‍্যাক্টিভ চিপ হিসেবে দেখতে পান।

স্টার্টার প্রম্পটে কমান্ড ম্যাপ করতে:

  1. আপনার কমান্ডে যেন অতিরিক্ত কাস্টম আর্গুমেন্টের প্রয়োজন না হয় (শুধুমাত্র কোনও আর্গুমেন্ট নেই বা প্রাথমিক আর্গুমেন্ট সহ কমান্ড স্টার্টার প্রম্পট হিসেবে কাজ করে)।
  2. Google Cloud কনসোলে, Chat API কনফিগারেশন পৃষ্ঠায় যান।
  3. ইন্টার‍্যাক্টিভ ফিচার > স্টার্টার প্রম্পট বিকল্পের অধীনে, প্রম্পট যোগ করুন বিকল্পে ক্লিক করুন।
  4. ডিসপ্লে অর্ডারের জন্য র‍্যাঙ্ক (১-৩) সেট করুন।
  5. ধরন বেছে নিন বিকল্পের মধ্যে, কমান্ড প্রম্পট বেছে নিন এবং ড্রপ-ডাউন থেকে আপনার কমান্ড বেছে নিন।
  6. হয়ে গেছে বিকল্পে ক্লিক করুন, তারপর সেভ করুন বিকল্পে ক্লিক করুন।

কমান্ডের উত্তর দিন

ব্যবহারকারী কোনও কমান্ড ব্যবহার করলে, আপনার Chat অ্যাপ একটি ইভেন্ট অবজেক্ট পায়। ইভেন্ট পেলোডে (event.chat.appCommandPayload) একটি appCommandPayload অবজেক্ট থাকে যাতে যে কমান্ডটি চালু করা হয়েছিল তার বিবরণ থাকে (কমান্ড আইডি এবং কমান্ডের ধরন সহ), যাতে আপনি একটি উপযুক্ত উত্তর দিতে পারেন। ইভেন্ট অবজেক্টটি HTTP এন্ডপয়েন্ট বা Apps Script ফাংশনে পাঠানো হয় যা আপনি অ্যাপ কমান্ড ট্রিগার কনফিগার করার সময় নির্দিষ্ট করেছিলেন।

Cymbal Labs Chat অ্যাপের জন্য
  ব্যক্তিগত মেসেজ। মেসেজে বলা হয়েছে যে
  Chat অ্যাপটি Cymbal Labs তৈরি করেছে এবং ডকুমেন্টেশনের লিঙ্ক
  ও সহায়তা টিমের সাথে যোগাযোগ করার লিঙ্ক শেয়ার করে।
সহায়তা কীভাবে পাওয়া যায় তা ব্যাখ্যা করতে স্ল্যাশ কমান্ড /help-এ Chat অ্যাপ ব্যক্তিগতভাবে উত্তর দেয়।

স্ল্যাশ কমান্ড বা কুইক কমান্ডের উত্তর দেওয়া

নিচের কোডটি একটি Chat অ্যাপের উদাহরণ দেখায় যা টেক্সট মেসেজ সহ স্ল্যাশ কমান্ড /about-এর উত্তর দেয়। স্ল্যাশ কমান্ড বা দ্রুত কমান্ডের উত্তর দিতে, Chat অ্যাপ অ্যাপ কমান্ড ট্রিগার থেকে ইভেন্ট অবজেক্ট (event.chat.appCommandPayload) ম্যানেজ করে। ইভেন্ট অবজেক্টের পেলোডে মিলে যাওয়া কমান্ড আইডি থাকলে, Chat অ্যাপ DataActions অ্যাকশনটি createMessageAction (hostAppDataAction.chatDataAction.createMessageAction) অবজেক্টের সাথে ফিরিয়ে দেয়:

Node.js

node/chat/avatar-app/index.js
// The ID of the slash command "/about".
// You must use the same ID in the Google Chat API configuration.
const ABOUT_COMMAND_ID = 1;

/**
 * Handle requests from Google Workspace add on
 *
 * @param {Object} req Request sent by Google Chat
 * @param {Object} res Response to be sent back to Google Chat
 */
http('avatarApp', (req, res) => {
  const chatEvent = req.body.chat;
  let message;
  if (chatEvent.appCommandPayload) {
    message = handleAppCommand(chatEvent);
  } else {
    message = handleMessage(chatEvent);
  }
  res.send({ hostAppDataAction: { chatDataAction: { createMessageAction: {
    message: message
  }}}});
});

/**
 * Responds to an APP_COMMAND event in Google Chat.
 *
 * @param {Object} event the event object from Google Chat
 * @return the response message object.
 */
function handleAppCommand(event) {
  switch (event.appCommandPayload.appCommandMetadata.appCommandId) {
    case ABOUT_COMMAND_ID:
      return {
        text: 'The Avatar app replies to Google Chat messages.'
      };
  }
}

Python

python/chat/avatar-app/main.py
# The ID of the slash command "/about".
# You must use the same ID in the Google Chat API configuration.
ABOUT_COMMAND_ID = 1

@functions_framework.http
def avatar_app(req: flask.Request) -> Mapping[str, Any]:
  """Handle requests from Google Workspace add on

  Args:
    flask.Request req: the request sent by Google Chat

  Returns:
    Mapping[str, Any]: the response to be sent back to Google Chat
  """
  chat_event = req.get_json(silent=True)["chat"]
  if chat_event and "appCommandPayload" in chat_event:
    message = handle_app_command(chat_event)
  else:
    message = handle_message(chat_event)
  return { "hostAppDataAction": { "chatDataAction": { "createMessageAction": {
      "message": message
  }}}}

def handle_app_command(event: Mapping[str, Any]) -> Mapping[str, Any]:
  """Responds to an APP_COMMAND event in Google Chat.

  Args:
    Mapping[str, Any] event: the event object from Google Chat

  Returns:
    Mapping[str, Any]: the response message object.
  """
  if event["appCommandPayload"]["appCommandMetadata"]["appCommandId"] == ABOUT_COMMAND_ID:
    return {
      "text": "The Avatar app replies to Google Chat messages.",
    }
  return {}

Java

java/chat/avatar-app/src/main/java/com/google/chat/avatar/App.java
// The ID of the slash command "/about".
// You must use the same ID in the Google Chat API configuration.
private static final int ABOUT_COMMAND_ID = 1;

private static final Gson gson = new Gson();

/**
 * Handle requests from Google Workspace add on
 * 
 * @param request the request sent by Google Chat
 * @param response the response to be sent back to Google Chat
 */
@Override
public void service(HttpRequest request, HttpResponse response) throws Exception {
  JsonObject event = gson.fromJson(request.getReader(), JsonObject.class);
  JsonObject chatEvent = event.getAsJsonObject("chat");
  Message message;
  if (chatEvent.has("appCommandPayload")) {
    message = handleAppCommand(chatEvent);
  } else {
    message = handleMessage(chatEvent);
  }
  JsonObject createMessageAction = new JsonObject();
  createMessageAction.add("message", gson.fromJson(gson.toJson(message), JsonObject.class));
  JsonObject chatDataAction = new JsonObject();
  chatDataAction.add("createMessageAction", createMessageAction);
  JsonObject hostAppDataAction = new JsonObject();
  hostAppDataAction.add("chatDataAction", chatDataAction);
  JsonObject dataActions = new JsonObject();
  dataActions.add("hostAppDataAction", hostAppDataAction);
  response.getWriter().write(gson.toJson(dataActions));
}

/**
 * Handles an APP_COMMAND event in Google Chat.
 *
 * @param event the event object from Google Chat
 * @return the response message object.
 */
private Message handleAppCommand(JsonObject event) throws Exception {
  switch (event.getAsJsonObject("appCommandPayload")
    .getAsJsonObject("appCommandMetadata").get("appCommandId").getAsInt()) {
    case ABOUT_COMMAND_ID:
      return new Message()
        .setText("The Avatar app replies to Google Chat messages.");
    default:
      return null;
  }
}

Apps Script

apps-script/chat/avatar-app/Code.gs
// The ID of the slash command "/about".
// You must use the same ID in the Google Chat API configuration.
const ABOUT_COMMAND_ID = 1;

/**
 * Responds to an APP_COMMAND event in Google Chat.
 *
 * @param {Object} event the event object from Google Chat
 */
function onAppCommand(event) {
  // Executes the app command logic based on ID.
  switch (event.chat.appCommandPayload.appCommandMetadata.appCommandId) {
    case ABOUT_COMMAND_ID:
      return { hostAppDataAction: { chatDataAction: { createMessageAction: { message: {
        text: 'The Avatar app replies to Google Chat messages.'
      }}}}};
  }
}

এই কোডের স্যাম্পেল ব্যবহার করতে, ABOUT_COMMAND_ID-এর জায়গায় সেই কমান্ড আইডি লিখুন যেটি আপনি Chat API-তে কমান্ড কনফিগার করার সময় উল্লেখ করেছিলেন।

মেসেজ অ্যাকশনে উত্তর দিন

নিচের কোডটি একটি Chat অ্যাপের উদাহরণ দেখায় যা টেক্সট মেসেজের মাধ্যমে মেসেজ অ্যাকশন আমাকে মনে করিয়ে দাও-এর উত্তর দেয়। মেসেজ অ্যাকশনে প্রতিক্রিয়া জানাতে, Chat অ্যাপ অ্যাপ কমান্ড ট্রিগার থেকে ইভেন্ট অবজেক্ট ম্যানেজ করে। কোনও ইভেন্ট অবজেক্টের পেলোডে মেসেজ অ্যাকশন কমান্ড আইডি থাকলে, Chat অ্যাপ createMessageAction অবজেক্ট সহ DataActions অ্যাকশন ফিরিয়ে দেয়:

Node.js

/**
 * Responds to an APP_COMMAND interaction event from Google Chat.
 *
 * @param {Object} event The interaction event from Google Chat.
 * @param {Object} res The HTTP response object.
 * @return {Object} The JSON response message with a confirmation.
 */
function onAppCommand(event, res) {
  // Collect the command ID and type from the event metadata.
  const {appCommandId, appCommandType} =
    event.chat.appCommandPayload.appCommandMetadata;

  if (appCommandType === 'MESSAGE_ACTION' &&
      appCommandId === REMIND_ME_COMMAND_ID) {

    // Message actions can access the context of the message they were
    // invoked on, such as the text or sender of that message.
    const messageText = event.chat.appCommandPayload.message.text;

    // Return a response that includes details from the original message.
    return res.json({
      "hostAppDataAction": {
        "chatDataAction": {
          "createMessageAction": {
            "message": {
              "text": `Setting a reminder for message: "${messageText}"`
            }
          }
        }
      }
    });
  }
}

Python

def on_app_command(event):
    """Responds to an APP_COMMAND interaction event from Google Chat.

    Args:
        event (dict): The interaction event from Google Chat.

    Returns:
        dict: The JSON response message with a confirmation.
    """
    # Collect the command ID and type from the event metadata.
    payload = event.get('chat', {}).get('appCommandPayload', {})
    metadata = payload.get('appCommandMetadata', {})
    if metadata.get('appCommandType') == 'MESSAGE_ACTION' and \
       metadata.get('appCommandId') == REMIND_ME_COMMAND_ID:

        # Message actions can access the context of the message they were
        # invoked on, such as the text or sender of that message.
        message_text = payload.get('message', {}).get('text')

        # Return a response that includes details from the original message.
        return {
            "hostAppDataAction": {
                "chatDataAction": {
                    "createMessageAction": {
                        "message": {
                            "text": f'Setting a reminder for message: "{message_text}"'
                        }
                    }
                }
            }
        }

Java

/**
 * Responds to an APP_COMMAND interaction event from Google Chat.
 *
 * @param event The interaction event from Google Chat.
 * @param response The HTTP response object.
 */
void onAppCommand(JsonObject event, HttpResponse response) throws Exception {
  // Collect the command ID and type from the event metadata.
  JsonObject payload = event.getAsJsonObject("chat").getAsJsonObject("appCommandPayload");
  JsonObject metadata = payload.getAsJsonObject("appCommandMetadata");
  String appCommandType = metadata.get("appCommandType").getAsString();

  if (appCommandType.equals("MESSAGE_ACTION")) {
    int commandId = metadata.get("appCommandId").getAsInt();
    if (commandId == REMIND_ME_COMMAND_ID) {
      // Message actions can access the context of the message they were
      // invoked on, such as the text or sender of that message.
      String messageText = payload.getAsJsonObject("message").get("text").getAsString();

      // Return a response that includes details from the original message.
      JsonObject responseMessage = new JsonObject();
      responseMessage.addProperty("text", "Setting a reminder for message: " + messageText);

      JsonObject createMessageAction = new JsonObject();
      createMessageAction.add("message", responseMessage);

      JsonObject chatDataAction = new JsonObject();
      chatDataAction.add("createMessageAction", createMessageAction);

      JsonObject hostAppDataAction = new JsonObject();
      hostAppDataAction.add("chatDataAction", chatDataAction);

      JsonObject finalResponse = new JsonObject();
      finalResponse.add("hostAppDataAction", hostAppDataAction);

      response.getWriter().write(finalResponse.toString());
    }
  }
}

Apps Script

/**
 * Responds to an APP_COMMAND interaction event in Google Chat.
 *
 * @param {Object} event The interaction event from Google Chat.
 * @return {Object} The JSON response message with a confirmation.
 */
function onAppCommand(event) {
  // Collect the command ID and type from the event metadata.
  const {appCommandId, appCommandType} =
    event.chat.appCommandPayload.appCommandMetadata;

  if (appCommandType === 'MESSAGE_ACTION' &&
      appCommandId === REMIND_ME_COMMAND_ID) {

    // Message actions can access the context of the message they were
    // invoked on, such as the text or sender of that message.
    const messageText = event.chat.appCommandPayload.message.text;

    // Return a response that includes details from the original message.
    return CardService.newChatResponseBuilder()
        .setText("Setting a reminder for message: " + messageText)
        .build();
  }
}

এই কোডের স্যাম্পেল ব্যবহার করতে, REMIND_ME_COMMAND_ID-এর জায়গায় সেই কমান্ড আইডি লিখুন যেটি আপনি Chat API-তে কমান্ড কনফিগার করার সময় উল্লেখ করেছিলেন।

কমান্ড পরীক্ষা করুন

কমান্ড ও কোড টেস্ট করতে, Google Chat অ্যাপের জন্য ইন্টার‍্যাক্টিভ ফিচার টেস্ট করুন দেখুন।

Chat UI-তে কীভাবে কমান্ড পরীক্ষা ও ব্যবহার করতে হয় তা জানতে, Google Chat সহায়তা ডকুমেন্টেশনে Google Chat-এ অ্যাপ ব্যবহার করুন দেখুন।

অ্যাড-অন নয় এমন Chat অ্যাপ: কমান্ডের উত্তর দেয়

নিম্নলিখিত ডকুমেন্টেশন Chat অ্যাপের ক্ষেত্রে প্রযোজ্য যা Google Workspace অ্যাড-অন নয়। অ্যাড-অন নয় এমন Chat অ্যাপ মাইগ্রেট করতে, Google Chat অ্যাপকে Google Workspace অ্যাড-অনে কনভার্ট করুন দেখুন।

ব্যবহারকারী কোনও কমান্ড ব্যবহার করলে, অ্যাড-অন নয় এমন Chat অ্যাপ ইন্টার‍্যাকশন ইভেন্ট পায় এবং সরাসরি Message অবজেক্ট ফিরিয়ে দিয়ে উত্তর দিতে পারে। ইভেন্ট পেলোডে মেটাডেটা থাকে যাতে যে কমান্ডটি ইনভোক করা হয়েছে (কমান্ড আইডি এবং কমান্ডের ধরন সহ) তার বিবরণ থাকে, যাতে আপনি একটি উপযুক্ত উত্তর দিতে পারেন।

অ্যাড-অন নয় এমন Chat অ্যাপে প্রতিটি ধরনের কমান্ডের উত্তর দিতে, আপনাকে ইভেন্ট পেলোডে বিভিন্ন ধরনের ইভেন্ট ও মেটাডেটা অবজেক্ট ম্যানেজ করতে হবে:

কমান্ডের ধরন ইভেন্টের প্রকার কমান্ড মেটাডেটা
স্ল্যাশ কমান্ড MESSAGE message.slashCommand অথবা message.annotation.slashCommand
দ্রুত কমান্ড APP_COMMAND appCommandMetadata
মেসেজ অ্যাকশন APP_COMMAND appCommandMetadata

স্ল্যাশ কমান্ডের উত্তর দিন

নিম্নলিখিত কোডটি এমন একটি Chat অ্যাপের উদাহরণ দেখায় যা স্ল্যাশ কমান্ডের উত্তর দেয় এমন কোনও অ্যাড-অন নয় /about. Chat অ্যাপ MESSAGE ইন্টার‍্যাকশন ইভেন্ট ম্যানেজ করে, ইন্টার‍্যাকশন ইভেন্টে ম্যাচিং কমান্ড আইডি আছে কিনা তা শনাক্ত করে এবং একটি ব্যক্তিগত Message অবজেক্ট রিটার্ন করে:

Node.js

node/avatar-app/index.js
/**
 * Handles slash and quick commands.
 *
 * @param {Object} event - The Google Chat event.
 * @param {Object} res - The HTTP response object.
 */
function handleAppCommands(event, res) {
  const {appCommandId, appCommandType} = event.appCommandMetadata;

  switch (appCommandId) {
    case ABOUT_COMMAND_ID:
      return res.send({
        privateMessageViewer: event.user,
        text: 'The Avatar app replies to Google Chat messages.'
      });
    case HELP_COMMAND_ID:
      return res.send({
        privateMessageViewer: event.user,
        text: 'The Avatar app replies to Google Chat messages.'
      });
  }
}

Apps Script

apps-script/avatar-app/avatar-app.gs
// Checks for the presence of a slash command in the message.
if (event.message.slashCommand) {
  // Executes the slash command logic based on its ID.
  // Slash command IDs are set in the Google Chat API configuration.
  switch (event.message.slashCommand.commandId) {
    case ABOUT_COMMAND_ID:
      return {
        privateMessageViewer: event.user,
        text: 'The Avatar app replies to Google Chat messages.'
      };
  }
}

Python

python/avatar-app/main.py
def handle_app_commands(event: Mapping[str, Any]) -> Mapping[str, Any]:
    """Handles slash and quick commands.

    Args:
        Mapping[str, Any] event: The Google Chat event.

    Returns:
        Mapping[str, Any]: the response
    """
    app_command_id = event["appCommandMetadata"]["appCommandId"]

    if app_command_id == ABOUT_COMMAND_ID:
        return {
            "privateMessageViewer": event["user"],
            "text": "The Avatar app replies to Google Chat messages.",
        }
    elif app_command_id == HELP_COMMAND_ID:
        return {
            "privateMessageViewer": event["user"],
            "text": "The Avatar app replies to Google Chat messages.",
        }
    return {}

Java

java/avatar-app/src/main/java/AvatarApp.java
/**
 * Handles slash and quick commands.
 *
 * @param event    The Google Chat event.
 * @param response The HTTP response object.
 */
private void handleAppCommands(JsonObject event, HttpResponse response) throws Exception {
  int appCommandId = event.getAsJsonObject("appCommandMetadata").get("appCommandId").getAsInt();

  switch (appCommandId) {
    case ABOUT_COMMAND_ID:
      Message aboutMessage = new Message();
      aboutMessage.setText("The Avatar app replies to Google Chat messages.");
      aboutMessage.setPrivateMessageViewer(new User()
          .setName(event.getAsJsonObject("user").get("name").getAsString()));
      response.getWriter().write(gson.toJson(aboutMessage));
      return;
    case HELP_COMMAND_ID:
      Message helpMessage = new Message();
      helpMessage.setText("The Avatar app replies to Google Chat messages.");
      helpMessage.setPrivateMessageViewer(new User()
          .setName(event.getAsJsonObject("user").get("name").getAsString()));
      response.getWriter().write(gson.toJson(helpMessage));
      return;
  }
}

Google Cloud কনসোলে কমান্ড কনফিগার করার সময় আপনি যে কমান্ড আইডি উল্লেখ করেছিলেন, ABOUT_COMMAND_ID-এর পরিবর্তে সেটি লিখুন।

দ্রুত কমান্ডের উত্তর দিন

নিম্নলিখিত কোডটি এমন একটি Chat অ্যাপের উদাহরণ দেখায় যা কোনও অ্যাড-অন নয় এবং এটি কুইক কমান্ড Help-এর উত্তর দেয়। Chat অ্যাপ APP_COMMAND ইন্টার‍্যাকশন ইভেন্ট ম্যানেজ করে, ইন্টার‍্যাকশন ইভেন্টে ম্যাচিং কমান্ড আইডি আছে কিনা তা শনাক্ত করে এবং একটি ব্যক্তিগত Message অবজেক্ট রিটার্ন করে:

Node.js

node/avatar-app/index.js
/**
 * Handles slash and quick commands.
 *
 * @param {Object} event - The Google Chat event.
 * @param {Object} res - The HTTP response object.
 */
function handleAppCommands(event, res) {
  const {appCommandId, appCommandType} = event.appCommandMetadata;

  switch (appCommandId) {
    case ABOUT_COMMAND_ID:
      return res.send({
        privateMessageViewer: event.user,
        text: 'The Avatar app replies to Google Chat messages.'
      });
    case HELP_COMMAND_ID:
      return res.send({
        privateMessageViewer: event.user,
        text: 'The Avatar app replies to Google Chat messages.'
      });
  }
}

Apps Script

apps-script/avatar-app/avatar-app.gs
/**
 * Handles the APP_COMMAND event type. This function is triggered when a user
 * interacts with a quick command within the Google Chat app.  It responds
 * based on the command ID.
 *
 * @param {Object} event The event object from Google Chat, containing details
 *     about the app command interaction.  It includes information like the
 *     command ID and the user who triggered it.
 */
function onAppCommand(event) {
  // Executes the quick command logic based on its ID.
  // Command IDs are set in the Google Chat API configuration.
  switch (event.appCommandMetadata.appCommandId) {
    case HELP_COMMAND_ID:
      return {
        privateMessageViewer: event.user,
        text: 'The Avatar app replies to Google Chat messages.'
      };
  }
}

Python

python/avatar-app/main.py
def handle_app_commands(event: Mapping[str, Any]) -> Mapping[str, Any]:
    """Handles slash and quick commands.

    Args:
        Mapping[str, Any] event: The Google Chat event.

    Returns:
        Mapping[str, Any]: the response
    """
    app_command_id = event["appCommandMetadata"]["appCommandId"]

    if app_command_id == ABOUT_COMMAND_ID:
        return {
            "privateMessageViewer": event["user"],
            "text": "The Avatar app replies to Google Chat messages.",
        }
    elif app_command_id == HELP_COMMAND_ID:
        return {
            "privateMessageViewer": event["user"],
            "text": "The Avatar app replies to Google Chat messages.",
        }
    return {}

Java

java/avatar-app/src/main/java/AvatarApp.java
/**
 * Handles slash and quick commands.
 *
 * @param event    The Google Chat event.
 * @param response The HTTP response object.
 */
private void handleAppCommands(JsonObject event, HttpResponse response) throws Exception {
  int appCommandId = event.getAsJsonObject("appCommandMetadata").get("appCommandId").getAsInt();

  switch (appCommandId) {
    case ABOUT_COMMAND_ID:
      Message aboutMessage = new Message();
      aboutMessage.setText("The Avatar app replies to Google Chat messages.");
      aboutMessage.setPrivateMessageViewer(new User()
          .setName(event.getAsJsonObject("user").get("name").getAsString()));
      response.getWriter().write(gson.toJson(aboutMessage));
      return;
    case HELP_COMMAND_ID:
      Message helpMessage = new Message();
      helpMessage.setText("The Avatar app replies to Google Chat messages.");
      helpMessage.setPrivateMessageViewer(new User()
          .setName(event.getAsJsonObject("user").get("name").getAsString()));
      response.getWriter().write(gson.toJson(helpMessage));
      return;
  }
}

Google Cloud কনসোলে কমান্ড কনফিগার করার সময় আপনি যে কমান্ড আইডি উল্লেখ করেছিলেন, HELP_COMMAND_ID-এর পরিবর্তে সেটি লিখুন।

মেসেজ অ্যাকশনে উত্তর দিন

নিম্নলিখিত কোডটি এমন একটি Chat অ্যাপের উদাহরণ দেখায় যা অ্যাড-অন নয় এবং মেসেজ অ্যাকশন আমাকে মনে করিয়ে দাও-এর উত্তর দেয়। Chat অ্যাপ APP_COMMAND ইন্টার‍্যাকশন ইভেন্ট ম্যানেজ করে, ইন্টার‍্যাকশন ইভেন্টে ম্যাচিং কমান্ড আইডি আছে কিনা তা শনাক্ত করে এবং একটি ব্যক্তিগত Message অবজেক্ট ফিরিয়ে দেয়:

Node.js

/**
 * Responds to an APP_COMMAND interaction event from Google Chat.
 *
 * @param {Object} event The interaction event from Google Chat.
 * @param {Object} res The HTTP response object.
 * @return {Object} The JSON response message with a confirmation.
 */
function handleAppCommand(event, res) {
  // Collect the command ID and type from the event metadata.
  const {appCommandId, appCommandType} = event.appCommandMetadata;

  // Use appCommandType to detect message actions.
  if (appCommandType === 'MESSAGE_ACTION' &&
      appCommandId === REMIND_ME_COMMAND_ID) {

    // Message actions can access the context of the message they were
    // invoked on, such as the text or sender of that message.
    const messageText = event.message.text;

    // Return a response that includes details from the original message.
    return res.send({
      text: `Setting a reminder for this message: "${messageText}"`
    });
  }
}

Apps Script

/**
 * Responds to an APP_COMMAND interaction event in Google Chat.
 *
 * @param {Object} event The interaction event from Google Chat.
 * @return {Object} The JSON response message with a confirmation.
 */
function onAppCommand(event) {
  // Collect the command ID and type from the event metadata.
  const {appCommandId, appCommandType} = event.appCommandMetadata;

  if (appCommandType === 'MESSAGE_ACTION' &&
      appCommandId === REMIND_ME_COMMAND_ID) {

    // Message actions can access the context of the message they were
    // invoked on, such as the text or sender of that message.
    const messageText = event.message.text;

    // Return a response that includes details from the original message.
    return { "text": "Setting a reminder for message: " + messageText };
  }
}

Python

def handle_app_command(event):
    """Responds to an APP_COMMAND interaction event from Google Chat.

    Args:
        event (dict): The interaction event from Google Chat.

    Returns:
        dict: The JSON response message with a confirmation.
    """
    # Collect the command ID and type from the event metadata.
    metadata = event.get('appCommandMetadata', {})
    if metadata.get('appCommandType') == 'MESSAGE_ACTION' and \
       metadata.get('appCommandId') == REMIND_ME_COMMAND_ID:

        # Message actions can access the context of the message they were
        # invoked on, such as the text or sender of that message.
        message_text = event.get('message', {}).get('text')

        # Return a response that includes details from the original message.
        return {
            "text": f'Setting a reminder for message: "{message_text}"'
        }

Java

/**
 * Responds to an APP_COMMAND interaction event from Google Chat.
 *
 * @param event The interaction event from Google Chat.
 * @param response The HTTP response object.
 */
void handleAppCommand(JsonObject event, HttpResponse response) throws Exception {
  // Collect the command ID and type from the event metadata.
  JsonObject metadata = event.getAsJsonObject("appCommandMetadata");
  String appCommandType = metadata.get("appCommandType").getAsString();

  if (appCommandType.equals("MESSAGE_ACTION")) {
    int commandId = metadata.get("appCommandId").getAsInt();
    if (commandId == REMIND_ME_COMMAND_ID) {
      // Message actions can access the context of the message they were
      // invoked on, such as the text or sender of that message.
      String messageText = event.getAsJsonObject("message").get("text").getAsString();

      // Return a response that includes details from the original message.
      JsonObject responseMessage = new JsonObject();
      responseMessage.addProperty("text", "Setting a reminder for message: " + messageText);
      response.getWriter().write(responseMessage.toString());
    }
  }
}

Google Cloud কনসোলে কমান্ড কনফিগার করার সময় আপনি যে কমান্ড আইডি উল্লেখ করেছিলেন, REMIND_ME_COMMAND_ID-এর পরিবর্তে সেটি লিখুন।