একটি বার্তা আপডেট করুন

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

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

পূর্বশর্ত

নোড.জেএস

  • Google Chat অ্যাক্সেস সহ একটি ব্যবসা বা এন্টারপ্রাইজ Google Workspace অ্যাকাউন্ট।

পাইথন

  • Google Chat অ্যাক্সেস সহ একটি ব্যবসা বা এন্টারপ্রাইজ Google Workspace অ্যাকাউন্ট।

জাভা

  • Google Chat অ্যাক্সেস সহ একটি ব্যবসা বা এন্টারপ্রাইজ Google Workspace অ্যাকাউন্ট।

অ্যাপস স্ক্রিপ্ট

  • Google Chat অ্যাক্সেস সহ একটি ব্যবসা বা এন্টারপ্রাইজ Google Workspace অ্যাকাউন্ট।

একজন ব্যবহারকারীর পক্ষ থেকে একটি বার্তা আপডেট করুন

ব্যবহারকারী প্রমাণীকরণের মাধ্যমে, শুধুমাত্র একটি বার্তার পাঠ্য আপডেট করা যেতে পারে।

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

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

যদি আপডেট করা বার্তাটি একটি কার্ড বার্তা হয়, তাহলে টেক্সটটি কার্ডগুলিতে যুক্ত হয় (যা প্রদর্শিত হতে থাকে)।

ব্যবহারকারী প্রমাণীকরণ সহ একটি কার্ড বার্তায় কীভাবে একটি বার্তা আপডেট করবেন, অথবা একটি টেক্সট বার্তা যুক্ত করবেন তা এখানে দেওয়া হল:

নোড.জেএস

চ্যাট/ক্লায়েন্ট-লাইব্রেরি/ক্লাউড/আপডেট-মেসেজ-ইউজার-ক্রেড.জেএস
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();

পাইথন

চ্যাট/ক্লায়েন্ট-লাইব্রেরি/ক্লাউড/আপডেট_মেসেজ_ইউজার_ক্রেড.পি
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()

জাভা

চ্যাট/ক্লায়েন্ট-লাইব্রেরি/ক্লাউড/এসআরসি/মেইন/জাভা/কম/গুগল/ওয়ার্কস্পেস/এপিআই/চ্যাট/স্যাম্পল/আপডেটমেসেজইউজারক্রেড.জাভা
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));
    }
  }
}

অ্যাপস স্ক্রিপ্ট

চ্যাট/অ্যাডভান্সড-সার্ভিস/মেইন.জি.এস
/**
 * 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 থেকে আইডিটি পেতে পারেন।
  • MESSAGE_NAME : বার্তার name আইডি। আপনি চ্যাট API ব্যবহার করে অ্যাসিঙ্ক্রোনাসভাবে বার্তা তৈরি করার পরে ফিরে আসা প্রতিক্রিয়া বডি থেকে, অথবা তৈরির সময় বার্তাটিতে নির্ধারিত কাস্টম নাম ব্যবহার করে আইডিটি পেতে পারেন।

চ্যাট এপিআই Message একটি উদাহরণ প্রদান করে যা আপডেট করা বার্তাটির বিস্তারিত বিবরণ দেয়।

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

অ্যাপ প্রমাণীকরণের মাধ্যমে, বার্তার টেক্সট এবং কার্ড উভয়ই আপডেট করা যেতে পারে।

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

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

যদি আপডেট করা বার্তাটি একটি কার্ড বার্তা হয় এবং টেক্সট আপডেট করা হয়, তাহলে আপডেট করা পাঠ্যটি কার্ডগুলিতে যুক্ত হয় (যা প্রদর্শিত হতে থাকে)। যদি আপডেট করা বার্তাটি একটি টেক্সট বার্তা হয় এবং কার্ডগুলি আপডেট করা হয়, তাহলে আপডেট করা কার্ডগুলি পাঠ্যের সাথে যুক্ত হয় (যা প্রদর্শিত হতে থাকে)।

অ্যাপ প্রমাণীকরণের মাধ্যমে বার্তার টেক্সট এবং কার্ডগুলি কীভাবে আপডেট করবেন তা এখানে দেওয়া হল:

নোড.জেএস

চ্যাট/ক্লায়েন্ট-লাইব্রেরি/ক্লাউড/আপডেট-মেসেজ-অ্যাপ-ক্রেড.জেএস
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();

পাইথন

চ্যাট/ক্লায়েন্ট-লাইব্রেরি/ক্লাউড/আপডেট_মেসেজ_অ্যাপ_ক্রেড.পি
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()

জাভা

চ্যাট/ক্লায়েন্ট-লাইব্রেরি/ক্লাউড/এসআরসি/মেইন/জাভা/কম/গুগল/ওয়ার্কস্পেস/এপিআই/চ্যাট/স্যাম্পল/আপডেটমেসেজঅ্যাপক্রেড.জাভা
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));
    }
  }
}

অ্যাপস স্ক্রিপ্ট

চ্যাট/অ্যাডভান্সড-সার্ভিস/মেইন.জি.এস
/**
 * 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 থেকে আইডিটি পেতে পারেন।
  • MESSAGE_NAME : বার্তার name আইডি। আপনি চ্যাট API ব্যবহার করে অ্যাসিঙ্ক্রোনাসভাবে বার্তা তৈরি করার পরে ফিরে আসা প্রতিক্রিয়া বডি থেকে, অথবা তৈরির সময় বার্তাটিতে নির্ধারিত কাস্টম নাম ব্যবহার করে আইডিটি পেতে পারেন।

চ্যাট এপিআই Message একটি উদাহরণ প্রদান করে যা আপডেট করা বার্তাটির বিস্তারিত বিবরণ দেয়।