মেসেজ আপডেট করা

এই নির্দেশিকা থেকে জানতে পারবেন যে স্পেসে টেক্সট বা কার্ড মেসেজ আপডেট করতে, Google Chat API-এর Message রিসোর্সে কীভাবে update পদ্ধতি ব্যবহার করতে হয়। মেসেজের অ্যাট্রিবিউট পরিবর্তন করতে মেসেজ আপডেট করুন, যেমন, এটি কী বলে বা কার্ডের কন্টেন্ট। এছাড়াও, আপনি কার্ড মেসেজের আগে টেক্সট মেসেজ যোগ করতে পারেন অথবা টেক্সট মেসেজের পরে কার্ড যোগ করতে পারেন।

Chat API-তে, Chat মেসেজ Message রিসোর্স দ্বারা দেখানো হয়। Chat ব্যবহারকারীরা শুধুমাত্র টেক্সট মেসেজ পাঠাতে পারলেও, Chat অ্যাপ আরও অনেক মেসেজিং ফিচার ব্যবহার করতে পারে, যার মধ্যে স্ট্যাটিক বা ইন্টার‍্যাক্টিভ ইউজার ইন্টারফেস দেখানো, ব্যবহারকারীদের থেকে তথ্য সংগ্রহ করা এবং ব্যক্তিগতভাবে মেসেজ পাঠানোর মতো ফিচার অন্তর্ভুক্ত। Chat API-এর জন্য উপলভ্য মেসেজিং ফিচার সম্পর্কে আরও জানতে, Google Chat মেসেজের ওভারভিউ দেখুন।

পূর্বশর্ত

Node.js

  • Google Chat-এ অ্যাক্সেস সহ Google Workspace-এর Business বা Enterprise অ্যাকাউন্ট।

Python

  • Google Chat-এ অ্যাক্সেস সহ Google Workspace-এর Business বা Enterprise অ্যাকাউন্ট।

Java

  • Google Chat-এ অ্যাক্সেস সহ Google Workspace-এর Business বা Enterprise অ্যাকাউন্ট।

Apps Script

  • Google Chat-এ অ্যাক্সেস সহ Google Workspace-এর Business বা Enterprise অ্যাকাউন্ট।

ব্যবহারকারীর হয়ে মেসেজ আপডেট করুন

ব্যবহারকারীর পরিচয় যাচাইকরণ ফিচারের মাধ্যমে, শুধুমাত্র মেসেজের টেক্সট আপডেট করা যাবে।

ব্যবহারকারীর যাচাইকরণ সহ কোনও মেসেজ আপডেট করতে, আপনার অনুরোধে নিম্নলিখিত তথ্য পাস করুন:

  • chat.messages অনুমোদনের স্কোপ নির্দিষ্ট করুন।
  • UpdateMessage মেথড কল করুন।
  • message-কে Message-এর একটি ইনস্ট্যান্স হিসেবে পাস করুন নিম্নলিখিতগুলির সাথে:
    • name ফিল্ডটি আপডেট করার জন্য মেসেজে সেট করা হয়েছে, যার মধ্যে একটি স্পেস আইডি এবং একটি মেসেজ আইডি রয়েছে।
    • text ফিল্ডটি নতুন টেক্সট দিয়ে সেট করা হয়েছে।
  • text ভ্যালু সহ updateMask পাস করুন।

আপডেট করা মেসেজটি যদি কার্ড মেসেজ হয়, তাহলে টেক্সটটি কার্ডের আগে যোগ করা হয় (যা দেখানো চলতে থাকে)।

ব্যবহারকারী যাচাইকরণ-এর মাধ্যমে কীভাবে মেসেজ আপডেট করবেন বা কার্ড মেসেজের আগে টেক্সট মেসেজ যোগ করবেন তা এখানে দেওয়া হল:

Node.js

chat/client-libraries/cloud/update-message-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';

const USER_AUTH_OAUTH_SCOPES = [
  'https://www.googleapis.com/auth/chat.messages',
];

