Cloud Run पर Node.js में, Google Workspace Studio के लिए कस्टम चरण बनाना

1. परिचय

Google Workspace Studio की मदद से, Gmail, Google Chat, Google Drive, और Google Sheets जैसे Google Workspace ऐप्लिकेशन में, कारोबार की प्रोसेस को ऑटोमेट किया जा सकता है. जब आपको अपने वर्कफ़्लो किसी बाहरी वेब ऐप्लिकेशन से शुरू करने हों या अपने क्लाउड एनवायरमेंट में कस्टम लॉजिक चलाना हो, तो Google Workspace Studio को एचटीटीपी Google Workspace ऐड-ऑन के साथ इस्तेमाल किया जा सकता है. इसके लिए, Cloud Run पर Node.js का इस्तेमाल करें:

  1. कस्टम स्टार्टर स्टेप (workflowTrigger): यह ट्रिगर के notifyUri (या Google Workspace Studio triggers.fire REST API) को कॉल करके, कोई बाहरी इवेंट होने पर Google Workspace Studio फ़्लो शुरू करता है. जैसे, किसी ग्राहक का इंटरनल वेब पोर्टल में टिकट सबमिट करना.
  2. कस्टम ऐक्शन वाला चरण (workflowAction): यह फ़्लो में पिछले चरणों से वैरिएबल लेता है, आपकी Node.js सेवा में कस्टम लॉजिक या एआई इन्फ़्रेंस चलाता है, और आउटपुट वैरिएबल को Google Workspace Studio में वापस भेजता है.

इस कोडलैब में, Cloud Run पर Google Workspace Studio के लिए, Node.js एचटीटीपी एक्सटेंशन बनाया जाता है और उसे डिप्लॉय किया जाता है. साथ ही, कंटेनर के अलग-अलग वर्शन में, ऐक्टिव फ़्लो ट्रिगर की सदस्यताओं और सबमिट किए गए टिकटों को बनाए रखने के लिए, Cloud Firestore का इस्तेमाल किया जाता है. अगर notifyUri से सफलता का रिस्पॉन्स नहीं मिलता है, तो ट्रिगर की सूचनाओं को अपने-आप फिर से भेजने के लिए, Cloud Tasks का इस्तेमाल किया जाता है. इसके अलावा, Gemini Enterprise Agent Platform पर Gemini 3.8 Flash (gemini-3.8-flash) का इस्तेमाल करके, कस्टम ऐक्शन चरण में टिकट की गंभीरता को कैटगरी में बांटा जाता है. इसके लिए, कीवर्ड मैचिंग वाले फ़ॉलबैक का इस्तेमाल किया जाता है.

आपको क्या बनाना होगा

  • Cloud Run पर Node.js, Express, Firestore, और Cloud Tasks की मदद से बनाया गया Support Quick Portal वेब ऐप्लिकेशन और एचटीटीपी Google Workspace ऐड-ऑन.
  • नया सहायता टिकट कस्टम स्टार्टर स्टेप (supportTicketTrigger), जो studio_triggers Firestore कलेक्शन में ऐक्टिव फ़्लो की सदस्यताओं को बनाए रखता है. साथ ही, सबमिट किए गए टिकटों को support_tickets Firestore कलेक्शन में लॉग करता है. इसके अलावा, वेब पोर्टल में टिकट सबमिट होने पर ट्रिगर होता है. साथ ही, ticketTitle और ticketDescription को Google Workspace Studio फ़्लो में पास करता है.
  • Cloud Tasks retry worker (studio-trigger-retries सूची और POST /api/tasks/fire-trigger) जो फ़ायरस्टोर में सेव किए गए नए userOAuthToken का इस्तेमाल करके, एक्सपोनेंशियल बैकऑफ़ के साथ ट्रिगर कॉल को सूची में जोड़ता है और फिर से कोशिश करता है. इससे notifyUri को डिलीवरी की गारंटी मिलती है.
  • Gemini Enterprise Agent Platform (aiplatform.googleapis.com) पर Gemini 3.8 Flash (gemini-3.8-flash) का इस्तेमाल करके, टिकट की गंभीरता को कैटगरी में बांटने वाला गंभीरता का पता लगाएं कस्टम ऐक्शन स्टेप (urgencyDetectorStep). इसमें कीवर्ड मैचिंग (urgent, blocker, critical) पर अपने-आप फ़ॉलबैक होने की सुविधा भी है.

आर्किटेक्चर

यहां दिए गए डायग्राम में बताया गया है कि Support Quick Portal, Cloud Run पर मौजूद आपका Node.js ऐड-ऑन, Cloud Firestore, Cloud Tasks (studio-trigger-retries), Gemini 3.8 Flash, और Google Workspace Studio, फ़्लो रजिस्ट्रेशन से लेकर ट्रिगर डिलीवरी और कार्रवाई को पूरा करने तक, एक-दूसरे के साथ कैसे इंटरैक्ट करते हैं:

Firestore, Cloud Tasks, और Gemini 3.8 Flash के साथ Google Workspace Studio Node.js ऐड-ऑन आर्किटेक्चर

आपको क्या सीखने को मिलेगा

  • workflowTrigger और workflowAction एलिमेंट के साथ, एचटीटीपी Google Workspace ऐड-ऑन डिप्लॉयमेंट मेनिफ़ेस्ट (deployment.json) को कॉन्फ़िगर करने का तरीका.
  • studio_triggers Firestore कलेक्शन में Google Workspace Studio ट्रिगर की सदस्यताओं (triggerId, notifyUri, और userOAuthToken) को बनाए रखने और notifyUri / triggers.fire का इस्तेमाल करके फ़्लो ट्रिगर करने का तरीका.
  • Cloud Tasks (@google-cloud/tasks) का इस्तेमाल करके, ट्रिगर की गई उन सूचनाओं को फिर से भेजने की कोशिश कैसे करें जो नहीं भेजी जा सकीं. इसके लिए, एक्सपोनेंशियल बैकऑफ़ का इस्तेमाल करें. ऐसा तब तक करें, जब तक notifyUri से 2xx रिस्पॉन्स न मिल जाए.
  • Gemini Enterprise के एजेंट प्लैटफ़ॉर्म पर, Gemini 3.8 Flash (gemini-3.8-flash) के स्ट्रक्चर्ड आउटपुट का इस्तेमाल करके, Node.js में workflowAction कस्टम चरण बनाने का तरीका. इसमें कीवर्ड फ़ॉलबैक का इस्तेमाल किया गया है.

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

  • Google Workspace खाता, जिसमें Google Workspace Studio का ऐक्सेस हो.
  • बिलिंग की सुविधा वाला Google Cloud प्रोजेक्ट. इसे उसी Google Workspace संगठन में बनाया गया हो जिसमें आपका उपयोगकर्ता खाता है. इससे, टेस्टिंग के लिए ऐड-ऑन के ऐसे डिप्लॉयमेंट इंस्टॉल किए जा सकते हैं जो पब्लिश नहीं किए गए हैं.

