तीसरे पक्ष की कॉन्फ़्रेंस बनाना

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

आपको ऐड-ऑन मेनिफ़ेस्ट में बताए गए हर onCreateFunction को लागू करना होगा. सामान्य तौर पर, इन फ़ंक्शन को ये काम करने होंगे:

  1. Google Calendar में मौजूद इवेंट से जुड़ी कोई भी जानकारी हासिल करें. जैसे, इवेंट आईडी या मेहमानों की सूची. तीसरे पक्ष के कॉन्फ़्रेंसिंग सिस्टम को कॉन्फ़्रेंस बनाने के लिए, ज़रूरत पड़ सकती है.
  2. तीसरे पक्ष की कॉन्फ़्रेंसिंग सेवा से कनेक्ट करें और Google Calendar इवेंट की जानकारी का इस्तेमाल करके नई कॉन्फ़्रेंस बनाएं.
  3. अगर किसी वजह से कॉन्फ़्रेंस बनाने का अनुरोध पूरा नहीं हो पाता है, तो ConferenceError वाला ConferenceData ऑब्जेक्ट बनाने और उसे वापस करने के लिए, गड़बड़ी की जानकारी का इस्तेमाल करें. इसके अलावा, अगले चरण पूरे करें.
    1. कॉन्फ़्रेंस सिंक करना शुरू करें.
    2. कोई नया ConferenceData ऑब्जेक्ट बनाने और उसे वापस करने के लिए, तीसरे पक्ष की कॉन्फ़्रेंसिंग सेवा से मिली जानकारी का इस्तेमाल करें.

इवेंट की जानकारी वापस हासिल की जा रही है

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

कॉल किए जाने पर, आपका तय किया गया हर onCreateFunction एक आर्ग्युमेंट पास किया जाता है, जिसमें कैलेंडर और इवेंट आईडी होते हैं. Google Calendar की बेहतर सेवा का इस्तेमाल करके, इवेंट की पूरी जानकारी पाने के लिए, इन आईडी का इस्तेमाल किया जा सकता है.

ऐसा हो सकता है कि Google Calendar, इवेंट के मौजूद होने से पहले उसमें कॉन्फ़्रेंस की जानकारी जोड़ दे. ऐसे मामलों में, Google Calendar, onCreateFunction को एक मान्य eventId पास करता है, लेकिन Calendar.Events.get() को बाद में किए गए कॉल की वजह से गड़बड़ी का मैसेज दिख सकता है. इसमें लिखा होता है कि इवेंट मौजूद नहीं है. इन मामलों में, प्लेसहोल्डर डेटा का इस्तेमाल करके तीसरे पक्ष की कॉन्फ़्रेंस बनाना सबसे अच्छा होता है. अगली बार इवेंट सिंक होने पर, यह डेटा बदल दिया जाता है.

तीसरे पक्ष का कॉन्फ़्रेंस बनाना

जब onCreateFunction को इवेंट का ज़रूरी डेटा मिल जाएगा, तब उसे कॉन्फ़्रेंस बनाने के लिए, तीसरे पक्ष के कॉन्फ़्रेंसिंग सिस्टम से कनेक्ट करना होगा. आम तौर पर, ऐसा तब होता है, जब तीसरे पक्ष के कॉन्फ़्रेंसिंग सिस्टम के साथ काम करने वाले एपीआई अनुरोध किए जाते हैं. तीसरे पक्ष की कॉन्फ़्रेंसिंग सुविधा के दस्तावेज़ देखें. इससे आपको यह तय करने में मदद मिलेगी कि कॉन्फ़्रेंस बनाने के लिए, एपीआई के किन अनुरोधों का इस्तेमाल किया जा सकता है.

Apps Script में, बाहरी एपीआई अनुरोधों को मैनेज करने का सबसे आसान तरीका, Apps Script के लिए OAuth2 या ओपन सोर्स लाइब्रेरी की OAuth1 फ़ाइल का इस्तेमाल करना है. UrlFetch सेवा का इस्तेमाल करके, बाहरी एपीआई से भी कनेक्ट किया जा सकता है. हालांकि, इसके लिए आपको अनुमति से जुड़ी जानकारी को साफ़ तौर पर मैनेज करना होगा.

कॉन्फ़्रेंस बनाने का अनुरोध करने के बाद, आपको नई कॉन्फ़्रेंस की जानकारी वापस पाने के लिए, कुछ और अनुरोध करने पड़ सकते हैं.

कॉन्फ़्रेंस सिंक करना शुरू करें