// This sample shows how to update a message with user credential
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(
    USER_AUTH_OAUTH_SCOPES,
  );

  // Initialize request argument(s)
  const request = {
    message: {
      // Replace SPACE_NAME and MESSAGE_NAME here
      name: 'spaces/SPACE_NAME/messages/MESSAGE_NAME',
      text: 'Updated with user credential!',
    },
    // The field paths to update. Separate multiple values with commas or use `*`
    // to update all field paths.
    updateMask: {
      // The field paths to update.
      paths: ['text'],
    },
  };

  // Make the request
  const response = await chatClient.updateMessage(request);

  // Handle the response
  console.log(response);
}

await main();

Python

chat/client-libraries/cloud/update_message_user_cred.py
from authentication_utils import create_client_with_user_credentials
from google.apps import chat_v1 as google_chat

SCOPES = ["https://www.googleapis.com/auth/chat.messages"]

# This sample shows how to update a message with user credential
def update_message_with_user_cred():
    # Create a client
    client = create_client_with_user_credentials(SCOPES)

    # Initialize request argument(s)
    request = google_chat.UpdateMessageRequest(
        message = {
            # Replace SPACE_NAME and MESSAGE_NAME here
            "name": "spaces/SPACE_NAME/messages/MESSAGE_NAME",
            "text": "Updated with user credential!"
        },
        # The field paths to update. Separate multiple values with commas or use
        # `*` to update all field paths.
        update_mask = "text"
    )

    # Make the request
    response = client.update_message(request)

    # Handle the response
    print(response)

update_message_with_user_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/UpdateMessageUserCred.java
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.UpdateMessageRequest;
import com.google.chat.v1.Message;
import com.google.protobuf.FieldMask;

// This sample shows how to update message with user credential.
public class UpdateMessageUserCred {

  private static final String SCOPE =
    "https://www.googleapis.com/auth/chat.messages";

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithUserCredentials(
          ImmutableList.of(SCOPE))) {
      UpdateMessageRequest.Builder request = UpdateMessageRequest.newBuilder()
        .setMessage(Message.newBuilder()
          // replace SPACE_NAME and MESSAGE_NAME here
          .setName("spaces/SPACE_NAME/messages/MESSAGE_NAME")
          .setText("Updated with user credential!"))
        .setUpdateMask(FieldMask.newBuilder()
          // The field paths to update.
          .addPaths("text"));
      Message response = chatServiceClient.updateMessage(request.build());

      System.out.println(JsonFormat.printer().print(response));
    }
  }
}

Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to update a message with user credential
 *
 * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.messages'
 * referenced in the manifest file (appsscript.json).
 */
function updateMessageUserCred() {
  // Initialize request argument(s)
  // TODO(developer): Replace SPACE_NAME and MESSAGE_NAME here
  const name = "spaces/SPACE_NAME/messages/MESSAGE_NAME";
  const message = {
    text: "Updated with user credential!",
  };
  // The field paths to update. Separate multiple values with commas or use
  // `*` to update all field paths.
  const updateMask = "text";

  // Make the request
  const response = Chat.Spaces.Messages.patch(message, name, {
    updateMask: updateMask,
  });

  // Handle the response
  console.log(response);
}

এই স্যাম্পেল রান করতে, নিম্নলিখিতগুলি পরিবর্তন করুন:

  • SPACE_NAME: স্পেসের name থেকে আইডি। আপনি ListSpaces মেথড কল করে বা স্পেসের URL থেকে ID পেতে পারেন।
  • MESSAGE_NAME: মেসেজের আইডি name. Chat API-এর মাধ্যমে অ্যাসিঙ্ক্রোনাসভাবে মেসেজ তৈরি করার পরে, আপনি রেসপন্স বডি থেকে আইডি পেতে পারেন অথবা মেসেজ তৈরি করার সময় অ্যাসাইন করা কাস্টম নাম থেকেও আইডি পেতে পারেন।

Chat API Message-এর একটি ইনস্ট্যান্স রিটার্ন করে যা আপডেট করা মেসেজের বিবরণ দেয়।

Chat অ্যাপ হিসেবে মেসেজ আপডেট করুন

অ্যাপ যাচাইকরণ ফিচারের মাধ্যমে, মেসেজের টেক্সট ও কার্ড, দুটিই আপডেট করা যাবে।

