পূর্বরূপ লিঙ্ক

ব্যবহারকারীরা যখন Google Chat-এ একটি লিঙ্ক শেয়ার করেন তখন প্রসঙ্গ পরিবর্তন রোধ করতে, আপনার Chat অ্যাপ তাদের মেসেজের সাথে একটি কার্ড সংযুক্ত করে লিঙ্কটির পূর্বরূপ দেখতে পারে যা আরও তথ্য দেয় এবং লোকেদের সরাসরি Google Chat থেকে পদক্ষেপ নিতে দেয়।

উদাহরণস্বরূপ, একটি Google চ্যাট স্পেস কল্পনা করুন যাতে একটি কোম্পানির সমস্ত গ্রাহক পরিষেবা এজেন্ট এবং Case-y নামে একটি চ্যাট অ্যাপ অন্তর্ভুক্ত থাকে। এজেন্টরা প্রায়শই চ্যাট স্পেসে কাস্টমার সার্ভিস কেসের লিঙ্ক শেয়ার করে এবং প্রতিবারই তাদের সহকর্মীদের কেস লিংক খুলতে হবে যাতে অ্যাসাইনি, স্ট্যাটাস এবং বিষয়ের মতো বিশদ বিবরণ দেখতে হয়। একইভাবে, কেউ যদি কোনও মামলার মালিকানা নিতে বা স্ট্যাটাস পরিবর্তন করতে চান তবে তাদের লিঙ্কটি খুলতে হবে।

লিংক প্রিভিউ করার মাধ্যমে স্পেসের রেসিডেন্ট চ্যাট অ্যাপ, কেস-ওয়াই, যখনই কেউ একটি কেস লিঙ্ক শেয়ার করে তখন অ্যাসাইনি, স্ট্যাটাস এবং বিষয় দেখানো একটি কার্ড সংযুক্ত করতে সক্ষম করে। কার্ডের বোতামগুলি এজেন্টদের কেসের মালিকানা নিতে এবং চ্যাট স্ট্রীম থেকে সরাসরি স্থিতি পরিবর্তন করতে দেয়।

যখন কেউ তাদের বার্তায় একটি লিঙ্ক যোগ করে, তখন একটি চিপ উপস্থিত হয় যা তাদের জানতে দেয় যে একটি চ্যাট অ্যাপ লিঙ্কটির পূর্বরূপ দেখতে পারে।

চিপ ইঙ্গিত করে যে একটি চ্যাট অ্যাপ একটি লিঙ্কের পূর্বরূপ দেখতে পারে

বার্তা পাঠানোর পরে, লিঙ্কটি চ্যাট অ্যাপে পাঠানো হয়, যা তারপর ব্যবহারকারীর বার্তায় কার্ড তৈরি করে এবং সংযুক্ত করে।

চ্যাট অ্যাপ মেসেজের সাথে একটি কার্ড সংযুক্ত করে একটি লিঙ্কের প্রিভিউ করছে

লিঙ্কের পাশাপাশি, কার্ডটি বোতামের মতো ইন্টারেক্টিভ উপাদান সহ লিঙ্ক সম্পর্কে অতিরিক্ত তথ্য প্রদান করে। আপনার চ্যাট অ্যাপ ব্যবহারকারীর ইন্টারঅ্যাকশনের প্রতিক্রিয়া হিসেবে সংযুক্ত কার্ড আপডেট করতে পারে, যেমন বোতামে ক্লিক করা।

যদি কেউ চান না যে চ্যাট অ্যাপ তাদের বার্তার সাথে একটি কার্ড সংযুক্ত করে তাদের লিঙ্কের পূর্বরূপ দেখুক, তারা প্রিভিউ চিপে ক্লিক করে প্রিভিউ করা প্রতিরোধ করতে পারে। ব্যবহারকারীরা যেকোন সময় রিমুভ প্রিভিউ এ ক্লিক করে সংযুক্ত কার্ডটি সরাতে পারেন।

Google ক্লাউড কনসোলে আপনার চ্যাট অ্যাপের কনফিগারেশন পৃষ্ঠায় URL প্যাটার্ন হিসাবে example.com , support.example.com , এবং support.example.com/cases/ এর মতো নির্দিষ্ট লিঙ্কগুলি নিবন্ধন করুন যাতে আপনার চ্যাট অ্যাপ তাদের পূর্বরূপ দেখতে পারে।