2. अपना Google क्लाउड प्रोजेक्ट, Firestore, और Cloud Tasks सेट अप करना

इस चरण में, आपको अपने प्रोजेक्ट की ऐसी स्क्रीन को कॉन्फ़िगर करना होगा जहां OAuth के लिए सहमति दी जाती है. साथ ही, Cloud Shell में ज़रूरी Google Cloud और Google Workspace API चालू करने होंगे. इसके बाद, आपको (default) Firestore डेटाबेस को सेट अप करना होगा और Cloud Tasks की फिर से कोशिश करने वाली सूची बनानी होगी. इसके बाद, ऐड-ऑन को अनुमति देने वाले सेवा खाते को शुरू करना होगा.

  1. Google Cloud console खोलें और अपना Google Cloud प्रोजेक्ट चुनें. इसके बाद, सबसे ऊपर मौजूद नेविगेशन बार में, Cloud Shell चालू करें आइकॉन पर क्लिक करें.
  2. OAuth के लिए सहमति वाली स्क्रीन को कॉन्फ़िगर करें, ताकि Google Workspace आपके ऐड-ऑन के लिए OAuth क्लाइंट उपलब्ध करा सके:
    1. Google Auth Platform का ब्रैंडिंग पेज खोलें.
    2. जब कहा जाए, तब शुरू करें पर क्लिक करें. (अगर ऐसी स्क्रीन जहां OAuth के लिए सहमति दी जाती है पहले से कॉन्फ़िगर की गई है, तो तीसरे चरण पर जाएं.)
    3. ऐप्लिकेशन की जानकारी में जाकर, ऐप्लिकेशन के नाम के लिए Support Extension डालें. इसके बाद, उपयोगकर्ता सहायता ईमेल चुनें और आगे बढ़ें पर क्लिक करें.
    4. ऑडियंस में जाकर, इंटरनल चुनें और आगे बढ़ें पर क्लिक करें.
    5. संपर्क जानकारी में जाकर, अपना ईमेल पता डालें और आगे बढ़ें पर क्लिक करें.
    6. पूरा करें में जाकर, Google API Services: उपयोगकर्ता के डेटा से जुड़ी नीति से सहमत हों. इसके बाद, जारी रखें पर क्लिक करें और फिर बनाएं पर क्लिक करें.
  3. Cloud Shell में, अपना ऐक्टिव प्रोजेक्ट सेट करें (YOUR_PROJECT_ID को अपने Google Cloud प्रोजेक्ट आईडी से बदलें) और ज़रूरी एपीआई चालू करें:
    gcloud config set project YOUR_PROJECT_ID
    gcloud services enable \
      aiplatform.googleapis.com \
      firestore.googleapis.com \
      cloudtasks.googleapis.com \
      run.googleapis.com \
      cloudbuild.googleapis.com \
      artifactregistry.googleapis.com \
      appsmarket-component.googleapis.com \
      gsuiteaddons.googleapis.com \
      workspacestudio.googleapis.com
    
  4. us-central1 में अपना (default) Firestore डेटाबेस और studio-trigger-retries Cloud Tasks सूची को सेट अप करें (अगर वे पहले से मौजूद नहीं हैं). इसके बाद, Google Workspace ऐड-ऑन सेवा खाते को शुरू करें:
    gcloud firestore databases describe --database="(default)" >/dev/null 2>&1 || \
      gcloud firestore databases create \
        --database="(default)" \
        --location=us-central1 \
        --type=firestore-native \
        --quiet
    
    gcloud tasks queues describe studio-trigger-retries --location=us-central1 >/dev/null 2>&1 || \
      gcloud tasks queues create studio-trigger-retries \
        --location=us-central1 \
        --max-attempts=5 \
        --min-backoff=10s \
        --max-backoff=300s \
        --max-doublings=4
    
    gcloud workspace-add-ons get-authorization
    

3. Firestore, Cloud Tasks, और Gemini 3.8 Flash की मदद से Node.js ऐप्लिकेशन बनाना

इस चरण में, ~/studio-support-addon में Node.js ऐप्लिकेशन बनाया जाता है. कोड को मॉड्यूलर और पढ़ने लायक बनाए रखने के लिए, प्रोजेक्ट को छह फ़ाइलों में व्यवस्थित किया जाता है:

  • firestore.js: यह Cloud Firestore क्लाइंट (studio_triggers और support_tickets कलेक्शन) को शुरू करता है और कैश मेमोरी में सेव किए गए OAuth टोकन को रीफ़्रेश करता है.
  • starter.js: नया सहायता टिकट कस्टम स्टार्टर स्टेप वेबहुक (/onConfigTrigger और /onManageTrigger) को लागू करता है.
  • action.js: Gemini 3.8 Flash (gemini-3.8-flash) का इस्तेमाल करके, ज़रूरी होने का पता लगाएं कस्टम ऐक्शन स्टेप वेबहुक (/onConfigUrgency और /onExecuteUrgency) को लागू करता है. साथ ही, कीवर्ड-मैचिंग फ़ॉलबैक का इस्तेमाल करता है.
  • tasks.js: यह trigger.notifyUri को ट्रिगर की सूचनाएं भेजता है. अगर यह उपलब्ध नहीं है, तो https://workspacestudio.googleapis.com/v1/triggers/{triggerId}:fire को भेजता है. साथ ही, डिलीवर न हो पाने वाली सूचनाओं को studio-trigger-retries Cloud Tasks की सूची में डालता है और POST /api/tasks/fire-trigger रीट्राय वर्कर एंडपॉइंट को लागू करता है.
  • portal.js: यह Support Quick Portal वेब यूज़र इंटरफ़ेस (GET /) को दिखाता है और Google Workspace Studio के चालू ट्रिगर (POST /api/submit-ticket) को ट्रिगर करता है. इसमें कुछ समय के लिए होने वाली गड़बड़ी को सिम्युलेट करने और Cloud Tasks को फिर से कोशिश करते हुए देखने का विकल्प होता है.
  • index.js: सभी Express रूट को एक साथ जोड़ता है और एचटीटीपी सर्वर को चालू करता है.