অ্যাপ যাচাইকরণের মাধ্যমে কোনও মেসেজ আপডেট করতে, আপনার অনুরোধে নিম্নলিখিত তথ্য পাস করুন:

  • chat.bot অনুমোদনের স্কোপ নির্দিষ্ট করুন।
  • UpdateMessage মেথড কল করুন।
  • message-কে Message-এর একটি ইনস্ট্যান্স হিসেবে পাস করুন নিম্নলিখিতগুলির সাথে:
    • name ফিল্ডটি আপডেট করার জন্য মেসেজে সেট করা হয়েছে, যার মধ্যে একটি স্পেস আইডি এবং একটি মেসেজ আইডি রয়েছে।
    • text ফিল্ড আপডেট করার প্রয়োজন হলে, নতুন টেক্সট দিয়ে সেট করা হয়।
    • নতুন কার্ড আপডেট করার প্রয়োজন হলে, cardsV2 ফিল্ড সেট করা হয়।
  • updateMask পাস করুন, সাথে আপডেট করার জন্য ফিল্ডের তালিকা যেমন text, এবং cardsV2।

আপডেট করা মেসেজটি যদি কার্ড মেসেজ হয় এবং টেক্সট আপডেট করা হয়, তাহলে আপডেট করা টেক্সট কার্ডের আগে যোগ করা হয় (যা দেখানো চলতে থাকে)। আপডেট করা মেসেজটি যদি টেক্সট মেসেজ হয় এবং কার্ড আপডেট করা হয়, তাহলে আপডেট করা কার্ড টেক্সটের সাথে যোগ করা হয় (যা দেখানো চালিয়ে যাওয়া হয়)।

অ্যাপ যাচাইকরণ সহ কোনও মেসেজের টেক্সট ও কার্ড কীভাবে আপডেট করবেন তা এখানে দেওয়া হল:

Node.js

chat/client-libraries/cloud/update-message-app-cred.js
import {createClientWithAppCredentials} from './authentication-utils.js';

// This sample shows how to update a message with app credential
async function main() {
  // Create a client
  const chatClient = createClientWithAppCredentials();

  // Initialize request argument(s)
  const request = {
    message: {
      // Replace SPACE_NAME and MESSAGE_NAME here
      name: 'spaces/SPACE_NAME/messages/MESSAGE_NAME',
      text: 'Text updated with app credential!',
      cardsV2: [
        {
          card: {
            header: {
              title: 'Card updated with app credential!',
              imageUrl:
                'https://fonts.gstatic.com/s/i/short-term/release/googlesymbols/info/default/24px.svg',
            },
          },
        },
      ],
    },
    // The field paths to update. Separate multiple values with commas or use `*`
    // to update all field paths.
    updateMask: {
      // The field paths to update.
      paths: ['text', 'cards_v2'],
    },
  };

  // Make the request
  const response = await chatClient.updateMessage(request);

  // Handle the response
  console.log(response);
}

await main();

Python

chat/client-libraries/cloud/update_message_app_cred.py
from authentication_utils import create_client_with_app_credentials
from google.apps import chat_v1 as google_chat

# This sample shows how to update a message with app credential
def update_message_with_app_cred():
    # Create a client
    client = create_client_with_app_credentials()

    # Initialize request argument(s)
    request = google_chat.UpdateMessageRequest(
        message = {
            # Replace SPACE_NAME and MESSAGE_NAME here
            "name": "spaces/SPACE_NAME/messages/MESSAGE_NAME",
            "text": "Text updated with app credential!",
            "cards_v2" : [{ "card": { "header": {
                "title": 'Card updated with app credential!',
                "image_url": 'https://fonts.gstatic.com/s/i/short-term/release/googlesymbols/info/default/24px.svg'
            }}}]
        },
        # The field paths to update. Separate multiple values with commas or use
        # `*` to update all field paths.
        update_mask = "text,cardsV2"
    )

    # Make the request
    response = client.update_message(request)

    # Handle the response
    print(response)