जब ऐड-ऑन, तीसरे पक्ष के सिस्टम पर कॉन्फ़्रेंस बना लेता है, तो सिंक करने की सुविधा चालू करने के लिए कुछ कदम उठाने होंगे. ऐसा करने से, Google Calendar इवेंट में किए गए बदलाव कॉन्फ़्रेंस में दिखेंगे.

कॉन्फ़्रेंस बनाने के बाद, सिंक करने की सुविधा सेट अप करने के बारे में जानने के लिए, Calendar में किए गए बदलावों को सिंक करना देखें.

कॉन्फ़्रेंस डेटा का जवाब तैयार करना

तीसरे पक्ष की सेवा से मिली कॉन्फ़्रेंस की जानकारी का इस्तेमाल करके, onCreateFunction को ConferenceData ऑब्जेक्ट बनाना और दिखाना होगा. कॉन्फ़्रेंस डेटा सेक्शन में इस ऑब्जेक्ट के कॉन्टेंट के बारे में बताया गया है. Google Calendar इस जानकारी का इस्तेमाल, कॉन्फ़्रेंस शुरू होने पर उपयोगकर्ताओं को कॉन्फ़्रेंस में भेजने के लिए करता है.

ConferenceData ऑब्जेक्ट बनाते समय, ध्यान रखें कि फ़ील्ड की लंबाई, एंट्री पॉइंट यूआरआई के फ़ॉर्मैट, और एंट्री पॉइंट के मान्य कॉम्बिनेशन की कुछ सीमाएं हैं. उदाहरण के लिए, एक ConferenceData में ज़्यादा से ज़्यादा एक VIDEO एंट्री पॉइंट हो सकता है. ये सीमाएं, Calendar API इवेंट में इनसे जुड़े conferenceData फ़ील्ड के लिए बताई गई सीमाओं के जैसी ही हैं. हालांकि, इस फ़ील्ड में बताए गए सभी एपीआई इवेंट फ़ील्ड, Apps Script में उपलब्ध नहीं होते हैं.

गड़बड़ियों को ठीक करना

कुछ मामलों में कॉन्फ़्रेंस बनाने की प्रोसेस पूरी नहीं की जा सकती, क्योंकि तीसरे पक्ष के कॉन्फ़्रेंसिंग सिस्टम से कोई गड़बड़ी हुई है. इन मामलों में आपके ऐड-ऑन को गड़बड़ी की स्थिति को बेहतर तरीके से मैनेज करना चाहिए. इसके लिए, आपको ConferenceError जानकारी वाला ConferenceData ऑब्जेक्ट बनाना और दिखाना चाहिए, ताकि Google Calendar उसके मुताबिक काम कर सके.

किसी गड़बड़ी की शिकायत करने के लिए, ConferenceData ऑब्जेक्ट बनाते समय, आपको ConferenceError ऑब्जेक्ट के अलावा, किसी भी ConferenceData कॉम्पोनेंट को शामिल करने की ज़रूरत नहीं है. ConferenceErrors में ConferenceErrorType और गड़बड़ी का मैसेज हो सकता है. पुष्टि करने से जुड़ी समस्याओं के लिए, एक ऐसा यूआरएल भी हो सकता है जो उपयोगकर्ताओं को तीसरे पक्ष के कॉन्फ़्रेंसिंग सिस्टम में लॉग इन करने की अनुमति देता है.

उदाहरण

नीचे onCreateFunction का उदाहरण दिया गया है (ध्यान दें कि फ़ंक्शन का नाम कुछ भी हो सकता है; आपको इसे सिर्फ़ अपने ऐड-ऑन प्रोजेक्ट मेनिफ़ेस्ट में तय करना होगा).

create3rdPartyConference() फ़ंक्शन, कॉन्फ़्रेंस बनाने के लिए तीसरे पक्ष के सिस्टम से संपर्क करता है और getAuthenticationUrl() फ़ंक्शन, तीसरे पक्ष के सिस्टम की पुष्टि करने वाला यूआरएल बनाता है. यहां इन्हें पूरी तरह से लागू नहीं किया गया है, क्योंकि ये तीसरे पक्ष के सिस्टम की जानकारी पर पूरी तरह निर्भर हैं.

यहां initializeSyncing() फ़ंक्शन नहीं दिखाया गया है. यह सिंक करने के लिए ज़रूरी सभी शुरुआती काम को हैंडल करता है. ज़्यादा जानकारी के लिए, कैलेंडर में किए गए बदलाव सिंक करना देखें.

/**
 *  Creates a conference, then builds and returns a ConferenceData object
 *  with the corresponding conference information. This method is called
 *  when a user selects a conference solution defined by the add-on that
 *  uses this function as its 'onCreateFunction' in the add-on manifest.
 *
 *  @param {Object} arg The default argument passed to a 'onCreateFunction';
 *      it carries information about the Google Calendar event.
 *  @return {ConferenceData}
 */
