कॉन्फ़्रेंस में होने वाले सेशन के लिए साइन-अप करें

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

मकसद

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

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

पूरी तरह से इवेंट रजिस्ट्रेशन सिस्टम बनाएं. अगर कॉन्फ़्रेंस जैसा कोई इवेंट शुरू होने वाला है, तो कॉन्फ़्रेंस सेशन के लिए एक नया कैलेंडर सेट अप किया जा सकता है. साथ ही, साइन अप फ़ॉर्म बनाया जा सकता है और मेहमानों को उनके हिसाब से बनाए गए इवेंट की जानकारी अपने-आप ईमेल की जा सकती है.

Sheets की जानकारी को Forms और Calendar पर ट्रांसफ़र किया जा रहा है

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

यह समाधान, Google Sheets में कस्टम मेन्यू का इस्तेमाल करके अपने-आप होने वाले इवेंट रजिस्ट्रेशन सिस्टम को लागू करता है. स्क्रिप्ट शीट स्प्रेडशीट में सूची में शामिल कॉन्फ़्रेंस इवेंट के साथ एक कैलेंडर बनाती है. इसके बाद, स्क्रिप्ट इवेंट की सूची वाला एक फ़ॉर्म बनाती है. इस सूची में, इवेंट में शामिल लोग उन इवेंट के लिए साइन अप कर सकते हैं जिनके लिए वे साइन अप कर सकते हैं. मेहमानों के फ़ॉर्म भर जाने के बाद, स्क्रिप्ट इवेंट में आने वाले लोगों को कैलेंडर इवेंट में जोड़ देती है. साथ ही, उन्हें यात्रा की योजना के बारे में ईमेल से जानकारी भी भेज देती है.

Apps Script सेवाएं

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

  • स्प्रेडशीट सेवा–यह दूसरी सेवाओं को इवेंट की जानकारी देती है.
  • कैलेंडर सेवा–इवेंट के लिए एक नया कैलेंडर बनाता है, इवेंट को कैलेंडर में जोड़ता है, और मेहमानों को उन इवेंट में जोड़ता है जिनके लिए उन्होंने साइन अप किया है.
  • प्रॉपर्टी सेवा–यह, Calendar सेवा से बनाए गए कैलेंडर का आईडी सेव करती है. जब कोई उपयोगकर्ता पसंद के मुताबिक बनाए गए कॉन्फ़्रेंस मेन्यू में, कॉन्फ़्रेंस सेट अप करें विकल्प पर क्लिक करता है, तो प्रॉपर्टी सेवा यह जांच करती है कि इवेंट रजिस्ट्रेशन सिस्टम पहले से सेट अप है या नहीं. इसके लिए, देखें कि Calendar आईडी प्रॉपर्टी मौजूद है या नहीं. ऐसा करने से डुप्लीकेट फ़ॉर्म और कैलेंडर बनाने से बचा जा सकता है.
  • फ़ॉर्म सेवा–स्प्रेडशीट में दी गई जानकारी से एक फ़ॉर्म बनाता है, जिसकी मदद से मेहमान सेशन के लिए साइन अप कर सकते हैं.
  • स्क्रिप्ट सेवा–यह, इवेंट में शामिल होने वाले किसी व्यक्ति के फ़ॉर्म भरने पर ट्रिगर होने वाला ट्रिगर बनाता है.
  • दस्तावेज़ से जुड़ी सेवा– इससे उन इवेंट की जानकारी मिलती है जिनके लिए मेहमान साइन अप करता है और इवेंट की सूची को नए दस्तावेज़ में जोड़ता है. स्क्रिप्ट, मेहमान को दस्तावेज़ में बदलाव करने की अनुमति देती है.
  • मेल सेवा–मेहमान को यात्रा की योजना का दस्तावेज़ ईमेल करता है.

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

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

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

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

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

  4. कॉन्फ़्रेंस > कॉन्फ़्रेंस सेट अप करें पर फिर से क्लिक करें.

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

  1. टूल > फ़ॉर्म मैनेज करें > लाइव फ़ॉर्म पर जाएं पर क्लिक करें.
  2. फ़ॉर्म भरकर सबमिट करें.
  3. calendar.google.com पर जाएं.
  4. बाईं ओर, पक्का करें कि कॉन्फ़्रेंस कैलेंडर के बगल में मौजूद बॉक्स पर सही का निशान लगा हो.
  5. उन इवेंट की तारीखों पर जाएं जिनके लिए आपने साइन अप किया है और पुष्टि करें कि आपको मेहमान के तौर पर जोड़ा गया है.