प्रोजेक्ट और package.json को शुरू करें

  1. प्रोजेक्ट डायरेक्ट्री बनाएं और उसमें जाएं:
    mkdir -p ~/studio-support-addon && cd ~/studio-support-addon
    
  2. express, @google-cloud/firestore, @google-cloud/tasks, और @google/genai के साथ package.json बनाएं:
    cat << 'EOF' > package.json
    {
      "name": "studio-support-addon",
      "version": "1.0.0",
      "type": "module",
      "main": "index.js",
      "scripts": {
        "start": "node index.js"
      },
      "dependencies": {
        "@google-cloud/firestore": "^7.11.0",
        "@google-cloud/tasks": "^5.6.0",
        "@google/genai": "^1.0.0",
        "express": "^4.21.2"
      }
    }
    EOF
    

firestore.js — शेयर किया गया Firestore स्टेटस और OAuth टोकन रीफ़्रेश करना

अपने दो Firestore कलेक्शन को मैनेज करने और कैश मेमोरी में सेव किए गए उपयोगकर्ता के OAuth टोकन को अपडेट रखने के लिए, firestore.js बनाएं:

  • studio_triggers: इसमें Google Workspace Studio के फ़्लो की चालू सदस्यताओं (triggerId, notifyUri, और userOAuthToken) को सेव किया जाता है, ताकि Cloud Run कंटेनर के रीस्टार्ट होने और स्केल-टू-ज़ीरो इवेंट के दौरान भी वे बनी रहें.
  • support_tickets: पोर्टल के ज़रिए सबमिट किए गए हर सहायता टिकट का रिकॉर्ड सेव करता है.
  • refreshTokenInFirestore(req): जब भी Google Workspace Studio आपके किसी वेबहुक एंडपॉइंट को कॉल करता है, तो उसमें कुछ समय के लिए मान्य authorizationEventObject.userOAuthToken शामिल होता है. यह हेल्पर, चालू ट्रिगर दस्तावेज़ों को नए टोकन के साथ अपडेट करता है, ताकि बैकग्राउंड में होने वाले triggers.fire कॉल को अनुमति मिलती रहे.
cat << 'EOF' > firestore.js
import { Firestore } from '@google-cloud/firestore';

export const db = new Firestore({
  projectId: process.env.GOOGLE_CLOUD_PROJECT || undefined,
  databaseId: '(default)',
  ignoreUndefinedProperties: true,
});

export const triggersCollection = db.collection(
  process.env.FIRESTORE_TRIGGERS_COLLECTION || 'studio_triggers'
);

export const ticketsCollection = db.collection(
  process.env.FIRESTORE_TICKETS_COLLECTION || 'support_tickets'
);

// Keep cached userOAuthToken fresh across active trigger documents
export async function refreshTokenInFirestore(req) {
  const freshToken = req.body?.authorizationEventObject?.userOAuthToken;
  if (!freshToken) return;
  try {
    const snapshot = await triggersCollection.get();
    if (snapshot.empty) return;
    const batch = db.batch();
    snapshot.docs.forEach((doc) => {
      batch.set(
        doc.ref,
        { userOAuthToken: freshToken, updatedAt: new Date().toISOString() },
        { merge: true }
      );
    });
    await batch.commit();
  } catch (err) {
    console.error('Error refreshing OAuth token in Firestore:', err.message);
  }
}
EOF

starter.js — कस्टम स्टार्टर स्टेप (workflowTrigger)

Google Workspace Studio के कस्टम स्टार्टर स्टेप के लिए ज़रूरी दो वेबहुक एंडपॉइंट लागू करने के लिए, starter.js बनाएं:

  • onConfigTrigger (POST /onConfigTrigger): इसे तब कॉल किया जाता है, जब कोई उपयोगकर्ता Google Workspace Studio में अपने फ़्लो के स्टार्टर के तौर पर, नया सहायता टिकट चुनता है. यह pushCard नेविगेशन ऐक्शन दिखाता है, जिसमें स्टार्टर के बारे में बताया गया है.
  • onManageTrigger (POST /onManageTrigger): इसे तब कॉल किया जाता है, जब कोई उपयोगकर्ता किसी फ़्लो को चालू (req.body.workflow.triggerCreation) करता है या उसे बंद / मिटाता (req.body.workflow.triggerDeletion) है. यह studio_triggers Firestore कलेक्शन में सदस्यता के दस्तावेज़ को सेव करता है या मिटाता है.
cat << 'EOF' > starter.js
import { triggersCollection, refreshTokenInFirestore } from './firestore.js';

// Custom Starter Configuration Card
export async function onConfigTrigger(req, res) {
  await refreshTokenInFirestore(req);
  res.status(200).json({
    action: {
      navigations: [
        {
          pushCard: {
            sections: [
              {
                header: 'Support Ticket Listener',
                widgets: [
                  {
                    textParagraph: {
                      text: 'This starter listens for new tickets submitted through the Support Quick Portal and stores subscriptions in Firestore.',
                    },
                  },
                ],
              },
            ],
          },
        },
      ],
    },
  });
}

// Custom Starter Subscription Lifecycle (Firestore studio_triggers collection)
export async function onManageTrigger(req, res) {
  try {
    const triggerCreation = req.body?.workflow?.triggerCreation;
    const triggerDeletion = req.body?.workflow?.triggerDeletion;
    const userOAuthToken =
      req.body?.authorizationEventObject?.userOAuthToken || null;

    if (triggerCreation?.triggerId) {
      const triggerId = String(triggerCreation.triggerId);
      const docId = encodeURIComponent(triggerId);
      await triggersCollection.doc(docId).set(
        {
          triggerId,
          notifyUri: triggerCreation.notifyUri || null,
          ...(userOAuthToken ? { userOAuthToken } : {}),
          updatedAt: new Date().toISOString(),
        },
        { merge: true }
      );
    }

    if (triggerDeletion?.triggerId) {
      const triggerId = String(triggerDeletion.triggerId);
      const docId = encodeURIComponent(triggerId);
      await triggersCollection.doc(docId).delete();
    }

    if (!triggerCreation && !triggerDeletion && userOAuthToken) {
      await refreshTokenInFirestore(req);
    }
  } catch (err) {
    console.error('Error in /onManageTrigger:', err.message);
  }
  res.status(200).json({});
}
EOF

action.js — Gemini 3.8 Flash के साथ कस्टम ऐक्शन का चरण (workflowAction)

