मीटिंग के लिए एजेंडा बनाएं

कोडिंग का लेवल: शुरुआती
कुल समय: 15 मिनट
प्रोजेक्ट टाइप: इवेंट से ट्रिगर होने वाले ट्रिगर के साथ ऑटोमेशन की सुविधा

मकसद

  • जानें कि समस्या को हल करने से क्या होता है.
  • समझें कि Apps Script सेवाएं, इस सॉल्यूशन के हिसाब से क्या करती हैं.
  • स्क्रिप्ट सेट अप करें.
  • स्क्रिप्ट चलाएं.

इस सलूशन के बारे में जानकारी

Google Docs में अपने-आप एजेंडा दस्तावेज़ बनाएं और उन्हें Google Calendar की मीटिंग में अटैच करें.

Calendar इवेंट में, एजेंडा का स्क्रीनशॉट जोड़ा गया

यह सुविधा कैसे काम करती है

स्क्रिप्ट किसी एजेंडा के लिए दस्तावेज़ का टेंप्लेट बनाती है. कैलेंडर अपडेट करने पर, स्क्रिप्ट यह जांच करती है कि आपके मालिकाना हक वाले किसी इवेंट के ब्यौरे में "#agenda" शामिल है या नहीं. अगर टैग मौजूद होता है, तो स्क्रिप्ट टेंप्लेट की एक कॉपी बनाती है, उसे कैलेंडर इवेंट में जोड़ती है, और उसे इवेंट के मेहमानों के साथ शेयर करती है.

Apps Script सेवाएं

यह समाधान नीचे दी गई सेवाओं का इस्तेमाल करता है:

  • Drive सेवा– इससे यह जांच की जाती है कि टेंप्लेट दस्तावेज़ मौजूद है या नहीं. अगर नहीं है, तो टेंप्लेट दस्तावेज़ के लिए एक नया फ़ोल्डर बना दिया जाता है. हर नए एजेंडा के लिए, टेंप्लेट दस्तावेज़ की कॉपी बनाता है.
  • दस्तावेज़ सेवा– एजेंडा टेंप्लेट बनाता है.
  • कैलेंडर सेवा–"#agenda" टैग वाले इवेंट की जांच करता है और एजेंडा दस्तावेज़ के लिंक के साथ इवेंट की जानकारी अपडेट करता है.
  • बुनियादी सेवा–यह उपयोगकर्ता के ईमेल पाने के लिए, Session क्लास का इस्तेमाल करती है. इससे मौजूदा उपयोगकर्ता के लिए ट्रिगर बनाने में मदद मिलती है.
  • स्क्रिप्ट सेवा–उपयोगकर्ता के कैलेंडर में कोई भी बदलाव होने पर, ट्रिगर करने वाला ट्रिगर बनाया जाता है.

ज़रूरी शर्तें

इस सैंपल का इस्तेमाल करने के लिए, आपको ये शर्तें पूरी करनी होंगी:

  • Google खाता (Google Workspace खातों के लिए एडमिन की अनुमति की ज़रूरत पड़ सकती है).
  • इंटरनेट ऐक्सेस करने वाला वेब ब्राउज़र.

स्क्रिप्ट सेट अप करें

  1. नीचे दिए गए बटन पर क्लिक करके, मीटिंग के लिए एजेंडा बनाएं Apps Script प्रोजेक्ट का सैंपल खोलें.
    प्रोजेक्ट खोलें
  2. खास जानकारी पर क्लिक करें.
  3. खास जानकारी देने वाले पेज पर, 'कॉपी बनाएं' कॉपी बनाने के लिए आइकॉन पर क्लिक करें.
  4. कॉपी किए गए प्रोजेक्ट में, फ़ंक्शन ड्रॉपडाउन में, setUp चुनें.
  5. चलाएं पर क्लिक करें.
  6. जब कहा जाए, तब स्क्रिप्ट को अनुमति दें. अगर OAuth के लिए सहमति वाली स्क्रीन पर चेतावनी दिखती है, तो इस ऐप्लिकेशन की पुष्टि नहीं हुई है. बेहतर सेटिंग > को चुनकर जारी रखें {Project Name} पर जाएं (असुरक्षित).