লিঙ্ক পূর্বরূপ কনফিগারেশন মেনু

  1. গুগল ক্লাউড কনসোল খুলুন।
  2. "Google ক্লাউড"-এর পাশে, নিচের তীর এ ক্লিক করুন এবং আপনার চ্যাট অ্যাপের প্রোজেক্ট খুলুন।
  3. অনুসন্ধান ক্ষেত্রে, Google Chat API টাইপ করুন এবং Google Chat API-এ ক্লিক করুন।
  4. পরিচালনা > কনফিগারেশন ক্লিক করুন।
  5. লিঙ্ক পূর্বরূপের অধীনে, একটি URL প্যাটার্ন যোগ করুন বা সম্পাদনা করুন।
    1. একটি নতুন URL প্যাটার্নের জন্য লিঙ্কের পূর্বরূপ কনফিগার করতে, URL প্যাটার্ন যোগ করুন ক্লিক করুন।
    2. একটি বিদ্যমান URL প্যাটার্নের জন্য কনফিগারেশন সম্পাদনা করতে, নিচের তীর ক্লিক করুন।
  6. হোস্ট প্যাটার্ন ক্ষেত্রে, URL প্যাটার্নের ডোমেন লিখুন। চ্যাট অ্যাপ এই ডোমেনের লিঙ্কগুলির পূর্বরূপ দেখাবে।

    একটি নির্দিষ্ট সাবডোমেনের জন্য চ্যাট অ্যাপ প্রিভিউ লিঙ্ক পেতে, যেমন subdomain.example.com , সাবডোমেন অন্তর্ভুক্ত করুন।

    পুরো ডোমেনের জন্য চ্যাট অ্যাপের প্রিভিউ লিঙ্ক পেতে, সাবডোমেন হিসেবে তারকাচিহ্ন (*) সহ একটি ওয়াইল্ডকার্ড অক্ষর উল্লেখ করুন। উদাহরণস্বরূপ, *.example.com subdomain.example.com এবং any.number.of.subdomains.example.com এর সাথে মেলে।

  7. পথ উপসর্গ ক্ষেত্রে, হোস্ট প্যাটার্ন ডোমেনে যুক্ত করার জন্য একটি পাথ লিখুন।

    হোস্ট প্যাটার্ন ডোমেনে সমস্ত ইউআরএল মেলানোর জন্য, পাথ উপসর্গ খালি রাখুন।

    উদাহরণস্বরূপ, যদি হোস্ট প্যাটার্ন হয় support.example.com , তাহলে support.example.com/cases/ এ হোস্ট করা ক্ষেত্রে URL-এর সাথে মিল রাখতে, cases/ লিখুন।

  8. সম্পন্ন ক্লিক করুন.

  9. Save এ ক্লিক করুন।

এখন, যখনই কেউ একটি লিঙ্ক অন্তর্ভুক্ত করে যা একটি লিঙ্ক প্রিভিউ URL প্যাটার্নের সাথে মেলে এমন একটি চ্যাট স্পেসের একটি বার্তার সাথে যার মধ্যে আপনার চ্যাট অ্যাপ রয়েছে, আপনার অ্যাপ লিঙ্কটির পূর্বরূপ দেখায়।

আপনি একটি প্রদত্ত লিঙ্কের জন্য লিঙ্ক প্রিভিউ কনফিগার করার পরে, আপনার চ্যাট অ্যাপ এটিতে আরও তথ্য সংযুক্ত করে লিঙ্কটিকে চিনতে এবং পূর্বরূপ দেখতে পারে।

চ্যাট স্পেসগুলির ভিতরে যা আপনার চ্যাট অ্যাপকে অন্তর্ভুক্ত করে, যখন কারও বার্তায় একটি লিঙ্ক থাকে যা লিঙ্কের পূর্বরূপ URL প্যাটার্নের সাথে মেলে, তখন আপনার চ্যাট অ্যাপ একটি MESSAGE ইন্টারঅ্যাকশন ইভেন্ট পায়। ইন্টারঅ্যাকশন ইভেন্টের জন্য JSON পেলোডে matchedUrl ক্ষেত্র রয়েছে:

JSON

"message": {

  . . . // other message attributes redacted

  "matchedUrl": {
     "url": "https://support.example.com/cases/case123"
   },

  . . . // other message attributes redacted

}

MESSAGE ইভেন্ট পেলোডে matchedUrl ফিল্ডের উপস্থিতি পরীক্ষা করে, আপনার চ্যাট অ্যাপটি প্রিভিউ করা লিঙ্ক সহ মেসেজে তথ্য যোগ করতে পারে। আপনার চ্যাট অ্যাপটি হয় একটি সাধারণ পাঠ্য বার্তার মাধ্যমে উত্তর দিতে পারে বা একটি কার্ড সংযুক্ত করতে পারে।

একটি পাঠ্য বার্তা দিয়ে উত্তর দিন

