রচনা ক্রিয়া সহ রচনা UI প্রসারিত করা

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

অ্যাড-অন কম্পোজ UI অ্যাক্সেস করা হচ্ছে

একটি অ্যাড-অনের কম্পোজ UI দেখার দুটি উপায় আছে। প্রথম উপায় হল অ্যাড-অনটি খোলা থাকা অবস্থায় একটি নতুন খসড়া রচনা করা বা উত্তর দেওয়া শুরু করা। দ্বিতীয় উপায় হল একটি খসড়া রচনা করার সময় অ্যাড-অনটি শুরু করা।

যেকোনো ক্ষেত্রেই অ্যাড-অনটি অ্যাড-অন ম্যানিফেস্টে সংজ্ঞায়িত সংশ্লিষ্ট কম্পোজ ট্রিগার ফাংশনটি কার্যকর করে। কম্পোজ ট্রিগার ফাংশনটি সেই কম্পোজ অ্যাকশনের জন্য কম্পোজ UI তৈরি করে, যা Gmail ব্যবহারকারীকে প্রদর্শন করে।

একটি কম্পোজ অ্যাড-অন তৈরি করা হচ্ছে

আপনি এই সাধারণ পদক্ষেপগুলি অনুসরণ করে একটি অ্যাড-অনে রচনা কার্যকারিতা যোগ করতে পারেন:

  1. অ্যাড-অন স্ক্রিপ্ট প্রজেক্ট ম্যানিফেস্টে gmail.composeTrigger ফিল্ড যোগ করুন এবং কম্পোজ অ্যাকশনের জন্য প্রয়োজনীয় স্কোপগুলি অন্তর্ভুক্ত করার জন্য ম্যানিফেস্ট স্কোপগুলি আপডেট করুন।
  2. একটি কম্পোজ ট্রিগার ফাংশন বাস্তবায়ন করে যা ট্রিগার চালু হলে একটি কম্পোজ UI তৈরি করে। কম্পোজ ট্রিগার ফাংশনগুলি একটি একক Card অবজেক্ট অথবা Card অবজেক্টের একটি অ্যারে প্রদান করে যা কম্পোজ অ্যাকশনের জন্য কম্পোজ UI ধারণ করে।
  3. ব্যবহারকারীর কম্পোজ UI ইন্টারঅ্যাকশনের প্রতিক্রিয়া জানাতে প্রয়োজনীয় অ্যাসোসিয়েটেড কলব্যাক ফাংশনগুলি বাস্তবায়ন করুন। এই ফাংশনগুলি কম্পোজ অ্যাকশন নয় (যার ফলে শুধুমাত্র কম্পোজ UI প্রদর্শিত হয়); বরং, এগুলি হল পৃথক ফাংশন যা কম্পোজ UI এর বিভিন্ন উপাদান নির্বাচন করা হলে কী ঘটে তা নিয়ন্ত্রণ করে। উদাহরণস্বরূপ, একটি বোতামযুক্ত UI কার্ডে সাধারণত একটি অ্যাসোসিয়েটেড কলব্যাক ফাংশন থাকে যা ব্যবহারকারী যখন সেই বোতামে ক্লিক করেন তখন কার্যকর হয়। ড্রাফ্ট বার্তার সামগ্রী আপডেট করে এমন উইজেটগুলির জন্য কলব্যাক ফাংশনটি একটি UpdateDraftActionResponse অবজেক্ট ফেরত পাঠাবে।

কম্পোজ ট্রিগার ফাংশন

একটি অ্যাড-অনের কম্পোজ UI অ্যাড-অনের মেসেজ UI এর মতোই তৈরি করা হয়—অ্যাপস স্ক্রিপ্ট কার্ড পরিষেবা ব্যবহার করে কার্ড তৈরি করা এবং উইজেট দিয়ে পূরণ করা।

আপনার ম্যানিফেস্টে সংজ্ঞায়িত gmail.composeTrigger.selectActions[].runFunction বাস্তবায়ন করতে হবে। কম্পোজ ট্রিগার ফাংশনটি অবশ্যই একটি একক Card অবজেক্ট অথবা সেই অ্যাকশনের জন্য কম্পোজ UI ধারণকারী Card অবজেক্টের একটি অ্যারে ফেরত পাঠাবে। এই ফাংশনগুলি প্রাসঙ্গিক ট্রিগার ফাংশনের মতোই এবং একইভাবে কার্ড তৈরি করা উচিত।