function createConference(arg) {
  const eventData = arg.eventData;
  const calendarId = eventData.calendarId;
  const eventId = eventData.eventId;

  // Retrieve the Calendar event information using the Calendar
  // Advanced service.
  var calendarEvent;
  try {
    calendarEvent = Calendar.Events.get(calendarId, eventId);
  } catch (err) {
    // The calendar event does not exist just yet; just proceed with the
    // given event ID and allow the event details to sync later.
    console.log(err);
    calendarEvent = {
      id: eventId,
    };
  }

  // Create a conference on the third-party service and return the
  // conference data or errors in a custom JSON object.
  var conferenceInfo = create3rdPartyConference(calendarEvent);

  // Build and return a ConferenceData object, either with conference or
  // error information.
  var dataBuilder = ConferenceDataService.newConferenceDataBuilder();

  if (!conferenceInfo.error) {
    // No error, so build the ConferenceData object from the
    // returned conference info.

    var phoneEntryPoint = ConferenceDataService.newEntryPoint()
        .setEntryPointType(ConferenceDataService.EntryPointType.PHONE)
        .setUri('tel:+' + conferenceInfo.phoneNumber)
        .setPin(conferenceInfo.phonePin);

    var adminEmailParameter = ConferenceDataService.newConferenceParameter()
        .setKey('adminEmail')
        .setValue(conferenceInfo.adminEmail);

    dataBuilder.setConferenceId(conferenceInfo.id)
        .addEntryPoint(phoneEntryPoint)
        .addConferenceParameter(adminEmailParameter)
        .setNotes(conferenceInfo.conferenceLegalNotice);

    if (conferenceInfo.videoUri) {
      var videoEntryPoint = ConferenceDataService.newEntryPoint()
          .setEntryPointType(ConferenceDataService.EntryPointType.VIDEO)
          .setUri(conferenceInfo.videoUri)
          .setPasscode(conferenceInfo.videoPasscode);
      dataBuilder.addEntryPoint(videoEntryPoint);
    }

    // Since the conference creation request succeeded, make sure that
    // syncing has been enabled.
    initializeSyncing(calendarId, eventId, conferenceInfo.id);

  } else if (conferenceInfo.error === 'AUTH') {
    // Authenentication error. Implement a function to build the correct
    // authenication URL for the third-party conferencing system.
    var authenticationUrl = getAuthenticationUrl();
    var error = ConferenceDataService.newConferenceError()
        .setConferenceErrorType(
            ConferenceDataService.ConferenceErrorType.AUTHENTICATION)
        .setAuthenticationUrl(authenticationUrl);
    dataBuilder.setError(error);

  } else {
    // Other error type;
    var error = ConferenceDataService.newConferenceError()
        .setConferenceErrorType(
            ConferenceDataService.ConferenceErrorType.TEMPORARY);
    dataBuilder.setError(error);
  }

  // Don't forget to build the ConferenceData object.
  return dataBuilder.build();
}


/**
 *  Contact the third-party conferencing system to create a conference there,
 *  using the provided calendar event information. Collects and retuns the
 *  conference data returned by the third-party system in a custom JSON object
 *  with the following fields:
 *
 *    data.adminEmail - the conference administrator's email
 *    data.conferenceLegalNotice - the conference legal notice text
 *    data.error - Only present if there was an error during
 *         conference creation. Equal to 'AUTH' if the add-on user needs to
 *         authorize on the third-party system.
 *    data.id - the conference ID
 *    data.phoneNumber - the conference phone entry point phone number
 *    data.phonePin - the conference phone entry point PIN
 *    data.videoPasscode - the conference video entry point passcode
 *    data.videoUri - the conference video entry point URI
 *
 *  The above fields are specific to this example; which conference information
 *  your add-on needs is dependent on the third-party conferencing system
 *  requirements.
 *
 * @param {Object} calendarEvent A Calendar Event resource object returned by
 *     the Google Calendar API.
 * @return {Object}
 */
function create3rdPartyConference(calendarEvent) {
  var data = {};

  // Implementation details dependent on the third-party system API.
  // Typically one or more API calls are made to create the conference and
  // acquire its relevant data, which is then put in to the returned JSON
  // object.

  return data;
}

/**
 *  Return the URL used to authenticate the user with the third-party
 *  conferencing system.
 *
 *  @return {String}
 */
function getAuthenticationUrl() {
  var url;
  // Implementation details dependent on the third-party system.

  return url;
}