সাধারণ প্রতিক্রিয়াগুলির জন্য, আপনার চ্যাট অ্যাপ একটি লিঙ্কে একটি সাধারণ পাঠ্য বার্তার সাথে উত্তর দিয়ে একটি লিঙ্কের পূর্বরূপ দেখতে পারে। এই উদাহরণটি এমন একটি বার্তা সংযুক্ত করে যা লিঙ্কের URLটির পুনরাবৃত্তি করে যা একটি লিঙ্কের পূর্বরূপ URL প্যাটার্নের সাথে মেলে।

Node.js

node/preview-link/simple-text-message.js
/**
 * Responds to messages that have links whose URLs match URL patterns
 * configured for link previewing.
 *
 * @param {Object} req Request sent from Google Chat.
 * @param {Object} res Response to send back.
 */
exports.onMessage = (req, res) => {
  if (req.method === 'GET' || !req.body.message) {
    return res.send(
      'Hello! This function is meant to be used in a Google Chat Space.');
  }

  // Checks for the presence of event.message.matchedUrl and responds with a
  // text message if present
  if (req.body.message.matchedUrl) {
    return res.json({
      'text': 'req.body.message.matchedUrl.url: ' +
        req.body.message.matchedUrl.url,
    });
  }

  // If the Chat app doesn’t detect a link preview URL pattern, it says so.
  return res.json({'text': 'No matchedUrl detected.'});
};

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

apps-script/preview-link/simple-text-message.gs
/**
 * Responds to messages that have links whose URLs match URL patterns
 * configured for link previewing.
 *
 * @param {Object} event The event object from Chat API.
 *
 * @return {Object} Response from the Chat app attached to the message with
 * the previewed link.
 */
function onMessage(event) {
  // Checks for the presence of event.message.matchedUrl and responds with a
  // text message if present
  if (event.message.matchedUrl) {
    return {
      'text': 'event.message.matchedUrl.url: ' + event.message.matchedUrl.url,
    };
  }

  // If the Chat app doesn’t detect a link preview URL pattern, it says so.
  return {'text': 'No matchedUrl detected.'};
}

একটি কার্ড সংযুক্ত করুন

একটি পূর্বরূপ লিঙ্কে একটি কার্ড সংযুক্ত করতে, UPDATE_USER_MESSAGE_CARDS টাইপের একটি ActionResponse ফেরত দিন। এই উদাহরণটি একটি সাধারণ কার্ড সংযুক্ত করে।

চ্যাট অ্যাপ মেসেজের সাথে একটি কার্ড সংযুক্ত করে একটি লিঙ্কের প্রিভিউ করছে

Node.js

node/preview-link/attach-card.js
/**
 * Responds to messages that have links whose URLs match URL patterns
 * configured for link previewing.
 *
 * @param {Object} req Request sent from Google Chat.
 * @param {Object} res Response to send back.
 */
exports.onMessage = (req, res) => {
  if (req.method === 'GET' || !req.body.message) {
    return res.send(
      'Hello! This function is meant to be used in a Google Chat Space.');
  }

  // Checks for the presence of event.message.matchedUrl and attaches a card
  // if present
  if (req.body.message.matchedUrl) {
    return res.json({
      'actionResponse': {'type': 'UPDATE_USER_MESSAGE_CARDS'},
      'cardsV2': [
        {
          'cardId': 'attachCard',
          'card': {
            'header': {
              'title': 'Example Customer Service Case',
              'subtitle': 'Case basics',
            },
            'sections': [
              {
                'widgets': [
                  {'keyValue': {'topLabel': 'Case ID', 'content': 'case123'}},
                  {'keyValue': {'topLabel': 'Assignee', 'content': 'Charlie'}},
                  {'keyValue': {'topLabel': 'Status', 'content': 'Open'}},
                  {
                    'keyValue': {
                      'topLabel': 'Subject', 'content': 'It won"t turn on...',
                    }
                  },
                ],
              },
              {
                'widgets': [
                  {
                    'buttons': [
                      {
                        'textButton': {
                          'text': 'OPEN CASE',
                          'onClick': {
                            'openLink': {
                              'url': 'https://support.example.com/orders/case123',
                            },
                          },
                        },
                      },
                      {
                        'textButton': {
                          'text': 'RESOLVE CASE',
                          'onClick': {
                            'openLink': {
                              'url': 'https://support.example.com/orders/case123?resolved=y',
                            },
                          },
                        },
                      },
                      {
                        'textButton': {
                          'text': 'ASSIGN TO ME',
                          'onClick': {
                            'action': {
                              'actionMethodName': 'assign',
                            },
                          },
                        },
                      },
                    ],
                  },
                ],
              },
            ],
          },
        },
      ],
    });
  }

  // If the Chat app doesn’t detect a link preview URL pattern, it says so.
  return res.json({'text': 'No matchedUrl detected.'});
};

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