ইভেন্ট অবজেক্ট ট্রিগার করুন

যখন একটি কম্পোজ অ্যাকশন নির্বাচন করা হয়, তখন এটি সংশ্লিষ্ট কম্পোজ ট্রিগার ফাংশনটি কার্যকর করে এবং ফাংশনটিকে একটি ইভেন্ট অবজেক্টকে প্যারামিটার হিসেবে পাস করে। ইভেন্ট অবজেক্টটি অ্যাড-অন প্রসঙ্গ এবং ট্রিগার ফাংশনে তৈরি করা খসড়া সম্পর্কে তথ্য বহন করতে পারে।

ইভেন্ট অবজেক্টে তথ্য কীভাবে সাজানো হয় তার বিস্তারিত জানার জন্য ইভেন্ট অবজেক্টের কাঠামো দেখুন। ইভেন্ট অবজেক্টে থাকা তথ্য আংশিকভাবে gmail.composeTrigger.draftAccess ম্যানিফেস্ট ক্ষেত্রের মান দ্বারা নিয়ন্ত্রিত হয়:

  • যদি gmail.composeTrigger.draftAccess ম্যানিফেস্ট ফিল্ডটি NONE হয় বা অন্তর্ভুক্ত না থাকে, তাহলে ইভেন্ট অবজেক্টে খুব কম তথ্য থাকবে।

  • যদি gmail.composeTrigger.draftAccess METADATA তে সেট করা থাকে, তাহলে compose trigger ফাংশনে পাঠানো ইভেন্ট অবজেক্টটি তৈরি করা ইমেলের প্রাপকদের তালিকা দিয়ে পূর্ণ হবে।

সক্রিয় খসড়াগুলিতে বিষয়বস্তু সন্নিবেশ করানো

সাধারণত একটি Google Workspace অ্যাড-অন কম্পোজ UI ব্যবহারকারীদের জন্য বার্তা রচনা করতে সাহায্য করার জন্য বিকল্প এবং নিয়ন্ত্রণ প্রদান করে। এই ব্যবহারের ক্ষেত্রে, ব্যবহারকারী UI-তে নির্বাচন করার পরে অ্যাড-অন নির্বাচনগুলি ব্যাখ্যা করে এবং সেই অনুযায়ী বর্তমান কার্যকরী ইমেল খসড়া আপডেট করে।

বর্তমান খসড়া ইমেল আপডেট করা সহজ করার জন্য, কার্ড পরিষেবাটি নিম্নলিখিত ক্লাসগুলির সাথে সম্প্রসারিত করা হয়েছে:

  • ContentType — একটি enum যা পরিবর্তনযোগ্য HTML, অপরিবর্তনীয় HTML (যা Gmail ব্যবহারকারীরা সম্পাদনা করতে পারবেন না), নাকি প্লেইন টেক্সট কন্টেন্ট যোগ করবেন তা নির্ধারণ করে।
  • UpdateDraftActionResponse — বর্তমান খসড়া ইমেল আপডেট করে এমন একটি অ্যাকশনের প্রতিক্রিয়া প্রতিনিধিত্ব করে।
  • UpdateDraftActionResponseBuilderUpdateDraftActionResponse অবজেক্টের জন্য একটি বিল্ডার।
  • UpdateDraftBodyAction — এমন একটি ক্রিয়া প্রতিনিধিত্ব করে যা বর্তমান খসড়া ইমেলের মূল অংশ আপডেট করে।
  • UpdateDraftBodyType — একটি এনাম যা শরীর কীভাবে পরিবর্তিত হয় তা নির্ধারণ করে।
  • UpdateDraftSubjectAction — বর্তমান খসড়া ইমেলের বিষয় ক্ষেত্র আপডেট করে এমন একটি ক্রিয়া প্রতিনিধিত্ব করে।
  • UpdateDraftToRecipientsAction — এমন একটি ক্রিয়া প্রতিনিধিত্ব করে যা বর্তমান খসড়া ইমেলের প্রাপকদের আপডেট করে।
  • UpdateDraftCcRecipientsAction — বর্তমান খসড়া ইমেলের Cc প্রাপকদের আপডেট করার জন্য একটি ক্রিয়া প্রতিনিধিত্ব করে।
  • UpdateDraftBccRecipientsAction — বর্তমান খসড়া ইমেলের Bcc প্রাপকদের আপডেট করার জন্য একটি ক্রিয়া উপস্থাপন করে।