(ज़रूरी नहीं) हल को रीसेट करें

अगर आपको यह तरीका फिर से आज़माना है या इवेंट की जानकारी का इस्तेमाल करने के लिए इसे कस्टमाइज़ करना है, तो आपको कुछ ऐसे आइटम रीसेट करने होंगे जो पहली बार स्क्रिप्ट चलाने के दौरान सेट अप किए गए थे. सलूशन को रीसेट करने का तरीका देखने के लिए, नीचे दिए गए सॉल्यूशन को रीसेट करें पर क्लिक करें:

हल को रीसेट करें

पहला चरण: सेव की गई स्क्रिप्ट प्रॉपर्टी रीसेट करना

अगर स्क्रिप्ट को एक से ज़्यादा बार चलाने की कोशिश की जाती है, तो आपको यह सूचना मिलेगी कि आपकी कॉन्फ़्रेंस पहले ही सेट अप हो चुकी है. Google Drive में अपना साइन अप फ़ॉर्म देखें! ऐसा इसलिए होता है, क्योंकि कॉन्फ़्रेंस कैलेंडर बनाने के बाद, कैलेंडर आईडी को स्क्रिप्ट प्रॉपर्टी के तौर पर सेव कर दिया जाता है. स्क्रिप्ट चलने पर, यह जांच करती है कि Calendar आईडी प्रॉपर्टी पहले से मौजूद है या नहीं. अगर स्क्रिप्ट चलता है, तो वह रुक जाती है.

मौजूदा कैलेंडर आईडी प्रॉपर्टी को हटाने के लिए, यह तरीका अपनाएं:

  1. स्प्रेडशीट में, एक्सटेंशन > Apps Script पर क्लिक करें.
  2. Apps Script एडिटर में, फ़ंक्शन की ड्रॉपडाउन सूची से resetProperties चुनें और रन पर क्लिक करें.

दूसरा चरण: कॉन्फ़्रेंस कैलेंडर मिटाना

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

  1. calendar.google.com पर जाएं.
  2. कॉन्फ़्रेंस कैलेंडर के बगल में, 'कॉन्फ़्रेंस कैलेंडर' के विकल्प पर क्लिक करें > सेटिंग और शेयर करना.
  3. सेटिंग के सबसे नीचे तक स्क्रोल करें और मिटाएं पर क्लिक करें.

तीसरा चरण: फ़ॉर्म सबमिट करने वाले ट्रिगर को मिटाना

हर बार जब आप फ़ॉर्म चलाते हैं, तो स्क्रिप्ट फ़ॉर्म सबमिशन के लिए एक ट्रिगर बनाती है. डुप्लीकेट ईमेल भेजने वाले कई ट्रिगर से बचने के लिए, ओरिजनल ट्रिगर को हटाएं. यह तरीक़ा अपनाएँ:

  1. स्प्रेडशीट में, एक्सटेंशन > Apps Script पर क्लिक करें.
  2. Apps Script प्रोजेक्ट में, बाईं ओर मौजूद ट्रिगर पर क्लिक करें.
  3. ट्रिगर के बगल में, ज़्यादा > ट्रिगर मिटाएं पर क्लिक करें.

