مهم : این راهنمای سریع فقط برای ارائه دهندگان کنفرانس وب است.
افزونهی Google Workspace که در ادامه آمده است، تقویم گوگل را برای همگامسازی با یک سرویس کنفرانس وب فرضی به نام My Web Conferencing گسترش میدهد. هنگام ویرایش رویدادهای تقویم، این افزونه به کاربران امکان میدهد My Web Conferencing را به عنوان یک گزینهی کنفرانس ببینند.
منوی شروع سریع، ایجاد کنفرانس و همگامسازی رویداد را نشان میدهد، اما تا زمانی که آن را به API راهکار کنفرانس خود متصل نکنید، قابل استفاده نیست.
اهداف
- محیط خود را تنظیم کنید.
- اسکریپت را تنظیم کنید.
- اسکریپت را اجرا کنید.
پیشنیازها
- یک مرورگر وب با دسترسی به اینترنت.
- یک حساب Google Workspace (ممکن است به تأیید مدیر نیاز داشته باشید).
- یک پروژه ابری گوگل .
محیط خود را تنظیم کنید
پروژه ابری خود را در کنسول گوگل کلود باز کنید
اگر هنوز باز نشده است، پروژه ابری که قصد دارید برای این نمونه استفاده کنید را باز کنید:
- در کنسول گوگل کلود، به صفحه انتخاب پروژه بروید.
- پروژه گوگل کلود مورد نظر خود را انتخاب کنید. یا روی ایجاد پروژه کلیک کنید و دستورالعملهای روی صفحه را دنبال کنید. اگر یک پروژه گوگل کلود ایجاد میکنید، ممکن است لازم باشد پرداخت هزینه را برای آن پروژه فعال کنید .
فعال کردن API تقویم
این راهنمای سریع از سرویس پیشرفته تقویم استفاده میکند که به API تقویم دسترسی دارد.
قبل از استفاده از APIهای گوگل، باید آنها را در یک پروژه گوگل کلود فعال کنید. میتوانید یک یا چند API را در یک پروژه گوگل کلود فعال کنید.در پروژه Google Cloud خود، API تقویم را فعال کنید.
صفحه رضایت OAuth را پیکربندی کنید
افزونههای Google Workspace نیاز به پیکربندی صفحه رضایت دارند. پیکربندی صفحه رضایت OAuth افزونه Google Workspace شما، آنچه گوگل به کاربران نمایش میدهد را تعریف میکند.
- در کنسول گوگل کلود، به Menu > برویدGoogle Auth platform > برندسازی .
- اگر قبلاً تنظیمات را انجام دادهاید Google Auth platformمیتوانید تنظیمات صفحه رضایت OAuth زیر را در Branding ، Audience و Data Access پیکربندی کنید. اگر پیامی با این مضمون مشاهده کردید Google Auth platform هنوز پیکربندی نشده است ، روی شروع کار کلیک کنید:
- در قسمت اطلاعات برنامه ، در قسمت نام برنامه ، نامی برای برنامه وارد کنید.
- در ایمیل پشتیبانی کاربر ، یک آدرس ایمیل پشتیبانی انتخاب کنید که کاربران در صورت داشتن هرگونه سوال در مورد رضایت خود بتوانند با شما تماس بگیرند.
- روی بعدی کلیک کنید.
- در قسمت مخاطبان ، داخلی (Internal) را انتخاب کنید.
- روی بعدی کلیک کنید.
- در قسمت اطلاعات تماس ، یک آدرس ایمیل وارد کنید که از طریق آن بتوانید از هرگونه تغییر در پروژه خود مطلع شوید.
- روی بعدی کلیک کنید.
- در قسمت Finish ، سیاست دادههای کاربر سرویسهای API گوگل را مرور کنید و در صورت موافقت، گزینه «من با سیاستهای دادههای کاربر سرویسهای API گوگل موافقم» را انتخاب کنید.
- روی ادامه کلیک کنید.
- روی ایجاد کلیک کنید.
- فعلاً میتوانید از اضافه کردن محدودهها صرف نظر کنید. در آینده، وقتی برنامهای برای استفاده در خارج از سازمان Google Workspace خود ایجاد میکنید، باید نوع کاربر (User type) را به خارجی (External) تغییر دهید. سپس محدودههای مجوز مورد نیاز برنامه خود را اضافه کنید. برای کسب اطلاعات بیشتر، به راهنمای کامل پیکربندی رضایت OAuth مراجعه کنید.
اسکریپت را تنظیم کنید
پروژه Apps Script را ایجاد کنید
- برای ایجاد یک پروژه جدید Apps Script، به script.new بروید.
- روی پروژه بدون عنوان کلیک کنید.
- نام افزونهی Conference پروژهی Apps Script را تغییر دهید و روی «تغییر نام» کلیک کنید.
- در کنار فایل
Code.gs، روی More > Rename کلیک کنید. نام فایل راCreateConfقرار دهید. - روی فایل > اسکریپت کلیک کنید.
- نام فایل را
Syncingبگذارید. محتویات هر فایل را با کد مربوطه زیر جایگزین کنید:
CreateConf.gs
/** * 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; }همگامسازی.gs
/** * Initializes syncing of conference data by creating a sync trigger and * sync token if either does not exist yet. * * @param {String} calendarId The ID of the Google Calendar. */ function initializeSyncing(calendarId) { // Create a syncing trigger if it doesn't exist yet. createSyncTrigger(calendarId); // Perform an event sync to create the initial sync token. syncEvents({'calendarId': calendarId}); } /** * Creates a sync trigger if it does not exist yet. * * @param {String} calendarId The ID of the Google Calendar. */ function createSyncTrigger(calendarId) { // Check to see if the trigger already exists; if does, return. var allTriggers = ScriptApp.getProjectTriggers(); for (var i = 0; i < allTriggers.length; i++) { var trigger = allTriggers[i]; if (trigger.getTriggerSourceId() == calendarId) { return; } } // Trigger does not exist, so create it. The trigger calls the // 'syncEvents()' trigger function when it fires. var trigger = ScriptApp.newTrigger('syncEvents') .forUserCalendar(calendarId) .onEventUpdated() .create(); } /** * Sync events for the given calendar; this is the syncing trigger * function. If a sync token already exists, this retrieves all events * that have been modified since the last sync, then checks each to see * if an associated conference needs to be updated and makes any required * changes. If the sync token does not exist or is invalid, this * retrieves future events modified in the last 24 hours instead. In * either case, a new sync token is created and stored. * * @param {Object} e If called by a event updated trigger, this object * contains the Google Calendar ID, authorization mode, and * calling trigger ID. Only the calendar ID is actually used here, * however. */ function syncEvents(e) { var calendarId = e.calendarId; var properties = PropertiesService.getUserProperties(); var syncToken = properties.getProperty('syncToken'); var options; if (syncToken) { // There's an existing sync token, so configure the following event // retrieval request to only get events that have been modified // since the last sync. options = { syncToken: syncToken }; } else { // No sync token, so configure to do a 'full' sync instead. In this // example only recently updated events are retrieved in a full sync. // A larger time window can be examined during a full sync, but this // slows down the script execution. Consider the trade-offs while // designing your add-on. var now = new Date(); var yesterday = new Date(); yesterday.setDate(now.getDate() - 1); options = { timeMin: now.toISOString(), // Events that start after now... updatedMin: yesterday.toISOString(), // ...and were modified recently maxResults: 50, // Max. number of results per page of responses orderBy: 'updated' } } // Examine the list of updated events since last sync (or all events // modified after yesterday if the sync token is missing or invalid), and // update any associated conferences as required. var events; var pageToken; do { try { options.pageToken = pageToken; events = Calendar.Events.list(calendarId, options); } catch (err) { // Check to see if the sync token was invalidated by the server; // if so, perform a full sync instead. if (err.message === "Sync token is no longer valid, a full sync is required.") { properties.deleteProperty('syncToken'); syncEvents(e); return; } else { throw new Error(err.message); } } // Read through the list of returned events looking for conferences // to update. if (events.items && events.items.length > 0) { for (var i = 0; i < events.items.length; i++) { var calEvent = events.items[i]; // Check to see if there is a record of this event has a // conference that needs updating. if (eventHasConference(calEvent)) { updateConference(calEvent, calEvent.conferenceData.conferenceId); } } } pageToken = events.nextPageToken; } while (pageToken); // Record the new sync token. if (events.nextSyncToken) { properties.setProperty('syncToken', events.nextSyncToken); } } /** * Returns true if the specified event has an associated conference * of the type managed by this add-on; retuns false otherwise. * * @param {Object} calEvent The Google Calendar event object, as defined by * the Calendar API. * @return {boolean} */ function eventHasConference(calEvent) { var name = calEvent.conferenceData.conferenceSolution.name || null; // This version checks if the conference data solution name matches the // one of the solution names used by the add-on. Alternatively you could // check the solution's entry point URIs or other solution-specific // information. if (name) { if (name === "My Web Conference" || name === "My Recorded Web Conference") { return true; } } return false; } /** * Update a conference based on new Google Calendar event information. * The exact implementation of this function is highly dependant on the * details of the third-party conferencing system, so only a rough outline * is shown here. * * @param {Object} calEvent The Google Calendar event object, as defined by * the Calendar API. * @param {String} conferenceId The ID used to identify the conference on * the third-party conferencing system. */ function updateConference(calEvent, conferenceId) { // Check edge case: the event was cancelled if (calEvent.status === 'cancelled' || eventHasConference(calEvent)) { // Use the third-party API to delete the conference too. } else { // Extract any necessary information from the event object, then // make the appropriate third-party API requests to update the // conference with that information. } }روی تنظیمات پروژه کلیک کنید
.
تیک گزینهی «نمایش فایل مانیفست "appsscript.json" در ویرایشگر» را بزنید.
روی ویرایشگر کلیک کنید.
فایل
appsscript.jsonرا باز کنید و محتویات آن را با کد زیر جایگزین کنید، سپس روی ذخیره کلیک کنید..
appsscript.json
{ "addOns": { "calendar": { "conferenceSolution": [{ "id": 1, "name": "My Web Conference", "logoUrl": "https://lh3.googleusercontent.com/...", "onCreateFunction": "createConference" }], "currentEventAccess": "READ_WRITE" }, "common": { "homepageTrigger": { "enabled": false }, "logoUrl": "https://lh3.googleusercontent.com/...", "name": "My Web Conferencing" } }, "timeZone": "America/New_York", "dependencies": { "enabledAdvancedServices": [ { "userSymbol": "Calendar", "serviceId": "calendar", "version": "v3" } ] }, "webapp": { "access": "ANYONE", "executeAs": "USER_ACCESSING" }, "exceptionLogging": "STACKDRIVER", "oauthScopes": [ "https://www.googleapis.com/auth/calendar.addons.execute", "https://www.googleapis.com/auth/calendar.events.readonly", "https://www.googleapis.com/auth/calendar.addons.current.event.read", "https://www.googleapis.com/auth/calendar.addons.current.event.write", "https://www.googleapis.com/auth/script.external_request", "https://www.googleapis.com/auth/script.scriptapp" ] }
شماره پروژه ابری را کپی کنید
- در کنسول گوگل کلود، به Menu > IAM & Admin > Settings بروید.
- در فیلد شماره پروژه ، مقدار را کپی کنید.
پروژه Cloud مربوط به پروژه Apps Script را تنظیم کنید.
- در پروژه Apps Script خود، روی تنظیمات پروژه کلیک کنید.
.
- در زیر پروژه پلتفرم ابری گوگل (GCP) ، روی تغییر پروژه کلیک کنید.
- در قسمت شماره پروژه GCP ، شماره پروژه Google Cloud را وارد کنید.
- روی تنظیم پروژه کلیک کنید.
نصب یک نسخه آزمایشی
- در پروژه Apps Script خود، روی Editor کلیک کنید.
- فایل
CreateConf.gsرا باز کنید و روی Run کلیک کنید. در صورت درخواست، اسکریپت را تأیید کنید. - روی استقرار > آزمایش استقرارها کلیک کنید.
- روی نصب > انجام شد کلیک کنید.
اسکریپت را اجرا کنید
- به calendar.google.com بروید.
- یک رویداد جدید ایجاد کنید یا یک رویداد موجود را باز کنید.
- در کنار افزودن کنفرانس ویدیویی Google Meet ، روی پیکان رو به پایین > کنفرانس وب من کلیک کنید. خطای «ایجاد کنفرانس ناموفق بود» نمایش داده میشود زیرا افزونه به یک راهکار کنفرانس شخص ثالث واقعی متصل نیست.