Google Workspace Studio के कस्टम ऐक्शन चरण के लिए ज़रूरी दो वेबहुक एंडपॉइंट लागू करने के लिए, action.js बनाएं:

  • onConfigUrgency (POST /onConfigUrgency): यह कॉन्फ़िगरेशन कार्ड दिखाता है. इसमें textInput विजेट होता है, जो hostAppDataSource.workflowDataSource.includeVariables: true को सेट करता है. इससे उपयोगकर्ता, स्टार्टर चरण से आउटपुट किए गए ticketDescription वैरिएबल को चुन सकते हैं.
  • onExecuteUrgency (POST /onExecuteUrgency): यह req.body.workflow.actionInvocation.inputs से ticketDescription इनपुट को रीड करता है. साथ ही, Gemini Enterprise के एजेंट प्लैटफ़ॉर्म पर Gemini 3.8 Flash (gemini-3.8-flash) का इस्तेमाल करके, कारोबार पर इसके असर और ज़रूरी होने के हिसाब से इसे कैटगरी में बांटता है. इसके लिए, स्ट्रक्चर्ड आउटपुट (responseSchema enum ["High", "Normal"]) का इस्तेमाल किया जाता है. अगर मॉडल कॉल फ़ेल हो जाता है, तो यह detectKeywordUrgency() (urgent, blocker, critical) पर वापस चला जाता है. साथ ही, hostAppAction.workflowAction.returnOutputVariablesAction का इस्तेमाल करके urgencyLevel आउटपुट वैरिएबल दिखाता है.
cat << 'EOF' > action.js
import { GoogleGenAI, Type } from '@google/genai';
import { refreshTokenInFirestore } from './firestore.js';

// Initialize Google GenAI SDK for the Gemini Enterprise Agent Platform
const ai = new GoogleGenAI({
  vertexai: true,
  project: process.env.GOOGLE_CLOUD_PROJECT,
  location: 'global',
});

// Fallback keyword classifier if the Gemini API call is unavailable
export function detectKeywordUrgency(description) {
  const lower = (description || '').toLowerCase();
  return lower.includes('urgent') ||
    lower.includes('blocker') ||
    lower.includes('critical')
    ? 'High'
    : 'Normal';
}

// Custom Action Step Configuration Card
export async function onConfigUrgency(req, res) {
  await refreshTokenInFirestore(req);
  res.status(200).json({
    action: {
      navigations: [
        {
          pushCard: {
            sections: [
              {
                header: 'Urgency Detector Step',
                widgets: [
                  {
                    textInput: {
                      name: 'ticketDescription',
                      label: 'Source Description',
                      hintText:
                        'Select the description variable outputted by the starter',
                      hostAppDataSource: {
                        workflowDataSource: {
                          includeVariables: true,
                        },
                      },
                    },
                  },
                ],
              },
            ],
          },
        },
      ],
    },
  });
}

// Custom Action Step Execution: Gemini 3.8 Flash with keyword fallback
export async function onExecuteUrgency(req, res) {
  await refreshTokenInFirestore(req);
  const inputs = req.body?.workflow?.actionInvocation?.inputs || {};
  const description = inputs.ticketDescription?.stringValues?.[0] || '';

  let urgencyLevel = detectKeywordUrgency(description);
  try {
    const response = await ai.models.generateContent({
      model: 'gemini-3.8-flash',
      contents: `Evaluate the business impact and time sensitivity of this support ticket description and classify its urgency:\n\n${description}`,
      config: {
        responseMimeType: 'text/x.enum',
        responseSchema: {
          type: Type.STRING,
          enum: ['High', 'Normal'],
        },
      },
    });
    const candidate = (response.text || '').trim();
    if (candidate === 'High' || candidate === 'Normal') {
      urgencyLevel = candidate;
    }
  } catch (err) {
    console.error('Gemini fallback to keyword matching:', err.message);
  }

  res.status(200).json({
    hostAppAction: {
      workflowAction: {
        returnOutputVariablesAction: {
          variables: {
            urgencyLevel: {
              stringValues: [urgencyLevel],
            },
          },
        },
      },
    },
  });
}
EOF

tasks.js — Cloud Tasks की फिर से कोशिश करने वाली सूची और वर्कर एंडपॉइंट

trigger.notifyUri (https://workspacestudio.googleapis.com/v1/triggers/{triggerId}:fire पर वापस जाने के लिए) पर ट्रिगर कॉल भेजने के लिए, tasks.js बनाएं. साथ ही, फ़ेल हो चुके कॉल को अपनी studio-trigger-retries Cloud Tasks सूची में शामिल करें और POST /api/tasks/fire-trigger पर फिर से कोशिश करें:

  • resolveTriggerUrl(trigger): यह triggerCreation.notifyUri से सेव किए गए trigger.notifyUri का इस्तेमाल करता है. अगर यह मौजूद नहीं है, तो https://workspacestudio.googleapis.com/v1/triggers/{triggerId}:fire का इस्तेमाल करता है.
  • fireTriggerDirect(trigger, payload): यह ticketTitle और ticketDescription आउटपुट वैरिएबल और एक आइडमपोटेंट requestId के साथ, ट्रिगर यूआरएल को POST अनुरोध भेजता है.
  • enqueueTriggerRetry(req, payload): जब भी शुरुआती ट्रिगर कॉल पूरा नहीं हो पाता या 2xx के अलावा कोई एचटीटीपी स्टेटस दिखाता है, तब यह आपकी Cloud Run सेवा के POST /api/tasks/fire-trigger एंडपॉइंट को टारगेट करने वाली studio-trigger-retries सूची में एचटीटीपी टास्क को सूची में जोड़ता है.
  • handleFireTriggerTask (POST /api/tasks/fire-trigger): फिर से कोशिश करने पर, Cloud Tasks इसे हर बार शुरू करता है. यह Firestore से studio_triggers में मौजूद सबसे नया trigger दस्तावेज़ खोजता है. इससे यह पक्का होता है कि फिर से कोशिश करने पर, हमेशा सबसे नए userOAuthToken का इस्तेमाल किया जाए. साथ ही, यह X-CloudTasks-TaskRetryCount हेडर की जांच करता है. अगर simulateFailure चालू है, तो यह 503 के साथ Cloud Tasks के पहले एक्ज़ीक्यूशन को पूरा नहीं करता. इससे Cloud Tasks को बैक ऑफ़ होते हुए देखा जा सकता है और फिर से कोशिश करने पर, #1 को पूरा किया जा सकता है. इसके अलावा, यह 200 OK को सिर्फ़ तब दिखाता है, जब notifyUri से 2xx सफलता का रिस्पॉन्स मिलता है. 5xx रिस्पॉन्स मिलने पर, Cloud Tasks आपकी सूची की बैकऑफ़ नीति के मुताबिक फिर से कोशिश करता है.
cat << 'EOF' > tasks.js
import { CloudTasksClient } from '@google-cloud/tasks';
import { triggersCollection } from './firestore.js';

const tasksClient = new CloudTasksClient();
const PROJECT_ID = process.env.GOOGLE_CLOUD_PROJECT;
const LOCATION = process.env.CLOUD_TASKS_LOCATION || 'us-central1';
const QUEUE = process.env.CLOUD_TASKS_QUEUE || 'studio-trigger-retries';

// Prefer trigger.notifyUri from triggerCreation, falling back to triggers.fire
export function resolveTriggerUrl(trigger) {
  return (
    trigger.notifyUri ||
    `https://workspacestudio.googleapis.com/v1/triggers/${encodeURIComponent(trigger.triggerId)}:fire`
  );
}

// Call the Google Workspace Studio trigger URL directly
export async function fireTriggerDirect(
  trigger,
  { title, description, requestId }
) {
  const targetUrl = resolveTriggerUrl(trigger);
  const response = await fetch(targetUrl, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${trigger.userOAuthToken}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      name: 'triggers/' + trigger.triggerId,
      outputs: {
        ticketTitle: { stringValues: [title] },
        ticketDescription: { stringValues: [description] },
      },
      requestId,
    }),
  });
  return { ok: response.ok, status: response.status, targetUrl };
}