সাধারণত একটি অ্যাড-অন কম্পোজ UI-তে একটি 'সংরক্ষণ করুন' বা 'সন্নিবেশ করুন' উইজেট থাকে যা ব্যবহারকারী ক্লিক করে বোঝাতে পারেন যে তারা UI-তে নির্বাচন করা শেষ করেছেন এবং তাদের পছন্দগুলি তারা যে ইমেলটি রচনা করছেন তাতে যোগ করতে চান। এই ইন্টারঅ্যাক্টিভিটি যোগ করার জন্য, উইজেটের একটি সংযুক্ত Action অবজেক্ট থাকা উচিত যা উইজেটটি ক্লিক করার সময় অ্যাড-অনকে একটি নির্দিষ্ট কলব্যাক ফাংশন চালানোর নির্দেশ দেয়। আপনাকে এই কলব্যাক ফাংশনগুলি বাস্তবায়ন করতে হবে। প্রতিটি কলব্যাক ফাংশনের একটি বিল্ট-ইন UpdateDraftActionResponse অবজেক্ট ফেরত দেওয়া উচিত যা বর্তমান খসড়া ইমেলে করা পরিবর্তনগুলির বিবরণ দেয়।

উদাহরণ ১

নিম্নলিখিত কোড স্নিপেটটি দেখায় যে কীভাবে একটি কম্পোজ UI তৈরি করতে হয় যা বর্তমান ইমেল খসড়ার বিষয় এবং To, Cc, Bcc প্রাপকদের আপডেট করে।

    /**
     * Compose trigger function that fires when the compose UI is
     * requested. Builds and returns a compose UI for inserting images.
     *
     * @param {event} e The compose trigger event object. Not used in
     *         this example.
     * @return {Card[]}
     */
    function getComposeUI(e) {
      return [buildComposeCard()];
    }

    /**
     * Build a card to display interactive buttons to allow the user to
     * update the subject, and To, Cc, Bcc recipients.
     *
     * @return {Card}
     */
    function buildComposeCard() {

      var card = CardService.newCardBuilder();
      var cardSection = CardService.newCardSection().setHeader('Update email');
      cardSection.addWidget(
          CardService.newTextButton()
              .setText('Update subject')
              .setOnClickAction(CardService.newAction()
                  .setFunctionName('applyUpdateSubjectAction')));
      cardSection.addWidget(
          CardService.newTextButton()
              .setText('Update To recipients')
              .setOnClickAction(CardService.newAction()
                  .setFunctionName('updateToRecipients')));
      cardSection.addWidget(
          CardService.newTextButton()
              .setText('Update Cc recipients')
              .setOnClickAction(CardService.newAction()
                  .setFunctionName('updateCcRecipients')));
      cardSection.addWidget(
          CardService.newTextButton()
              .setText('Update Bcc recipients')
              .setOnClickAction(CardService.newAction()
                  .setFunctionName('updateBccRecipients')));
      return card.addSection(cardSection).build();
    }

    /**
     * Updates the subject field of the current email when the user clicks
     * on "Update subject" in the compose UI.
     *
     * Note: This is not the compose action that builds a compose UI, but
     * rather an action taken when the user interacts with the compose UI.
     *
     * @return {UpdateDraftActionResponse}
     */
    function applyUpdateSubjectAction() {
      // Get the new subject field of the email.
      // This function is not shown in this example.
      var subject = getSubject();
      var response = CardService.newUpdateDraftActionResponseBuilder()
          .setUpdateDraftSubjectAction(CardService.newUpdateDraftSubjectAction()
              .addUpdateSubject(subject))
          .build();
      return response;
    }

    /**
     * Updates the To recipients of the current email when the user clicks
     * on "Update To recipients" in the compose UI.
     *
     * Note: This is not the compose action that builds a compose UI, but
     * rather an action taken when the user interacts with the compose UI.
     *
     * @return {UpdateDraftActionResponse}
     */
    function applyUpdateToRecipientsAction() {
      // Get the new To recipients of the email.
      // This function is not shown in this example.
      var toRecipients = getToRecipients();
      var response = CardService.newUpdateDraftActionResponseBuilder()
          .setUpdateDraftToRecipientsAction(CardService.newUpdateDraftToRecipientsAction()
              .addUpdateToRecipients(toRecipients))
          .build();
      return response;
    }

    /**
     * Updates the Cc recipients  of the current email when the user clicks
     * on "Update Cc recipients" in the compose UI.
     *
     * Note: This is not the compose action that builds a compose UI, but
     * rather an action taken when the user interacts with the compose UI.
     *
     * @return {UpdateDraftActionResponse}
     */
    function applyUpdateCcRecipientsAction() {
      // Get the new Cc recipients of the email.
      // This function is not shown in this example.
      var ccRecipients = getCcRecipients();
      var response = CardService.newUpdateDraftActionResponseBuilder()
          .setUpdateDraftCcRecipientsAction(CardService.newUpdateDraftCcRecipientsAction()
              .addUpdateToRecipients(ccRecipients))
          .build();
      return response;
    }

    /**
     * Updates the Bcc recipients  of the current email when the user clicks
     * on "Update Bcc recipients" in the compose UI.
     *
     * Note: This is not the compose action that builds a compose UI, but
     * rather an action taken when the user interacts with the compose UI.
     *
     * @return {UpdateDraftActionResponse}
     */
    function applyUpdateBccRecipientsAction() {
      // Get the new Bcc recipients of the email.
      // This function is not shown in this example.
      var bccRecipients = getBccRecipients();
      var response = CardService.newUpdateDraftActionResponseBuilder()
          .setUpdateDraftBccRecipientsAction(CardService.newUpdateDraftBccRecipientsAction()
              .addUpdateToRecipients(bccRecipients))
          .build();
      return response;
    }