हर बार स्क्रिप्ट चलाने पर, एक नया फ़ॉर्म बन जाता है. अपनी स्प्रेडशीट से फ़ॉर्म को अनलिंक करने और उसे मिटाने के लिए, यह तरीका अपनाएं:

  1. स्प्रेडशीट में, फ़ॉर्म जवाब शीट पर राइट क्लिक करें और फ़ॉर्म अनलिंक करें > ठीक है पर क्लिक करें.
  2. फ़ॉर्म जवाब शीट पर फिर से राइट क्लिक करें और मिटाएं > ठीक है पर क्लिक करें.
  3. forms.google.com पर जाएं.
  4. कॉन्फ़्रेंस फ़ॉर्म पर दायां क्लिक करें और हटाएं > ट्रैश में ले जाएं पर क्लिक करें.

समाधान को रीसेट करने के बाद, अपना डेटा जोड़ा जा सकता है. इसके अलावा, सैंपल डेटा का इस्तेमाल जारी रखने के बाद, स्क्रिप्ट को फिर से चलाया जा सकता है.

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

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

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

Code.gs

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

/*
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.
*/

/**
 * Inserts a custom menu when the spreadsheet opens.
 */
function onOpen() {
  SpreadsheetApp.getUi().createMenu('Conference')
      .addItem('Set up conference', 'setUpConference_')
      .addToUi();
}

/**
 * Uses the conference data in the spreadsheet to create
 * Google Calendar events, a Google Form, and a trigger that allows the script
 * to react to form responses.
 */
function setUpConference_() {
  let scriptProperties = PropertiesService.getScriptProperties();
  if (scriptProperties.getProperty('calId')) {
    Browser.msgBox('Your conference is already set up. Look in Google Drive for your'
                   + ' sign-up form!');
                   return;
  }
  let ss = SpreadsheetApp.getActive();
  let sheet = ss.getSheetByName('Conference Setup');
  let range = sheet.getDataRange();
  let values = range.getValues();
  setUpCalendar_(values, range);
  setUpForm_(ss, values);
  ScriptApp.newTrigger('onFormSubmit').forSpreadsheet(ss).onFormSubmit()
      .create();
}

/**
 * Creates a Google Calendar with events for each conference session in the
 * spreadsheet, then writes the event IDs to the spreadsheet for future use.
 * @param {Array<string[]>} values Cell values for the spreadsheet range.
 * @param {Range} range A spreadsheet range that contains conference data.
 */
function setUpCalendar_(values, range) {
  let cal = CalendarApp.createCalendar('Conference Calendar');
  // Start at 1 to skip the header row.
  for (let i = 1; i < values.length; i++) {
    let session = values[i];
    let title = session[0];
    let start = joinDateAndTime_(session[1], session[2]);
    let end = joinDateAndTime_(session[1], session[3]);
    let options = {location: session[4], sendInvites: true};
    let event = cal.createEvent(title, start, end, options)
        .setGuestsCanSeeGuests(false);
    session[5] = event.getId();
  }
  range.setValues(values);

  // Stores the ID for the Calendar, which is needed to retrieve events by ID.
  let scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.setProperty('calId', cal.getId());
}

/**
 * Creates a single Date object from separate date and time cells.
 *
 * @param {Date} date A Date object from which to extract the date.
 * @param {Date} time A Date object from which to extract the time.
 * @return {Date} A Date object representing the combined date and time.
 */
function joinDateAndTime_(date, time) {
  date = new Date(date);
  date.setHours(time.getHours());
  date.setMinutes(time.getMinutes());
  return date;
}

/**
 * Creates a Google Form that allows respondents to select which conference
 * sessions they would like to attend, grouped by date and start time in the
 * caller's time zone.
 *
 * @param {Spreadsheet} ss The spreadsheet that contains the conference data.
 * @param {Array<String[]>} values Cell values for the spreadsheet range.
 */