এই উদাহরণ কার্ড JSON ফেরত দিয়ে একটি কার্ড বার্তা পাঠায়। আপনি Apps স্ক্রিপ্ট কার্ড পরিষেবাও ব্যবহার করতে পারেন৷

apps-script/preview-link/attach-card.gs
/**
 * Responds to messages that have links whose URLs match URL patterns
 * configured for link previewing.
 *
 * @param {Object} event The event object from Chat API.
 * @return {Object} Response from the Chat app attached to the message with
 * the previewed link.
 */
function onMessage(event) {
  // Checks for the presence of event.message.matchedUrl and attaches a card
  // if present
  if (event.message.matchedUrl) {
    return {
      'actionResponse': {
        'type': 'UPDATE_USER_MESSAGE_CARDS',
      },
      'cardsV2': [{
        'cardId': 'attachCard',
        'card': {
          'header': {
            'title': 'Example Customer Service Case',
            'subtitle': 'Case basics',
          },
          'sections': [{
            'widgets': [
              {'keyValue': {'topLabel': 'Case ID', 'content': 'case123'}},
              {'keyValue': {'topLabel': 'Assignee', 'content': 'Charlie'}},
              {'keyValue': {'topLabel': 'Status', 'content': 'Open'}},
              {
                'keyValue': {
                  'topLabel': 'Subject', 'content': 'It won\'t turn on...',
                },
              },
            ],
          },
          {
            'widgets': [{
              'buttons': [
                {
                  'textButton': {
                    'text': 'OPEN CASE',
                    'onClick': {
                      'openLink': {
                        'url': 'https://support.example.com/orders/case123',
                      },
                    },
                  },
                },
                {
                  'textButton': {
                    'text': 'RESOLVE CASE',
                    'onClick': {
                      'openLink': {
                        'url': 'https://support.example.com/orders/case123?resolved=y',
                      },
                    },
                  },
                },
                {
                  'textButton': {
                    'text': 'ASSIGN TO ME',
                    'onClick': {'action': {'actionMethodName': 'assign'}},
                  },
                },
              ],
            }],
          }],
        },
      }],
    };
  }

  // If the Chat app doesn’t detect a link preview URL pattern, it says so.
  return {'text': 'No matchedUrl detected.'};
}

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

একটি প্রিভিউ করা লিঙ্কে সংযুক্ত কার্ড আপডেট করতে, UPDATE_USER_MESSAGE_CARDS টাইপের একটি ActionResponse ফেরত দিন। চ্যাট অ্যাপগুলি শুধুমাত্র সেই কার্ডগুলি আপডেট করতে পারে যেগুলি একটি চ্যাট অ্যাপ ইন্টারঅ্যাকশন ইভেন্টের প্রতিক্রিয়া হিসাবে লিঙ্কগুলির পূর্বরূপ দেখে। চ্যাট অ্যাপগুলি অ্যাসিঙ্ক্রোনাসভাবে Chat API কল করে এই কার্ডগুলি আপডেট করতে পারে না।

লিঙ্ক প্রিভিউ UPDATE_MESSAGE ধরনের একটি ActionResponse ফেরত দেওয়া সমর্থন করে না। কারণ UPDATE_MESSAGE শুধুমাত্র কার্ডের পরিবর্তে সম্পূর্ণ বার্তা আপডেট করে, এটি শুধুমাত্র তখনই কাজ করে যদি চ্যাট অ্যাপ আসল বার্তাটি তৈরি করে। লিঙ্ক প্রিভিউ করা ব্যবহারকারীর তৈরি বার্তার সাথে একটি কার্ড সংযুক্ত করে, তাই চ্যাট অ্যাপের এটি আপডেট করার অনুমতি নেই।

চ্যাট স্ট্রীমে ব্যবহারকারীর তৈরি এবং অ্যাপ-তৈরি কার্ড উভয়ই একটি ফাংশন আপডেট করে তা নিশ্চিত করতে, চ্যাট অ্যাপ বা ব্যবহারকারী মেসেজ তৈরি করেছেন কিনা তার উপর ভিত্তি করে গতিশীলভাবে ActionResponse সেট করুন।

  • যদি কোনো ব্যবহারকারী বার্তাটি তৈরি করে থাকেন, তাহলে ActionResponse কে UPDATE_USER_MESSAGE_CARDS এ সেট করুন।
  • যদি কোনো চ্যাট অ্যাপ বার্তাটি তৈরি করে, তাহলে ActionResponse UPDATE_MESSAGE এ সেট করুন।

এটি করার দুটি উপায় রয়েছে: সংযুক্ত কার্ডের onclick সম্পত্তির অংশ হিসাবে একটি কাস্টম actionMethodName নির্দিষ্ট করা এবং পরীক্ষা করা (যা বার্তাটিকে ব্যবহারকারীর তৈরি হিসাবে চিহ্নিত করে) বা বার্তাটি কোনও ব্যবহারকারী দ্বারা তৈরি করা হয়েছে কিনা তা পরীক্ষা করা৷