উদাহরণ ২

নিম্নলিখিত কোড স্নিপেটটি দেখায় কিভাবে একটি কম্পোজ UI তৈরি করতে হয় যা বর্তমান খসড়া ইমেলে ছবি সন্নিবেশ করে।

    /**
     * Compose trigger function that fires when the compose UI is
     * requested. Builds and returns a compose UI for inserting images.
     *
     * @param {event} e The compose trigger event object. Not used in
     *         this example.
     * @return {Card[]}
     */
    function getInsertImageComposeUI(e) {
      return [buildImageComposeCard()];
    }

    /**
     * Build a card to display images from a third-party source.
     *
     * @return {Card}
     */
    function buildImageComposeCard() {
      // Get a short list of image URLs to display in the UI.
      // This function is not shown in this example.
      var imageUrls = getImageUrls();

      var card = CardService.newCardBuilder();
      var cardSection = CardService.newCardSection().setHeader('My Images');
      for (var i = 0; i < imageUrls.length; i++) {
        var imageUrl = imageUrls[i];
        cardSection.addWidget(
            CardService.newImage()
                .setImageUrl(imageUrl)
                .setOnClickAction(CardService.newAction()
                      .setFunctionName('applyInsertImageAction')
                      .setParameters({'url' : imageUrl})));
      }
      return card.addSection(cardSection).build();
    }

    /**
     * Adds an image to the current draft email when the image is clicked
     * in the compose UI. The image is inserted at the current cursor
     * location. If any content of the email draft is currently selected,
     * it is deleted and replaced with the image.
     *
     * Note: This is not the compose action that builds a compose UI, but
     * rather an action taken when the user interacts with the compose UI.
     *
     * @param {event} e The incoming event object.
     * @return {UpdateDraftActionResponse}
     */
    function applyInsertImageAction(e) {
      var imageUrl = e.parameters.url;
      var imageHtmlContent = '<img style=\"display: block\" src=\"'
           + imageUrl + '\"/>';
      var response = CardService.newUpdateDraftActionResponseBuilder()
          .setUpdateDraftBodyAction(CardService.newUpdateDraftBodyAction()
              .addUpdateContent(
                  imageHtmlContent,
                  CardService.ContentType.MUTABLE_HTML)
              .setUpdateType(
                  CardService.UpdateDraftBodyType.IN_PLACE_INSERT))
          .build();
      return response;
    }