स्क्रिप्ट चलाएं

  1. Google Calendar खोलें.
  2. कोई नया इवेंट बनाएं या किसी मौजूदा इवेंट में बदलाव करें.
  3. ब्यौरे में, #agenda जोड़ें और इवेंट सेव करें.
  4. ईमेल सूचना के लिए अपना ईमेल देखें कि आपके साथ दस्तावेज़ शेयर किया गया है या कैलेंडर को रीफ़्रेश करें और एजेंडा दस्तावेज़ का लिंक देखने के लिए इवेंट पर फिर से क्लिक करें.

सभी मेहमानों को एजेंडा देखने के लिए ईमेल सूचना मिलती है. स्क्रिप्ट मेहमानों को बदलाव करने की अनुमति देती है, लेकिन मेहमानों के लिए एजेंडा दस्तावेज़ की अनुमतियां अपडेट करने के लिए स्क्रिप्ट में बदलाव किया जा सकता है.

कोड की समीक्षा करें

इस सलूशन के Apps Script कोड की समीक्षा करने के लिए, नीचे सोर्स कोड देखें पर क्लिक करें:

सोर्स कोड देखें

Code.gs

solutions/automations/agenda-maker/Code.js
// To learn how to use this script, refer to the documentation:
// https://developers.google.com/apps-script/samples/automations/agenda-maker

/*
Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/**
 * Checks if the folder for Agenda docs exists, and creates it if it doesn't.
 *
 * @return {*} Drive folder ID for the app.
 */
function checkFolder() {
  const folders = DriveApp.getFoldersByName('Agenda Maker - App');
  // Finds the folder if it exists
  while (folders.hasNext()) {
    let folder = folders.next();
    if (
      folder.getDescription() ==
        'Apps Script App - Do not change this description' &&
      folder.getOwner().getEmail() == Session.getActiveUser().getEmail()
    ) {
      return folder.getId();
    }
  }
  // If the folder doesn't exist, creates one
  let folder = DriveApp.createFolder('Agenda Maker - App');
  folder.setDescription('Apps Script App - Do not change this description');
  return folder.getId();
}

/**
 * Finds the template agenda doc, or creates one if it doesn't exist.
 */
function getTemplateId(folderId) {
  const folder = DriveApp.getFolderById(folderId);
  const files = folder.getFilesByName('Agenda TEMPLATE##');

  // If there is a file, returns the ID.
  while (files.hasNext()) {
    const file = files.next();
    return file.getId();
  }

  // Otherwise, creates the agenda template.
  // You can adjust the default template here
  const doc = DocumentApp.create('Agenda TEMPLATE##');
  const body = doc.getBody();

  body
      .appendParagraph('##Attendees##')
      .setHeading(DocumentApp.ParagraphHeading.HEADING1)
      .editAsText()
      .setBold(true);
  body.appendParagraph(' ').editAsText().setBold(false);

  body
      .appendParagraph('Overview')
      .setHeading(DocumentApp.ParagraphHeading.HEADING1)
      .editAsText()
      .setBold(true);
  body.appendParagraph(' ');
  body.appendParagraph('- Topic 1: ').editAsText().setBold(true);
  body.appendParagraph(' ').editAsText().setBold(false);
  body.appendParagraph('- Topic 2: ').editAsText().setBold(true);
  body.appendParagraph(' ').editAsText().setBold(false);
  body.appendParagraph('- Topic 3: ').editAsText().setBold(true);
  body.appendParagraph(' ').editAsText().setBold(false);

  body
      .appendParagraph('Next Steps')
      .setHeading(DocumentApp.ParagraphHeading.HEADING1)
      .editAsText()
      .setBold(true);
  body.appendParagraph('- Takeaway 1: ').editAsText().setBold(true);
  body.appendParagraph('- Responsible: ').editAsText().setBold(false);
  body.appendParagraph('- Accountable: ');
  body.appendParagraph('- Consult: ');
  body.appendParagraph('- Inform: ');
  body.appendParagraph(' ');
  body.appendParagraph('- Takeaway 2: ').editAsText().setBold(true);
  body.appendParagraph('- Responsible: ').editAsText().setBold(false);
  body.appendParagraph('- Accountable: ');
  body.appendParagraph('- Consult: ');
  body.appendParagraph('- Inform: ');
  body.appendParagraph(' ');
  body.appendParagraph('- Takeaway 3: ').editAsText().setBold(true);
  body.appendParagraph('- Responsible: ').editAsText().setBold(false);
  body.appendParagraph('- Accountable: ');
  body.appendParagraph('- Consult: ');
  body.appendParagraph('- Inform: ');

  doc.saveAndClose();

  folder.addFile(DriveApp.getFileById(doc.getId()));

  return doc.getId();
}