// Enqueue a retry task in Cloud Tasks targeting POST /api/tasks/fire-trigger
export async function enqueueTriggerRetry(req, payload) {
  const parent = tasksClient.queuePath(PROJECT_ID, LOCATION, QUEUE);
  const baseUrl = process.env.SERVICE_URL || `https://${req.get('host')}`;
  const workerUrl = `${baseUrl}/api/tasks/fire-trigger`;

  const task = {
    httpRequest: {
      httpMethod: 'POST',
      url: workerUrl,
      headers: { 'Content-Type': 'application/json' },
      body: Buffer.from(JSON.stringify(payload)).toString('base64'),
    },
  };

  const [response] = await tasksClient.createTask({ parent, task });
  return response.name;
}

// Cloud Tasks worker endpoint: retries calling notifyUri using fresh Firestore state
export async function handleFireTriggerTask(req, res) {
  const { triggerId, title, description, requestId, simulateFailure } =
    req.body || {};
  const retryCount = Number(req.get('X-CloudTasks-TaskRetryCount') || 0);

  if (!triggerId) {
    return res.status(200).json({ skipped: true, reason: 'Missing triggerId' });
  }

  try {
    const docId = encodeURIComponent(String(triggerId));
    const doc = await triggersCollection.doc(docId).get();
    if (!doc.exists) {
      return res
        .status(200)
        .json({ skipped: true, reason: 'Trigger no longer active' });
    }

    const trigger = doc.data();
    if (!trigger.userOAuthToken) {
      return res
        .status(503)
        .json({ ok: false, error: 'Missing userOAuthToken in Firestore' });
    }

    // When simulateFailure is enabled, fail the 1st Cloud Task attempt (retryCount === 0)
    // so learners can observe Cloud Tasks back off and succeed on retry #1.
    if (simulateFailure && retryCount < 1) {
      console.warn(
        `[Cloud Tasks] Simulated transient failure on initial task attempt (retryCount=${retryCount}) for trigger ${triggerId}`
      );
      return res
        .status(503)
        .json({ ok: false, simulated: true, retryCount, triggerId });
    }

    const outcome = await fireTriggerDirect(trigger, {
      title,
      description,
      requestId,
    });

    if (outcome.ok) {
      console.log(
        `[Cloud Tasks] Successfully delivered trigger ${triggerId} to ${outcome.targetUrl} on retryCount=${retryCount}`
      );
      return res
        .status(200)
        .json({ ok: true, status: outcome.status, retryCount });
    }

    console.error(
      `[Cloud Tasks] Non-2xx response (${outcome.status}) from ${outcome.targetUrl} on retryCount=${retryCount}`
    );
    return res
      .status(502)
      .json({ ok: false, status: outcome.status, retryCount });
  } catch (err) {
    console.error(
      `[Cloud Tasks] Error firing trigger ${triggerId} on retryCount=${retryCount}:`,
      err.message
    );
    return res
      .status(503)
      .json({ ok: false, error: err.message, retryCount });
  }
}
EOF

portal.js — Cloud Tasks फ़ॉलबैक के साथ, Support Quick Portal यूआई और notifyUri डिस्पैचर

वेब पोर्टल उपलब्ध कराने और Google Workspace Studio को टिकट सबमिशन भेजने के लिए, portal.js बनाएं. साथ ही, Cloud Tasks के लिए, फिर से कोशिश करने की सुविधा अपने-आप शेड्यूल होने की सुविधा चालू करें:

  • renderPortal (GET /): यह studio_triggers Firestore कलेक्शन से क्वेरी करता है, ताकि यह दिखाया जा सके कि Google Workspace Studio के कितने ट्रिगर रजिस्टर हैं. साथ ही, यह एचटीएमएल टिकट सबमिशन फ़ॉर्म दिखाता है. इसमें कुछ समय के लिए होने वाली गड़बड़ी को सिम्युलेट करें चेकबॉक्स भी शामिल है, ताकि Cloud Tasks के फिर से कोशिश करने की सुविधा को टेस्ट किया जा सके.
  • submitTicket (POST /api/submit-ticket): यह studio_triggers में मौजूद सभी चालू ट्रिगर दस्तावेज़ों को दोहराता है और fireTriggerDirect() को कॉल करता है. अगर ट्रिगर यूआरएल, 2xx के अलावा कोई और रिस्पॉन्स देता है, नेटवर्क की गड़बड़ी दिखाता है या उसमें simulateFailure चालू है, तो वह enqueueTriggerRetry() का इस्तेमाल करके studio-trigger-retries में फिर से कोशिश करने वाले टास्क को अपने-आप सूची में जोड़ देता है. साथ ही, टिकट को support_tickets Firestore कलेक्शन में लॉग करता है.
cat << 'EOF' > portal.js
import { triggersCollection, ticketsCollection } from './firestore.js';
import { fireTriggerDirect, enqueueTriggerRetry } from './tasks.js';