বিকল্প 1: actionMethodName চেক করুন

প্রিভিউ করা কার্ডে CARD_CLICKED ইন্টারঅ্যাকশন ইভেন্টগুলি সঠিকভাবে পরিচালনা করতে actionMethodName ব্যবহার করতে, সংযুক্ত কার্ডের onclick সম্পত্তির অংশ হিসাবে একটি কাস্টম actionMethodName সেট করুন:

JSON

. . . // Preview card details
{
  "textButton": {
    "text": "ASSIGN TO ME",
    "onClick": {

      // actionMethodName identifies the button to help determine the
      // appropriate ActionResponse.
      "action": {
        "actionMethodName": "assign",
      }
    }
  }
}
. . . // Preview card details

"actionMethodName": "assign" এর সাথে, একটি ম্যাচিং actionMethodName চেক করে গতিশীলভাবে সঠিক ActionResponse ফেরত দেওয়া সম্ভব:

Node.js

node/preview-link/update-card.js
/**
 * Responds to messages that have links whose URLs match URL patterns
 * configured for link previewing.
 *
 * @param {Object} req Request sent from Google Chat.
 * @param {Object} res Response to send back.
 */
exports.onMessage = (req, res) => {
  if (req.method === 'GET' || !req.body.message) {
    return res.send(
      'Hello! This function is meant to be used in a Google Chat Space.');
  }

  // Respond to button clicks on attached cards
  if (req.body.type === 'CARD_CLICKED') {
    // Checks for the presence of "actionMethodName": "assign" and sets
    // actionResponse.type to "UPDATE_USER"MESSAGE_CARDS" if present or
    // "UPDATE_MESSAGE" if absent.
    const actionResponseType = req.body.action.actionMethodName === 'assign' ?
      'UPDATE_USER_MESSAGE_CARDS' :
      'UPDATE_MESSAGE';

    if (req.body.action.actionMethodName === 'assign') {
      return res.json({
        'actionResponse': {

          // Dynamically returns the correct actionResponse type.
          'type': actionResponseType,
        },

        // Preview card details
        'cardsV2': [{}],
      });
    }
  }
};

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

এই উদাহরণ কার্ড JSON ফেরত দিয়ে একটি কার্ড বার্তা পাঠায়। আপনি Apps স্ক্রিপ্ট কার্ড পরিষেবাও ব্যবহার করতে পারেন৷

apps-script/preview-link/update-card.gs
/**
 * Updates a card that was attached to a message with a previewed link.
 *
 * @param {Object} event The event object from Chat API.
 * @return {Object} Response from the Chat app. Either a new card attached to
 * the message with the previewed link, or an update to an existing card.
 */
function onCardClick(event) {
  // Checks for the presence of "actionMethodName": "assign" and sets
  // actionResponse.type to "UPDATE_USER"MESSAGE_CARDS" if present or
  // "UPDATE_MESSAGE" if absent.
  const actionResponseType = event.action.actionMethodName === 'assign' ?
    'UPDATE_USER_MESSAGE_CARDS' :
    'UPDATE_MESSAGE';

  if (event.action.actionMethodName === 'assign') {
    return assignCase(actionResponseType);
  }
}

/**
 * Updates a card to say that "You" are the assignee after clicking the Assign
 * to Me button.
 *
 * @param {String} actionResponseType Which actionResponse the Chat app should
 * use to update the attached card based on who created the message.
 * @return {Object} Response from the Chat app. Updates the card attached to
 * the message with the previewed link.
 */
function assignCase(actionResponseType) {
  return {
    'actionResponse': {

      // Dynamically returns the correct actionResponse type.
      'type': actionResponseType,
    },
    // Preview card details
    'cardsV2': [{}],
  };
}

বিকল্প 2: প্রেরকের ধরন পরীক্ষা করুন

message.sender.type HUMAN বা BOT কিনা তা পরীক্ষা করে দেখুন। HUMAN হলে, ActionResponse UPDATE_USER_MESSAGE_CARDS এ সেট করুন, অন্যথায় ActionResponse UPDATE_MESSAGE এ সেট করুন। এখানে কিভাবে:

Node.js

node/preview-link/sender-type.js
/**
 * Responds to messages that have links whose URLs match URL patterns
 * configured for link previewing.
 *
 * @param {Object} req Request sent from Google Chat.
 * @param {Object} res Response to send back.
 */
