โซลูชันการประชุมแต่ละรายการที่กำหนดไว้ในไฟล์ Manifest ของโปรเจ็กต์สคริปต์จะมี onCreateFunction
เชื่อมโยงอยู่ ส่วนเสริมจะเรียกใช้ฟังก์ชันนี้เพื่อสร้างการประชุมเมื่อใดก็ตามที่ผู้ใช้พยายามเลือกเหตุการณ์ที่เป็นโซลูชันการประชุมนั้น
คุณต้องใช้ onCreateFunction
แต่ละรายการที่อธิบายไว้ในไฟล์ Manifest ของส่วนเสริม
โดยทั่วไปแล้ว ฟังก์ชันเหล่านี้ต้องมีลักษณะดังต่อไปนี้
- ดึงข้อมูลกิจกรรมใน Google ปฏิทิน เช่น รหัสกิจกรรมหรือรายชื่อผู้เข้าร่วมที่ระบบการประชุมของบุคคลที่สามอาจต้องใช้เพื่อสร้างการประชุม
- เชื่อมต่อกับบริการการประชุมของบุคคลที่สามและสร้างการประชุมใหม่โดยใช้ข้อมูลกิจกรรมของ Google ปฏิทิน
- หากคำขอสร้างการประชุมล้มเหลวด้วยเหตุผลบางอย่าง ให้ใช้ข้อมูลข้อผิดพลาดเพื่อสร้างและแสดงผลออบเจ็กต์
ConferenceData
ที่มีConferenceError
หรือทำตามขั้นตอนถัดไปให้เรียบร้อย- เริ่มต้นการซิงค์การประชุม
- ใช้ข้อมูลที่แสดงผลโดยบริการการประชุมของบุคคลที่สามเพื่อสร้างและแสดงผลออบเจ็กต์
ConferenceData
ใหม่
กำลังดึงข้อมูลกิจกรรม
หากต้องการสร้างการประชุมของบุคคลที่สาม จะต้องมีข้อมูลบางอย่างเกี่ยวกับกิจกรรมใน Google ปฏิทินที่เกี่ยวข้อง ข้อมูลกิจกรรมที่ต้องการจะแตกต่างกันไปตามระบบการประชุมของบุคคลที่สาม แต่มักประกอบด้วยเวลาเริ่มต้นกิจกรรม เวลาสิ้นสุด สรุป รายชื่อผู้เข้าร่วม และรหัส
เมื่อเรียกใช้ onCreateFunction
แต่ละรายการที่คุณกำหนดจะส่งผ่านอาร์กิวเมนต์ที่มีรหัสปฏิทินและรหัสกิจกรรม คุณใช้รหัสเหล่านี้เพื่อดึงข้อมูลกิจกรรมทั้งหมดได้โดยใช้บริการขั้นสูงของ Google ปฏิทิน
เป็นไปได้ที่ Google ปฏิทินจะเพิ่มรายละเอียดการประชุมในกิจกรรมก่อนกิจกรรมนั้น ในกรณีดังกล่าว Google ปฏิทินจะส่ง onCreateFunction
ที่ถูกต้องeventId
แต่การเรียกไปยัง Calendar.Events.get()
ในภายหลังอาจส่งผลให้เกิดการตอบกลับข้อผิดพลาดที่แจ้งว่าไม่มีกิจกรรมดังกล่าว ในกรณีเช่นนี้ วิธีที่ดีที่สุดคือสร้างการประชุมของบุคคลที่สามโดยใช้ข้อมูลตัวยึดตำแหน่ง ระบบจะแทนที่ข้อมูลนี้เมื่อซิงค์กิจกรรมในครั้งถัดไป
กำลังสร้างการประชุมของบุคคลที่สาม
เมื่อ onCreateFunction
เรียกข้อมูลกิจกรรมที่จำเป็นแล้ว อุปกรณ์จะต้องเชื่อมต่อกับระบบการประชุมของบุคคลที่สามเพื่อสร้างการประชุม
ซึ่งโดยทั่วไปแล้วทำได้โดยการทำให้คำขอ API รองรับโดยระบบการประชุมของบุคคลที่สาม โปรดอ่านเอกสารประกอบของโซลูชันการประชุมของบุคคลที่สามเพื่อดูว่าคำขอ API ใดที่คุณสามารถใช้สร้างการประชุมได้
ใน Apps Script วิธีที่ง่ายที่สุดในการจัดการกับการสร้างคำขอ API ภายนอกคือการใช้ไลบรารีโอเพนซอร์ส OAuth2 สำหรับ Apps Script หรือ OAuth1 สำหรับ Apps Script คุณยังเชื่อมต่อกับ API ภายนอกโดยใช้บริการ UrlFetch ได้ด้วย แต่คุณต้องจัดการรายละเอียดการให้สิทธิ์อย่างชัดเจน
หลังจากขอสร้างการประชุมแล้ว คุณอาจต้องส่งคำขอเพิ่มเติมเพื่อเรียกดูรายละเอียดการประชุมใหม่
เริ่มต้นการซิงค์การประชุม
เมื่อสร้างการประชุมในระบบของบุคคลที่สามเรียบร้อยแล้ว ให้ใช้ 2-3 ขั้นตอนเพื่อเปิดใช้การซิงค์ เพื่อให้การเปลี่ยนแปลงที่ทำกับกิจกรรมใน Google ปฏิทินปรากฏในการประชุม
ดูรายละเอียดการตั้งค่าการซิงค์หลังจากสร้างการประชุมได้ที่การซิงค์การเปลี่ยนแปลงปฏิทิน
การสร้างการตอบกลับข้อมูลการประชุม
เมื่อใช้ข้อมูลการประชุมที่แสดงผลโดยบริการของบุคคลที่สาม
onCreateFunction
จะต้องสร้างและแสดงผลออบเจ็กต์
ConferenceData
ส่วนข้อมูลการประชุม
จะอธิบายเนื้อหาของออบเจ็กต์นี้ Google ปฏิทินจะใช้ข้อมูลนี้เพื่อพาผู้ใช้ไปยังการประชุมเมื่อเริ่มการประชุม
เมื่อสร้างออบเจ็กต์ ConferenceData
โปรดทราบว่าความยาวช่อง รูปแบบ URI ของจุดแรกเข้า และชุดค่าผสมของจุดแรกเข้าที่อนุญาตไม่ได้ ตัวอย่างเช่น อาจมีจุดแรกเข้า VIDEO
ไม่เกิน 1 จุดใน ConferenceData
เดียว ข้อจำกัดเหล่านี้เหมือนกับข้อจำกัดที่อธิบายไว้ในกิจกรรม API ของปฏิทินสำหรับช่อง conferenceData
ที่เกี่ยวข้อง แม้ว่าช่องกิจกรรม API บางช่องที่ไม่ได้อธิบายจะมีใน Apps Script ก็ตาม
การจัดการข้อผิดพลาด
ในบางกรณี การสร้างการประชุมอาจไม่สำเร็จเนื่องจากเกิดข้อผิดพลาดที่ระบบการประชุมของบุคคลที่สามแสดงผล ในกรณีเหล่านี้ ส่วนเสริมของคุณควรจัดการกับเงื่อนไขข้อผิดพลาดได้อย่างมีประสิทธิภาพโดยการสร้างและแสดงผลออบเจ็กต์ ConferenceData
ที่มีรายละเอียด ConferenceError
เพื่อให้ Google ปฏิทินสามารถดำเนินการตามความเหมาะสม
เมื่อสร้างออบเจ็กต์ ConferenceData
เพื่อรายงานข้อผิดพลาด คุณไม่จำเป็นต้องรวมคอมโพเนนต์ ConferenceData
ใดๆ นอกเหนือไปจากออบเจ็กต์ ConferenceError
ConferenceErrors
อาจมี ConferenceErrorType
, ข้อความแสดงข้อผิดพลาด และ URL ที่อนุญาตให้ผู้ใช้เข้าสู่ระบบระบบการประชุมของบุคคลที่สามในกรณีที่การตรวจสอบสิทธิ์ออก
ตัวอย่าง
รายการต่อไปนี้จะแสดงตัวอย่างของ onCreateFunction
(โปรดทราบว่าชื่อของฟังก์ชันจะเป็นอะไรก็ได้ คุณเพียงแต่ต้องกำหนดในไฟล์ Manifest ของโปรเจ็กต์ส่วนเสริม)
ฟังก์ชัน create3rdPartyConference()
จะติดต่อกับระบบของบุคคลที่สามเพื่อสร้างการประชุมในระบบนั้น และฟังก์ชัน getAuthenticationUrl()
จะสร้าง URL การตรวจสอบสิทธิ์ระบบของบุคคลที่สาม การดำเนินการเหล่านี้ยังใช้ได้ไม่สมบูรณ์เนื่องจากจะขึ้นอยู่กับรายละเอียดของระบบของบุคคลที่สาม
ฟังก์ชัน 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; }