// Support Quick Portal UI
export async function renderPortal(req, res) {
  let activeCount = 0;
  try {
    const snapshot = await triggersCollection.get();
    activeCount = snapshot.size;
  } catch (err) {
    console.error('Error reading studio_triggers collection:', err.message);
  }

  res.status(200).send(`<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Support Quick Portal</title>
    <style>
      body { font-family: Arial, sans-serif; padding: 24px; max-width: 540px; margin: auto; color: #202124; }
      .badge { background: #e8f0fe; color: #1967d2; padding: 8px 12px; border-radius: 6px; font-size: 14px; margin-bottom: 16px; }
      label { font-weight: bold; display: block; margin-top: 16px; }
      .checkbox-label { font-weight: normal; margin-top: 14px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
      .checkbox-label input { width: auto; margin: 0; }
      input, textarea { width: 100%; margin-top: 6px; padding: 10px; box-sizing: border-box; border: 1px solid #dadce0; border-radius: 4px; }
      button { background-color: #1a73e8; color: white; border: none; padding: 10px 18px; margin-top: 16px; font-weight: bold; cursor: pointer; border-radius: 4px; }
      button:hover { background-color: #1557b0; }
      #status { margin-top: 16px; font-weight: bold; }
    </style>
  </head>
  <body>
    <h2>Support Quick Portal</h2>
    <div class="badge">
      Active Google Workspace Studio triggers in Firestore (<code>studio_triggers</code>):
      <strong id="trigger-count">${activeCount}</strong>
    </div>
    <p>Submit a support ticket below to fire your Google Workspace Studio flow.</p>

    <label for="title">Ticket Title</label>
    <input type="text" id="title" placeholder="e.g. Database failure">

    <label for="description">Issue Description</label>
    <textarea id="description" rows="4" placeholder="Describe the issue..."></textarea>

    <label class="checkbox-label" for="simulateFailure">
      <input type="checkbox" id="simulateFailure">
      Simulate transient failure (enqueue in Cloud Tasks and retry notifyUri)
    </label>

    <button onclick="submitTicket()">Submit Ticket</button>
    <div id="status"></div>

    <script>
      async function submitTicket() {
        const title = document.getElementById('title').value.trim();
        const description = document.getElementById('description').value.trim();
        const simulateFailure = document.getElementById('simulateFailure').checked;
        const statusEl = document.getElementById('status');

        if (!title || !description) {
          statusEl.style.color = '#d93025';
          statusEl.textContent = 'Please fill out both fields.';
          return;
        }

        statusEl.style.color = '#188038';
        statusEl.textContent = 'Submitting ticket...';

        try {
          const res = await fetch('/api/submit-ticket', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ title, description, simulateFailure }),
          });
          const data = await res.json();
          if (data.ok) {
            if (data.tasksQueued > 0) {
              statusEl.textContent =
                'Ticket saved! Initial notifyUri call did not succeed; queued ' +
                data.tasksQueued +
                ' retry task(s) in Cloud Tasks.';
            } else {
              statusEl.textContent =
                'Ticket saved to Firestore! Fired ' +
                data.triggersFired +
                ' Google Workspace Studio trigger(s).';
            }
          } else {
            statusEl.style.color = '#d93025';
            statusEl.textContent = 'Error: ' + (data.error || 'Unknown error');
          }
        } catch (err) {
          statusEl.style.color = '#d93025';
          statusEl.textContent = 'Request failed: ' + err.message;
        }
      }
    </script>
  </body>
</html>`);
}

// Portal Form Submission -> Call notifyUri directly, or enqueue Cloud Task on failure
export async function submitTicket(req, res) {
  const title = req.body?.title || 'Untitled Ticket';
  const description = req.body?.description || '';
  const simulateFailure = Boolean(req.body?.simulateFailure);
  const results = [];
  let triggersFired = 0;
  let tasksQueued = 0;

  try {
    const snapshot = await triggersCollection.get();
    for (const doc of snapshot.docs) {
      const trigger = doc.data();
      if (!trigger.triggerId || !trigger.userOAuthToken) continue;

      const requestId =
        'req_' + Date.now() + '_' + Math.floor(Math.random() * 1000);

      let outcome = { ok: false, status: 503 };
      if (!simulateFailure) {
        try {
          outcome = await fireTriggerDirect(trigger, {
            title,
            description,
            requestId,
          });
        } catch (fetchErr) {
          console.error(
            `Direct trigger call failed for ${trigger.triggerId}:`,
            fetchErr.message
          );
          outcome = { ok: false, status: 0, error: fetchErr.message };
        }
      }

      if (outcome.ok) {
        triggersFired++;
        results.push({
          triggerId: trigger.triggerId,
          status: outcome.status,
          queuedRetry: false,
        });
      } else {
        const taskName = await enqueueTriggerRetry(req, {
          triggerId: trigger.triggerId,
          title,
          description,
          requestId,
          simulateFailure,
        });
        tasksQueued++;
        results.push({
          triggerId: trigger.triggerId,
          status: outcome.status,
          queuedRetry: true,
          taskName,
        });
      }
    }

    await ticketsCollection.add({
      title,
      description,
      triggersFired,
      tasksQueued,
      createdAt: new Date().toISOString(),
    });

    res.status(200).json({
      ok: true,
      triggersFired,
      tasksQueued,
      results,
    });
  } catch (err) {
    console.error('Error in /api/submit-ticket:', err.message);
    res.status(500).json({ ok: false, error: err.message });
  }
}
EOF

index.js — Express सर्वर का एंट्री पॉइंट

index.js बनाएं, ताकि आपके पोर्टल के रूट, Cloud Tasks के फिर से कोशिश करने वाले वर्कर एंडपॉइंट, और Google Workspace Studio के वेबहुक एंडपॉइंट को एक साथ Express एचटीटीपी सर्वर में जोड़ा जा सके. यह सर्वर, PORT (Cloud Run पर डिफ़ॉल्ट रूप से 8080) पर सुनता है:

cat << 'EOF' > index.js
import express from 'express';
import { onConfigTrigger, onManageTrigger } from './starter.js';
import { onConfigUrgency, onExecuteUrgency } from './action.js';
import { renderPortal, submitTicket } from './portal.js';
import { handleFireTriggerTask } from './tasks.js';

const app = express();
app.use(express.json());

// Support Quick Portal routes
app.get('/', renderPortal);
app.post('/api/submit-ticket', submitTicket);

// Cloud Tasks retry worker route
app.post('/api/tasks/fire-trigger', handleFireTriggerTask);

// Google Workspace Studio Custom Starter Step webhooks
app.post('/onConfigTrigger', onConfigTrigger);
app.post('/onManageTrigger', onManageTrigger);

// Google Workspace Studio Custom Action Step webhooks
app.post('/onConfigUrgency', onConfigUrgency);
app.post('/onExecuteUrgency', onExecuteUrgency);