exports.onMessage = (req, res) => {
  if (req.method === 'GET' || !req.body.message) {
    return res.send(
      'Hello! This function is meant to be used in a Google Chat Space.');
  }

  // Respond to button clicks on attached cards
  if (req.body.type === 'CARD_CLICKED') {
    // Checks whether the message event originated from a human or a Chat app
    // and sets actionResponse.type to "UPDATE_USER_MESSAGE_CARDS if human or
    // "UPDATE_MESSAGE" if Chat app.
    const actionResponseType = req.body.action.actionMethodName === 'HUMAN' ?
      'UPDATE_USER_MESSAGE_CARDS' :
      'UPDATE_MESSAGE';

    return res.json({
      'actionResponse': {

        // Dynamically returns the correct actionResponse type.
        'type': actionResponseType,
      },

      // Preview card details
      'cardsV2': [{}],
    });
  }
};

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

এই উদাহরণ কার্ড JSON ফেরত দিয়ে একটি কার্ড বার্তা পাঠায়। আপনি Apps স্ক্রিপ্ট কার্ড পরিষেবাও ব্যবহার করতে পারেন৷

apps-script/preview-link/sender-type.gs
/**
 * Updates a card that was attached to a message with a previewed link.
 *
 * @param {Object} event The event object from Chat API.
 * @return {Object} Response from the Chat app. Either a new card attached to
 * the message with the previewed link, or an update to an existing card.
 */
function onCardClick(event) {
  // Checks whether the message event originated from a human or a Chat app
  // and sets actionResponse.type to "UPDATE_USER_MESSAGE_CARDS if human or
  // "UPDATE_MESSAGE" if Chat app.
  const actionResponseType = event.message.sender.type === 'HUMAN' ?
    'UPDATE_USER_MESSAGE_CARDS' :
    'UPDATE_MESSAGE';

  return assignCase(actionResponseType);
}

/**
 * Updates a card to say that "You" are the assignee after clicking the Assign
 * to Me button.
 *
 * @param {String} actionResponseType Which actionResponse the Chat app should
 * use to update the attached card based on who created the message.
 * @return {Object} Response from the Chat app. Updates the card attached to
 * the message with the previewed link.
 */
function assignCase(actionResponseType) {
  return {
    'actionResponse': {

      // Dynamically returns the correct actionResponse type.
      'type': actionResponseType,
    },
    // Preview card details
    'cardsV2': [{}],
  };
}

একটি কার্ড আপডেট করার একটি সাধারণ কারণ হল একটি বোতাম ক্লিকের প্রতিক্রিয়া। পূর্ববর্তী বিভাগ থেকে আমাকে বরাদ্দ করুন বোতামটি স্মরণ করুন, একটি কার্ড সংযুক্ত করুন । নীচের সম্পূর্ণ উদাহরণটি কার্ডটিকে আপডেট করে যাতে এটি বলে যে এটি "আপনি"-কে অ্যাসাইন করা হয়েছে একজন ব্যবহারকারী আমাকে অ্যাসাইন টু ক্লিক করার পরে৷ উদাহরণটি প্রেরকের ধরন পরীক্ষা করে গতিশীলভাবে ActionResponse সেট করে।

সম্পূর্ণ উদাহরণ: Case-y গ্রাহক পরিষেবা চ্যাট অ্যাপ

এখানে Case-y-এর সম্পূর্ণ কোড দেওয়া হল, একটি চ্যাট অ্যাপ যা গ্রাহক পরিষেবা এজেন্টদের সহযোগিতা করে এমন একটি চ্যাট স্পেসে শেয়ার করা কেসগুলির লিঙ্কগুলির পূর্বরূপ দেখায়।

Node.js

node/preview-link/preview-link.js
/**
 * Responds to messages that have links whose URLs match URL patterns
 * configured for link previewing.
 *
 * @param {Object} req Request sent from Google Chat.
 * @param {Object} res Response to send back.
 */
exports.onMessage = (req, res) => {
  if (req.method === 'GET' || !req.body.message) {
    return res.send(
      'Hello! This function is meant to be used in a Google Chat Space.');
  }

  // Respond to button clicks on attached cards
  if (req.body.type === 'CARD_CLICKED') {
    // Checks whether the message event originated from a human or a Chat app
    // and sets actionResponse.type to "UPDATE_USER_MESSAGE_CARDS if human or
    // "UPDATE_MESSAGE" if Chat app.
    const actionResponseType = req.body.action.actionMethodName === 'HUMAN' ?
      'UPDATE_USER_MESSAGE_CARDS' :
      'UPDATE_MESSAGE';

    if (req.body.action.actionMethodName === 'assign') {
      return res.json(createMessage(actionResponseType, 'You'));
    }
  }

  // Checks for the presence of event.message.matchedUrl and attaches a card
  // if present
  if (req.body.message.matchedUrl) {
    return res.json(createMessage());
  }

  // If the Chat app doesn’t detect a link preview URL pattern, it says so.
  return res.json({'text': 'No matchedUrl detected.'});
};