function setUpForm_(ss, values) {
  // Group the sessions by date and time so that they can be passed to the form.
  let schedule = {};
  // Start at 1 to skip the header row.
  for (let i = 1; i < values.length; i++) {
    let session = values[i];
    let day = session[1].toLocaleDateString();
    let time = session[2].toLocaleTimeString();
    if (!schedule[day]) {
      schedule[day] = {};
    }
    if (!schedule[day][time]) {
      schedule[day][time] = [];
    }
    schedule[day][time].push(session[0]);
  }

  // Creates the form and adds a multiple-choice question for each timeslot.
  let form = FormApp.create('Conference Form');
  form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
  form.addTextItem().setTitle('Name').setRequired(true);
  form.addTextItem().setTitle('Email').setRequired(true);
  Object.keys(schedule).forEach(function(day) {
    let header = form.addSectionHeaderItem().setTitle('Sessions for ' + day);
    Object.keys(schedule[day]).forEach(function(time) {
      let item = form.addMultipleChoiceItem().setTitle(time + ' ' + day)
          .setChoiceValues(schedule[day][time]);
    });
  });
}

/**
 * Sends out calendar invitations and a
 * personalized Google Docs itinerary after a user responds to the form.
 *
 * @param {Object} e The event parameter for form submission to a spreadsheet;
 *     see https://developers.google.com/apps-script/understanding_events
 */
function onFormSubmit(e) {
  let user = {name: e.namedValues['Name'][0], email: e.namedValues['Email'][0]};

  // Grab the session data again so that we can match it to the user's choices.
  let response = [];
  let values = SpreadsheetApp.getActive().getSheetByName('Conference Setup')
      .getDataRange().getValues();
  for (let i = 1; i < values.length; i++) {
    let session = values[i];
    let title = session[0];
    let day = session[1].toLocaleDateString();
    let time = session[2].toLocaleTimeString();
    let timeslot = time + ' ' + day;

    // For every selection in the response, find the matching timeslot and title
    // in the spreadsheet and add the session data to the response array.
    if (e.namedValues[timeslot] && e.namedValues[timeslot] == title) {
      response.push(session);
    }
  }
  sendInvites_(user, response);
  sendDoc_(user, response);
}

/**
 * Add the user as a guest for every session he or she selected.
 * @param {object} user An object that contains the user's name and email.
 * @param {Array<String[]>} response An array of data for the user's session choices.
 */
function sendInvites_(user, response) {
  let id = ScriptProperties.getProperty('calId');
  let cal = CalendarApp.getCalendarById(id);
  for (let i = 0; i < response.length; i++) {
    cal.getEventSeriesById(response[i][5]).addGuest(user.email);
  }
}

/**
 * Creates and shares a personalized Google Doc that shows the user's itinerary.
 * @param {object} user An object that contains the user's name and email.
 * @param {Array<string[]>} response An array of data for the user's session choices.
 */
function sendDoc_(user, response) {
  let doc = DocumentApp.create('Conference Itinerary for ' + user.name)
      .addEditor(user.email);
  let body = doc.getBody();
  let table = [['Session', 'Date', 'Time', 'Location']];
  for (let i = 0; i < response.length; i++) {
    table.push([response[i][0], response[i][1].toLocaleDateString(),
      response[i][2].toLocaleTimeString(), response[i][4]]);
  }
  body.insertParagraph(0, doc.getName())
      .setHeading(DocumentApp.ParagraphHeading.HEADING1);
  table = body.appendTable(table);
  table.getRow(0).editAsText().setBold(true);
  doc.saveAndClose();

  // Emails a link to the Doc as well as a PDF copy.
  MailApp.sendEmail({
    to: user.email,
    subject: doc.getName(),
    body: 'Thanks for registering! Here\'s your itinerary: ' + doc.getUrl(),
    attachments: doc.getAs(MimeType.PDF),
  });
}

/**
 * Removes the calId script property so that the 'setUpConference_()' can be run again.
 */
function resetProperties(){
  let scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.deleteAllProperties();
}

योगदानकर्ता

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

अगले चरण