/**
 * When there is a change to the calendar, searches for events that include "#agenda"
 * in the decrisption.
 *
 */
function onCalendarChange() {
  // Gets recent events with the #agenda tag
  const now = new Date();
  const events = CalendarApp.getEvents(
      now,
      new Date(now.getTime() + 2 * 60 * 60 * 1000000),
      {search: '#agenda'},
  );

  const folderId = checkFolder();
  const templateId = getTemplateId(folderId);

  const folder = DriveApp.getFolderById(folderId);

  // Loops through any events found
  for (i = 0; i < events.length; i++) {
    const event = events[i];

    // Confirms whether the event has the #agenda tag
    let description = event.getDescription();
    if (description.search('#agenda') == -1) continue;

    // Only works with events created by the owner of this calendar
    if (event.isOwnedByMe()) {
      // Creates a new document from the template for an agenda for this event
      const newDoc = DriveApp.getFileById(templateId).makeCopy();
      newDoc.setName('Agenda for ' + event.getTitle());

      const file = DriveApp.getFileById(newDoc.getId());
      folder.addFile(file);

      const doc = DocumentApp.openById(newDoc.getId());
      const body = doc.getBody();

      // Fills in the template with information about the attendees from the
      // calendar event
      const conf = body.findText('##Attendees##');
      if (conf) {
        const ref = conf.getStartOffset();

        for (let i in event.getGuestList()) {
          let guest = event.getGuestList()[i];

          body.insertParagraph(ref + 2, guest.getEmail());
        }
        body.replaceText('##Attendees##', 'Attendees');
      }

      // Replaces the tag with a link to the agenda document
      const agendaUrl = 'https://docs.google.com/document/d/' + newDoc.getId();
      description = description.replace(
          '#agenda',
          '<a href=' + agendaUrl + '>Agenda Doc</a>',
      );
      event.setDescription(description);

      // Invites attendees to the Google doc so they automatically receive access to the agenda
      newDoc.addEditor(newDoc.getOwner());

      for (let i in event.getGuestList()) {
        let guest = event.getGuestList()[i];

        newDoc.addEditor(guest.getEmail());
      }
    }
  }
  return;
}

/**
 * Creates an event-driven trigger that fires whenever there's a change to the calendar.
 */
function setUp() {
  let email = Session.getActiveUser().getEmail();
  ScriptApp.newTrigger("onCalendarChange").forUserCalendar(email).onEventUpdated().create();
}

बदलाव

सैंपल में, अपनी ज़रूरत के हिसाब से बदलाव किया जा सकता है. नीचे कुछ ऐसे बदलाव दिए गए हैं जो ज़रूरी नहीं हैं.

मेहमानों के लिए, एजेंडा दस्तावेज़ की अनुमतियां अपडेट करें

स्क्रिप्ट, मेहमानों को बदलाव करने की अनुमति देती है. अगर आपको सिर्फ़ अनुमतियों को सीमित तौर पर देखना है, तो कोड के इस हिस्से में, addEditor वाले तरीके को addViewer तरीके से बदलें:

     for (let i in event.getGuestList()) {
       let guest = event.getGuestList()[i];

       newDoc.addEditor(guest.getEmail());

एजेंडा दस्तावेज़ के टेंप्लेट में बदलाव करना

एजेंडा दस्तावेज़ के टेंप्लेट को अपडेट करने के लिए, यह तरीका अपनाएं:

  1. किसी कैलेंडर इवेंट में अपना पहला एजेंडा बनाने के बाद, Google Drive खोलें.
  2. Agenda Maker - ऐप्लिकेशन फ़ोल्डर खोलें.
  3. एजेंडा template## दस्तावेज़ खोलें और बदलाव करें.

योगदानकर्ता

यह नमूना, प्रॉडक्ट मैनेजमेंट और प्लैटफ़ॉर्म स्ट्रेटजी कंसल्टेंट, जेरेमी ग्लासनबर्ग ने बनाया है. @j Glassenberg पर Twitter पर जेरेमी को ढूंढें.

इस सैंपल को Google, Google Developer के विशेषज्ञों की मदद से मैनेज करता है.

अगले चरण