/**
 * Message to create a card with the correct response type and assignee.
 *
 * @param {string} actionResponseType
 * @param {string} assignee
 * @return {Object} a card with URL preview
 */
function createMessage(
  actionResponseType = 'UPDATE_USER_MESSAGE_CARDS',
  assignee = 'Charlie'
) {
  return {
    'actionResponse': {'type': actionResponseType},
    'cardsV2': [
      {
        'cardId': 'previewLink',
        'card': {
          'header': {
            'title': 'Example Customer Service Case',
            'subtitle': 'Case basics',
          },
          'sections': [
            {
              'widgets': [
                {'keyValue': {'topLabel': 'Case ID', 'content': 'case123'}},
                {'keyValue': {'topLabel': 'Assignee', 'content': assignee}},
                {'keyValue': {'topLabel': 'Status', 'content': 'Open'}},
                {
                  'keyValue': {
                    'topLabel': 'Subject', 'content': 'It won"t turn on...',
                  },
                },
              ],
            },
            {
              'widgets': [
                {
                  'buttons': [
                    {
                      'textButton': {
                        'text': 'OPEN CASE',
                        'onClick': {
                          'openLink': {
                            'url': 'https://support.example.com/orders/case123',
                          },
                        },
                      },
                    },
                    {
                      'textButton': {
                        'text': 'RESOLVE CASE',
                        'onClick': {
                          'openLink': {
                            'url': 'https://support.example.com/orders/case123?resolved=y',
                          },
                        },
                      },
                    },
                    {
                      'textButton': {
                        'text': 'ASSIGN TO ME',
                        'onClick': {
                          'action': {
                            'actionMethodName': 'assign',
                          },
                        },
                      },
                    },
                  ],
                },
              ],
            },
          ],
        }
      },
    ],
  };
}

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

এই উদাহরণ কার্ড JSON ফেরত দিয়ে একটি কার্ড বার্তা পাঠায়। আপনি Apps স্ক্রিপ্ট কার্ড পরিষেবাও ব্যবহার করতে পারেন৷

apps-script/preview-link/preview-link.gs
/**
 * Responds to messages that have links whose URLs match URL patterns
 * configured for link previews.
 *
 * @param {Object} event The event object from Chat API.
 * @return {Object} Response from the Chat app attached to the message with
 * the previewed link.
 */
function onMessage(event) {
  // Checks for the presence of event.message.matchedUrl and attaches a card
  // if present
  if (event.message.matchedUrl) {
    return {
      'actionResponse': {
        'type': 'UPDATE_USER_MESSAGE_CARDS',
      },
      'cardsV2': [{
        'cardId': 'previewLink',
        'card': {
          'header': {
            'title': 'Example Customer Service Case',
            'subtitle': 'Case basics',
          },
          'sections': [{
            'widgets': [
              {'keyValue': {'topLabel': 'Case ID', 'content': 'case123'}},
              {'keyValue': {'topLabel': 'Assignee', 'content': 'Charlie'}},
              {'keyValue': {'topLabel': 'Status', 'content': 'Open'}},
              {
                'keyValue': {
                  'topLabel': 'Subject', 'content': 'It won\'t turn on...',
                }
              },
            ],
          },
          {
            'widgets': [{
              'buttons': [
                {
                  'textButton': {
                    'text': 'OPEN CASE',
                    'onClick': {
                      'openLink': {
                        'url': 'https://support.example.com/orders/case123',
                      },
                    },
                  },
                },
                {
                  'textButton': {
                    'text': 'RESOLVE CASE',
                    'onClick': {
                      'openLink': {
                        'url': 'https://support.example.com/orders/case123?resolved=y',
                      },
                    },
                  },
                },
                {
                  'textButton': {
                    'text': 'ASSIGN TO ME',
                    'onClick': {'action': {'actionMethodName': 'assign'}}
                  },
                },
              ],
            }],
          }],
        },
      }],
    };
  }

  // If the Chat app doesn’t detect a link preview URL pattern, it says so.
  return {'text': 'No matchedUrl detected.'};
}

/**
 * Updates a card that was attached to a message with a previewed link.
 *
 * @param {Object} event The event object from Chat API.
 * @return {Object} Response from the Chat app. Either a new card attached to
 * the message with the previewed link, or an update to an existing card.
 */