update_message_with_app_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/UpdateMessageAppCred.java
import com.google.apps.card.v1.Card;
import com.google.apps.card.v1.Card.CardHeader;
import com.google.chat.v1.CardWithId;
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.UpdateMessageRequest;
import com.google.chat.v1.Message;
import com.google.protobuf.FieldMask;

// This sample shows how to update message with app credential.
public class UpdateMessageAppCred {

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithAppCredentials()) {
      UpdateMessageRequest.Builder request = UpdateMessageRequest.newBuilder()
        .setMessage(Message.newBuilder()
          // replace SPACE_NAME and MESSAGE_NAME here
          .setName("spaces/SPACE_NAME/messages/MESSAGE_NAME")
          .setText("Text updated with app credential!")
          .addCardsV2(CardWithId.newBuilder().setCard(Card.newBuilder()
            .setHeader(CardHeader.newBuilder()
              .setTitle("Card updated with app credential!")
              .setImageUrl("https://fonts.gstatic.com/s/i/short-term/release/googlesymbols/info/default/24px.svg")))))
        .setUpdateMask(FieldMask.newBuilder()
          // The field paths to update.
          .addAllPaths(List.of("text", "cards_v2")));
      Message response = chatServiceClient.updateMessage(request.build());

      System.out.println(JsonFormat.printer().print(response));
    }
  }
}

Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to update a message with app credential
 *
 * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.bot'
 * used by service accounts.
 */
function updateMessageAppCred() {
  // Initialize request argument(s)
  // TODO(developer): Replace SPACE_NAME and MESSAGE_NAME here
  const name = "spaces/SPACE_NAME/messages/MESSAGE_NAME";
  const message = {
    text: "Text updated with app credential!",
    cardsV2: [
      {
        card: {
          header: {
            title: "Card updated with app credential!",
            imageUrl:
              "https://fonts.gstatic.com/s/i/short-term/release/googlesymbols/info/default/24px.svg",
          },
        },
      },
    ],
  };
  // The field paths to update. Separate multiple values with commas or use
  // `*` to update all field paths.
  const updateMask = "text,cardsV2";

  // Make the request
  const response = Chat.Spaces.Messages.patch(
    message,
    name,
    {
      updateMask: updateMask,
    },
    getHeaderWithAppCredentials(),
  );

  // Handle the response
  console.log(response);
}

এই স্যাম্পেল রান করতে, নিম্নলিখিতগুলি পরিবর্তন করুন:

  • SPACE_NAME: স্পেসের name থেকে আইডি। আপনি ListSpaces মেথড কল করে বা স্পেসের URL থেকে ID পেতে পারেন।
  • MESSAGE_NAME: মেসেজের আইডি name. Chat API-এর মাধ্যমে অ্যাসিঙ্ক্রোনাসভাবে মেসেজ তৈরি করার পরে, আপনি রেসপন্স বডি থেকে আইডি পেতে পারেন অথবা মেসেজ তৈরি করার সময় অ্যাসাইন করা কাস্টম নাম থেকেও আইডি পেতে পারেন।

Chat API Message-এর একটি ইনস্ট্যান্স রিটার্ন করে যা আপডেট করা মেসেজের বিবরণ দেয়।

অ্যাসিঙ্ক্রোনাসভাবে কার্ড আপডেট করুন

আপনি replaceCards পদ্ধতি ব্যবহার করে কোনও মেসেজে কার্ড অ্যাসিঙ্ক্রোনাসভাবে আপডেট করতে পারবেন। ব্যবহারকারীর ইন্টার‍্যাকশন ছাড়াই কার্ডের কন্টেন্ট আপডেট করার জন্য এটি উপযোগী, যেমন, লিঙ্কের প্রিভিউ রিফ্রেশ করা বা কোনও টাস্কের স্ট্যাটাস আপডেট করা। এই পদ্ধতি অ্যাপের মাধ্যমে তৈরি করা মেসেজের ক্ষেত্রে কাজ করে, যার মধ্যে ব্যবহারকারীর হয়ে তৈরি করা মেসেজও অন্তর্ভুক্ত।

বিস্তারিত জানতে, ইন্টার‍্যাক্টিভ কার্ড তৈরি ও আপডেট করা দেখুন।