const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Support Extension listening on port ${PORT}`);
});
EOF

4. Cloud Run पर डिप्लॉय करना और ऐड-ऑन इंस्टॉल करना

इस चरण में, Node.js सेवा को Cloud Run पर डिप्लॉय किया जाता है. साथ ही, Google Workspace ऐड-ऑन को शुरू करने वाले टूल और Firestore, Cloud Tasks, और एजेंट प्लैटफ़ॉर्म के रनटाइम ऐक्सेस के लिए, आईएएम की अनुमतियां दी जाती हैं. इसके अलावा, deployment.json मेनिफ़ेस्ट जनरेट किया जाता है और ऐड-ऑन डिप्लॉयमेंट इंस्टॉल किया जाता है.

  1. अपने प्रोजेक्ट, Firestore कलेक्शन, और Cloud Tasks की सूची के एनवायरमेंट वैरिएबल के साथ, support-extension सेवा को Cloud Run पर डिप्लॉय करें:
    gcloud run deploy support-extension \
      --source . \
      --region us-central1 \
      --allow-unauthenticated \
      --set-env-vars="GOOGLE_CLOUD_PROJECT=$(gcloud config get-value project),FIRESTORE_TRIGGERS_COLLECTION=studio_triggers,FIRESTORE_TICKETS_COLLECTION=support_tickets,CLOUD_TASKS_QUEUE=studio-trigger-retries,CLOUD_TASKS_LOCATION=us-central1" \
      --quiet
    
  2. Google Workspace ऐड-ऑन सेवा खाते को Cloud Run सेवा पर roles/run.invoker की अनुमति दें, ताकि Google Workspace Studio आपके वेबहुक एंडपॉइंट को कॉल कर सके:
    ADDON_SA=$(gcloud workspace-add-ons get-authorization --format="value(serviceAccountEmail)")
    gcloud run services add-iam-policy-binding support-extension \
      --region=us-central1 \
      --member="serviceAccount:${ADDON_SA}" \
      --role="roles/run.invoker" \
      --quiet
    
  3. Cloud Run रनटाइम सेवा खाते को roles/datastore.user (studio_triggers और support_tickets Firestore कलेक्शन को पढ़ने और लिखने के लिए), roles/cloudtasks.enqueuer (फिर से कोशिश करने वाले टास्क को studio-trigger-retries में सूची में जोड़ने के लिए), और roles/aiplatform.user (Gemini Enterprise Agent Platform पर Gemini को कॉल करने के लिए) की अनुमति दें:
    PROJECT_ID=$(gcloud config get-value project)
    PROJECT_NUMBER=$(gcloud projects describe "${PROJECT_ID}" --format="value(projectNumber)")
    RUNTIME_SA=$(gcloud run services describe support-extension --region=us-central1 --format="value(spec.template.spec.serviceAccountName)")
    RUNTIME_SA=${RUNTIME_SA:-"${PROJECT_NUMBER}-compute@developer.gserviceaccount.com"}
    
    gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
      --member="serviceAccount:${RUNTIME_SA}" \
      --role="roles/datastore.user" \
      --condition=None \
      --quiet
    
    gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
      --member="serviceAccount:${RUNTIME_SA}" \
      --role="roles/cloudtasks.enqueuer" \
      --condition=None \
      --quiet
    
    gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
      --member="serviceAccount:${RUNTIME_SA}" \
      --role="roles/aiplatform.user" \
      --condition=None \
      --quiet
    
  4. डिप्लॉय किए गए Cloud Run यूआरएल को वापस पाएं और deployment.json मेनिफ़ेस्ट जनरेट करें. इसमें supportTicketTrigger (workflowTrigger) और urgencyDetectorStep (workflowAction) एलिमेंट के बारे में जानकारी दें:
    SERVICE_URL=$(gcloud run services describe support-extension --region=us-central1 --format="value(status.url)")
    
    cat << EOF > deployment.json
    {
      "oauthScopes": [
        "https://www.googleapis.com/auth/workspace.studio.trigger",
        "https://www.googleapis.com/auth/userinfo.email"
      ],
      "addOns": {
        "common": {
          "name": "Support Extension",
          "logoUrl": "https://www.gstatic.com/images/branding/productlogos/buganizer/v1/192px.svg"
        },
        "studio": {
          "flows": {
            "workflowElements": [
              {
                "id": "supportTicketTrigger",
                "state": "ACTIVE",
                "name": "New Support Ticket",
                "description": "Fires when someone submits a ticket in the Support Quick Portal.",
                "workflowTrigger": {
                  "inputs": [],
                  "outputs": [
                    {
                      "id": "ticketTitle",
                      "description": "Ticket Title",
                      "cardinality": "SINGLE",
                      "dataType": { "basicType": "STRING" }
                    },
                    {
                      "id": "ticketDescription",
                      "description": "Ticket Description",
                      "cardinality": "SINGLE",
                      "dataType": { "basicType": "STRING" }
                    }
                  ],
                  "onConfigFunction": "${SERVICE_URL}/onConfigTrigger",
                  "onManageFunction": "${SERVICE_URL}/onManageTrigger"
                }
              },
              {
                "id": "urgencyDetectorStep",
                "state": "ACTIVE",
                "name": "Detect Urgency",
                "description": "Evaluates the ticket description to detect High or Normal urgency.",
                "workflowAction": {
                  "inputs": [
                    {
                      "id": "ticketDescription",
                      "description": "Description to scan",
                      "cardinality": "SINGLE",
                      "dataType": { "basicType": "STRING" }
                    }
                  ],
                  "outputs": [
                    {
                      "id": "urgencyLevel",
                      "description": "Detected Urgency (High / Normal)",
                      "cardinality": "SINGLE",
                      "dataType": { "basicType": "STRING" }
                    }
                  ],
                  "onConfigFunction": "${SERVICE_URL}/onConfigUrgency",
                  "onExecuteFunction": "${SERVICE_URL}/onExecuteUrgency"
                }
              }
            ]
          }
        },
        "httpOptions": {
          "authorizationHeader": "SYSTEM_ID_TOKEN"
        }
      }
    }
    EOF
    
  5. अपने खाते के लिए, Google Workspace ऐड-ऑन डिप्लॉयमेंट बनाएं (या बदलें) और इंस्टॉल करें. साथ ही, सहायता के लिए क्विक पोर्टल का यूआरएल प्रिंट करें:
    gcloud workspace-add-ons deployments create support-extension --deployment-file=deployment.json || \
      gcloud workspace-add-ons deployments replace support-extension --deployment-file=deployment.json
    gcloud workspace-add-ons deployments install support-extension
    echo "Support Quick Portal URL: ${SERVICE_URL}"
    

5. कस्टम स्टेप और Cloud Tasks की फिर से कोशिश करने की सुविधा को टेस्ट करना

  1. Google Workspace Studio खोलें. अगर यह पहले से खुला है, तो ब्राउज़र टैब को रीफ़्रेश करें. इसके बाद, नया फ़्लो पर क्लिक करें.
  2. स्टार्टर चुनें > सहायता एक्सटेंशन > नया सहायता टिकट पर क्लिक करें.
  3. Add step (+) > Support Extension > Detect Urgency पर क्लिक करें. सोर्स की जानकारी फ़ील्ड में, + वैरिएबल पर क्लिक करें. इसके बाद, टिकट की जानकारी चुनें.
  4. चरण जोड़ें (+) पर क्लिक करें. इसके बाद, Chat > मुझे Chat में सूचना दें चरण जोड़ें. इसमें मैसेज में टिकट का टाइटल, ज़रूरी होने का लेवल, और टिकट की जानकारी वैरिएबल शामिल करें.
  5. सबसे ऊपर दाएं कोने में मौजूद, फ़्लो को चालू करें पर टॉगल करें. Google Workspace Studio, Cloud Run पर आपके /onManageTrigger एंडपॉइंट को तुरंत कॉल करता है. यह एंडपॉइंट, Firestore में studio_triggers कलेक्शन में, चालू ट्रिगर की सदस्यता (इसमें triggerId, notifyUri, और userOAuthToken शामिल हैं) को लिखता है.
  6. Support Quick Portal का यूआरएल (https://support-extension-...run.app) नए टैब में खोलें. इसके बाद, पुष्टि करें कि पोर्टल, Firestore में 1 चालू ट्रिगर दिखाता है. साथ ही, Gemini 3.8 Flash (gemini-3.8-flash) के क्लासिफ़िकेशन की जांच करने के लिए, दो टिकट सबमिट करें:
    • ज़्यादा असर वाला टिकट (टिकट का टाइटल: London office lockout, समस्या की जानकारी: All 500 employees in the London office are locked out of their workstations 20 minutes before the board presentation.): urgent या blocker जैसे हार्डकोड किए गए कीवर्ड के बिना भी, gemini-3.8-flash इस टिकट को High अर्जेंसी के तौर पर कैटगरी में बांटता है.
    • रूटीन टिकट (टिकट का टाइटल: Conference room adapters, समस्या की जानकारी: Could we order two extra HDMI adapters for the third-floor conference room next month?): gemini-3.8-flash इस टिकट को Normal अर्जेंसी के तौर पर कैटगरी में बांटता है.
  7. Google Chat और Google Workspace Studio के गतिविधि टैब में जाकर, पुष्टि करें कि आपका फ़्लो, Urgency Level: High और Urgency Level: Normal, दोनों टिकट के लिए चला है.
  8. notifyUri के काम न करने पर, Cloud Tasks की डिलीवरी फिर से करने की सुविधा को टेस्ट करें:
    1. Support Quick Portal में जाकर, Simulate transient failure (enqueue in Cloud Tasks and retry notifyUri) को चुनें.
    2. टिकट का टाइटल: Checkout service outage और समस्या की जानकारी: Production payment gateway is timing out for all customers डालें. इसके बाद, टिकट सबमिट करें पर क्लिक करें.
    3. ध्यान दें कि पोर्टल तुरंत यह जवाब देता है: Ticket saved! Initial notifyUri call did not succeed; queued 1 retry task(s) in Cloud Tasks.
    4. बैकग्राउंड में, Cloud Tasks POST /api/tasks/fire-trigger को एक्ज़ीक्यूट करता है. टास्क को पूरा करने की पहली कोशिश (retryCount=0) में, 503 गड़बड़ी को सिम्युलेट किया जाता है. इसकी वजह से, Cloud Tasks 10s (--min-backoff=10s) के लिए बैक ऑफ़ करता है और फिर से कोशिश (retryCount=1) करता है. इससे notifyUri को कॉल किया जाता है और टास्क पूरा हो जाता है. करीब 10 से 15 सेकंड बाद, पुष्टि करें कि आपको Google Chat की सूचना मिली है!

6. व्यवस्थित करें

अपने Google Cloud खाते पर लगने वाले शुल्क से बचने के लिए, Cloud Shell में डिप्लॉय किए गए संसाधनों को हटाएं:

gcloud workspace-add-ons deployments uninstall support-extension
gcloud workspace-add-ons deployments delete support-extension --quiet
gcloud run services delete support-extension --region=us-central1 --quiet
gcloud tasks queues delete studio-trigger-retries --location=us-central1 --quiet
gcloud firestore databases delete --database="(default)" --quiet

7. बधाई हो!

आपने Gemini Enterprise Agent Platform पर Firestore, Cloud Tasks, Cloud Run, और Gemini 3.8 Flash का इस्तेमाल करके, Google Workspace Studio के लिए Node.js एचटीटीपी एक्सटेंशन बनाया, डिप्लॉय किया, और टेस्ट किया!

हमने क्या-क्या कवर किया

  • workflowTrigger और workflowAction एलिमेंट के साथ, Google Workspace Studio के एचटीटीपी ऐड-ऑन मेनिफ़ेस्ट (deployment.json) को कॉन्फ़िगर करना.
  • studio_triggers Firestore कलेक्शन में Google Workspace Studio workflowTrigger की सदस्यताओं को सेव करना और पोर्टल सबमिशन को support_tickets में लॉग करना, ताकि ट्रिगर Cloud Run स्केलिंग और फिर से डिप्लॉयमेंट के बाद भी काम करते रहें.
  • Cloud Tasks (studio-trigger-retries) की मदद से, notifyUri (triggers.fire) की डिलीवरी की गारंटी देना. इससे, एचटीटीपी की अस्थायी गड़बड़ियों को एक्सपोनेंशियल बैकऑफ़ के साथ अपने-आप ठीक किया जाता है. इसके लिए, Firestore के नए userOAuthToken का इस्तेमाल किया जाता है.
  • Gemini Enterprise एजेंट प्लैटफ़ॉर्म पर, Gemini 3.8 Flash (gemini-3.8-flash) के स्ट्रक्चर्ड आउटपुट की मदद से, सहायता टिकटों को कैटगरी में बांटने वाला workflowAction चरण बनाना. इसमें कीवर्ड मैचिंग की सुविधा भी शामिल है.

अगले चरण