function onCardClick(event) {
  // Checks whether the message event originated from a human or a Chat app
  // and sets actionResponse to "UPDATE_USER_MESSAGE_CARDS if human or
  // "UPDATE_MESSAGE" if Chat app.
  const actionResponseType = event.message.sender.type === 'HUMAN' ?
    'UPDATE_USER_MESSAGE_CARDS' :
    'UPDATE_MESSAGE';

  // To respond to the correct button, checks the button's actionMethodName.
  if (event.action.actionMethodName === 'assign') {
    return assignCase(actionResponseType);
  }
}

/**
 * Updates a card to say that "You" are the assignee after clicking the Assign
 * to Me button.
 *
 * @param {String} actionResponseType Which actionResponse the Chat app should
 * use to update the attached card based on who created the message.
 * @return {Object} Response from the Chat app. Updates the card attached to
 * the message with the previewed link.
 */
function assignCase(actionResponseType) {
  return {
    'actionResponse': {

      // Dynamically returns the correct actionResponse type.
      'type': actionResponseType,
    },
    'cardsV2': [{
      'cardId': 'assignCase',
      'card': {
        'header': {
          'title': 'Example Customer Service Case',
          'subtitle': 'Case basics',
        },
        'sections': [{
          'widgets': [
            {'keyValue': {'topLabel': 'Case ID', 'content': 'case123'}},
            {'keyValue': {'topLabel': 'Assignee', 'content': 'You'}},
            {'keyValue': {'topLabel': 'Status', 'content': 'Open'}},
            {
              'keyValue': {
                'topLabel': 'Subject', 'content': 'It won\'t turn on...',
              }
            },
          ],
        },
        {
          'widgets': [{
            'buttons': [
              {
                'textButton': {
                  'text': 'OPEN CASE',
                  'onClick': {
                    'openLink': {
                      'url': 'https://support.example.com/orders/case123',
                    },
                  },
                },
              },
              {
                'textButton': {
                  'text': 'RESOLVE CASE',
                  'onClick': {
                    'openLink': {
                      'url': 'https://support.example.com/orders/case123?resolved=y',
                    },
                  },
                },
              },
              {
                'textButton': {
                  'text': 'ASSIGN TO ME',
                  'onClick': {'action': {'actionMethodName': 'assign'}},
                },
              },
            ],
          }],
        }],
      },
    }],
  };
}

সীমা এবং বিবেচনা

আপনি আপনার চ্যাট অ্যাপের জন্য লিঙ্ক প্রিভিউ কনফিগার করার সময়, এই সীমা এবং বিবেচনাগুলি নোট করুন:

  • প্রতিটি চ্যাট অ্যাপ 5টি পর্যন্ত URL প্যাটার্নের জন্য লিঙ্ক প্রিভিউ সমর্থন করে।
  • চ্যাট অ্যাপস প্রতি বার্তা প্রতি একটি লিঙ্কের পূর্বরূপ। যদি একাধিক পূর্বদর্শনযোগ্য লিঙ্ক একটি একক বার্তায় উপস্থিত থাকে, তবে শুধুমাত্র প্রথম পূর্বদর্শনযোগ্য লিঙ্কের পূর্বরূপ।
  • চ্যাট অ্যাপগুলি শুধুমাত্র https:// দিয়ে শুরু হওয়া লিঙ্কগুলির পূর্বরূপ দেখায়, তাই https://support.example.com/cases/ previews, কিন্তু support.example.com/cases/ করে না৷
  • স্ল্যাশ কমান্ডের মতো চ্যাট অ্যাপে পাঠানো অন্যান্য তথ্য বার্তাটিতে না থাকলে, শুধুমাত্র লিঙ্কের ইউআরএলটি চ্যাট অ্যাপে লিঙ্ক প্রিভিউ দ্বারা পাঠানো হয়।
  • প্রিভিউ করা লিঙ্কগুলির সাথে সংযুক্ত কার্ডগুলি শুধুমাত্র UPDATE_USER_MESSAGE_CARDS ধরনের একটি ActionResponse সমর্থন করে এবং শুধুমাত্র একটি চ্যাট অ্যাপ ইন্টারঅ্যাকশন ইভেন্টের প্রতিক্রিয়ায়। লিঙ্কের পূর্বরূপগুলি UPDATE_MESSAGE বা চ্যাট API এর মাধ্যমে একটি পূর্বরূপ দেখা লিঙ্কের সাথে সংযুক্ত কার্ড আপডেট করার জন্য অ্যাসিঙ্ক্রোনাস অনুরোধগুলিকে সমর্থন করে না৷ আরও জানতে, একটি কার্ড আপডেট করুন দেখুন।

আপনি লিঙ্ক প্রিভিউ প্রয়োগ করার সময়, আপনাকে অ্যাপের লগ পড়ে আপনার চ্যাট অ্যাপ ডিবাগ করতে হতে পারে। লগগুলি পড়তে, Google ক্লাউড কনসোলে লগ এক্সপ্লোরারে যান৷