In my workflow using a Telegram trigger, an AI agent, and two Google Calendar tools, creating an event immediately leads to an availability check that incorrectly shows the time slot as free, resulting in an inconsistency

  • Why does the availability check indicate that I’m free at a specific date and time immediately after creating an event in that exact slot?
  • Could there be a synchronization or caching issue causing the system to overlook the newly created event?
  • Is there a potential misconfiguration in my workflow or API settings (using a Telegram trigger, an AI agent, and two separate Google Calendar tools) that might lead to this inconsistency?
  • What steps can I take to ensure that the availability check accurately reflects the recently created event?

Here is the workflow
please help :wink:

{
“nodes”: [
{
“parameters”: {
“promptType”: “define”,
“text”: “={{ $json.message.text }}”,
“options”: {
“systemMessage”: “=# Tu es un assistant dédié à la gestion d’agenda.\n\n## Contexte\n- Nous sommes le {{$json["currentDate"]}}.\n- Le message de l’utilisateur est : {{ $json.message.text }}\n\n## Outils disponibles\n1. Google_Calendar_Availability \n - Pour consulter les événements de l’agenda et vérifier les disponibilités.\n2. Google_Calendar_Events \n - Pour créer des événements dans l’agenda.\n\n## Règles\n\n### 1. Création d’événement\n- Lorsque l’utilisateur demande de créer un événement, utilise Google_Calendar_Events.\n- Fournis obligatoirement :\n - La date\n - L’heure de début\n - L’heure de fin (si l’utilisateur ne précise pas, considère 1 heure par défaut)\n - Le titre (summary)\n - La description\n- Le champ summary doit inclure le titre exact fourni par l’utilisateur (ou un titre par défaut, par ex. “Événement”).\n\n### 2. Consultation d’événement (vérification de disponibilité)\n- Lorsque l’utilisateur souhaite vérifier sa disponibilité, utilise Google_Calendar_Availability pour interroger l’agenda.\n- Ne l’utilise pas pour créer un événement.\n\n### 3. Calcul de la date\n- Ignore toute autre source de date.\n- Si l’utilisateur mentionne une date relative (ex. “vendredi prochain”), calcule la date à partir de {{$json["currentDate"]}}.\n- Si le jour mentionné est déjà passé ou correspond à aujourd’hui, bascule sur le même jour de la semaine suivante.\n- Ne propose jamais de date différente de celle calculée selon ces règles.\n\n### 4. Titre (summary)\n- Ne crée jamais d’événement sans titre. \n- Le titre (summary) doit inclure la date et l’horaire.\n\n### 5. Sortie JSON stricte\n- Lorsque tu appelles Google_Calendar_Events pour créer un événement, renvoie uniquement du JSON valide (sans texte additionnel, sans Markdown).\n- Idem pour Google_Calendar_Availability : renvoie seulement la structure JSON attendue.\n\n—\n”
}
},
“type”: “@n8n/n8n-nodes-langchain.agent”,
“typeVersion”: 1.7,
“position”: [
1720,
320
],
“id”: “f1d8dd19-54bd-4e09-b61b-226315f1573b”,
“name”: “AI Agent”
},
{
“parameters”: {
“updates”: [
“message”
],
“additionalFields”: {}
},
“type”: “n8n-nodes-base.telegramTrigger”,
“typeVersion”: 1.1,
“position”: [
1280,
320
],
“id”: “6eeed94b-6d2a-4572-a24d-cf74cab346c8”,
“name”: “Telegram Message”,
“webhookId”: “969fe005-abe4-470f-88ea-f323f1135e82”,
“credentials”: {
“telegramApi”: {
“id”: “hjpttljMqWaVLeha”,
“name”: “Telegram account”
}
}
},
{
“parameters”: {
“jsCode”: “// On récupère tous les items reçus en entrée\nconst items = $input.all();\n\n// Pour chacun, on définit un nouveau champ "currentDate"\nfor (const item of items) {\n // On génère la date du jour\n const now = new Date();\n\n // Récupération du jour, du mois et de l’année avec un format à deux chiffres pour le jour et le mois\n const day = String(now.getDate()).padStart(2, ‘0’);\n const month = String(now.getMonth() + 1).padStart(2, ‘0’);\n const year = now.getFullYear();\n\n // Formatage en JJ-MM-AAAA\n const formattedDate = `${day}-${month}-${year}`;\n\n // On assigne la date formatée au champ "currentDate"\n item.json.currentDate = formattedDate;\n}\n\n// On renvoie tous les items, chacun ayant maintenant item.json.currentDate\nreturn items;”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
1500,
320
],
“id”: “1cc5ff2f-be82-4cf6-a563-b94331030858”,
“name”: “Current_Date”
},
{
“parameters”: {
“options”: {}
},
“type”: “@n8n/n8n-nodes-langchain.lmChatOpenRouter”,
“typeVersion”: 1,
“position”: [
1580,
600
],
“id”: “1b824df2-6706-46fc-9856-377bcf896f03”,
“name”: “OpenRouter Chat Model”,
“credentials”: {
“openRouterApi”: {
“id”: “JNG6vMIUc6SlgvzY”,
“name”: “OpenRouter account”
}
}
},
{
“parameters”: {
“sessionIdType”: “customKey”,
“sessionKey”: “={{ $json.update_id }}”,
“contextWindowLength”: 10
},
“type”: “@n8n/n8n-nodes-langchain.memoryBufferWindow”,
“typeVersion”: 1.3,
“position”: [
1720,
600
],
“id”: “c1dd22f4-892f-465b-b145-70e76856b806”,
“name”: “Simple Memory”
},
{
“parameters”: {
“chatId”: “={{ $(‘Telegram Message’).item.json.message.chat.id }}”,
“text”: “={{ $json.output }}”,
“additionalFields”: {
“appendAttribution”: false
}
},
“type”: “n8n-nodes-base.telegram”,
“typeVersion”: 1.2,
“position”: [
2080,
320
],
“id”: “d8555a00-9c5f-4a16-ba38-37a86be3ecb9”,
“name”: “Telegram”,
“webhookId”: “5c73bf3b-ef90-4075-b63c-86c4bfd2379b”,
“credentials”: {
“telegramApi”: {
“id”: “hjpttljMqWaVLeha”,
“name”: “Telegram account”
}
}
},
{
“parameters”: {
“resource”: “calendar”,
“calendar”: {
“__rl”: true,
“value”: “57190c329700ce4e213a1d7aa8d1dd4b0545c1b5242812b57c7820976a675668@group.calendar.google.com”,
“mode”: “list”,
“cachedResultName”: “Général”
},
“timeMin”: “={{ /n8n-auto-generated-fromAI-override/ $fromAI(‘Start_Time’, ``, ‘string’) }}”,
“timeMax”: “={{ /n8n-auto-generated-fromAI-override/ $fromAI(‘End_Time’, ``, ‘string’) }}”,
“options”: {
“outputFormat”: “availability”,
“timezone”: {
“__rl”: true,
“value”: “Europe/Paris”,
“mode”: “list”,
“cachedResultName”: “Europe/Paris”
}
}
},
“type”: “n8n-nodes-base.googleCalendarTool”,
“typeVersion”: 1.3,
“position”: [
2240,
600
],
“id”: “df7db254-f657-4d12-bac5-f4ae9b253f93”,
“name”: “Google_Calendar_Availability”,
“credentials”: {
“googleCalendarOAuth2Api”: {
“id”: “lPXu7sq0mHsiLUAc”,
“name”: “Google Calendar account 2”
}
}
},
{
“parameters”: {
“calendar”: {
“__rl”: true,
“value”: “57190c329700ce4e213a1d7aa8d1dd4b0545c1b5242812b57c7820976a675668@group.calendar.google.com”,
“mode”: “list”,
“cachedResultName”: “Général”
},
“start”: “={{ /n8n-auto-generated-fromAI-override/ $fromAI(‘Start’, ``, ‘string’) }}”,
“end”: “={{ /n8n-auto-generated-fromAI-override/ $fromAI(‘End’, ``, ‘string’) }}”,
“useDefaultReminders”: “={{ /n8n-auto-generated-fromAI-override/ $fromAI(‘Use_Default_Reminders’, ``, ‘boolean’) }}”,
“additionalFields”: {
“description”: “={{ /n8n-auto-generated-fromAI-override/ $fromAI(‘Description’, ``, ‘string’) }}”,
“showMeAs”: “opaque”,
“summary”: “={{ /n8n-auto-generated-fromAI-override/ $fromAI(‘Summary’, ``, ‘string’) }}”
}
},
“type”: “n8n-nodes-base.googleCalendarTool”,
“typeVersion”: 1.3,
“position”: [
2040,
600
],
“id”: “2147adb6-6bd2-4018-8b73-4f2c3f9fbf41”,
“name”: “Google_Calendar_Events”,
“credentials”: {
“googleCalendarOAuth2Api”: {
“id”: “lPXu7sq0mHsiLUAc”,
“name”: “Google Calendar account 2”
}
}
}
],
“connections”: {
“AI Agent”: {
“main”: [
[
{
“node”: “Telegram”,
“type”: “main”,
“index”: 0
}
]
]
},
“Telegram Message”: {
“main”: [
[
{
“node”: “Current_Date”,
“type”: “main”,
“index”: 0
}
]
]
},
“Current_Date”: {
“main”: [
[
{
“node”: “AI Agent”,
“type”: “main”,
“index”: 0
}
]
]
},
“OpenRouter Chat Model”: {
“ai_languageModel”: [
[
{
“node”: “AI Agent”,
“type”: “ai_languageModel”,
“index”: 0
}
]
]
},
“Simple Memory”: {
“ai_memory”: [
[
{
“node”: “AI Agent”,
“type”: “ai_memory”,
“index”: 0
}
]
]
},
“Google_Calendar_Availability”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
},
“Google_Calendar_Events”: {
“ai_tool”: [
[
{
“node”: “AI Agent”,
“type”: “ai_tool”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “5f4b6adcc32bdda4009cb0297e0e49d68df6d6d50886acf2b5cb773f6eeac789”
}
}

Simplified Answer:

Hello! Let’s unravel the mystery of the “phantom availability” in your workflow. The issue likely stems from a combination of Google Calendar API delays and workflow configuration. Here’s the step-by-step fix:

Step 1: Understand Google Calendar API Delays

The Google Calendar API isn’t instantaneous. When you create an event, it can take up to 1 minute to reflect in availability checks. This explains why the slot appears free immediately after creation.

Quick Fix:
Add a “Wait” node between event creation and availability checks. Set it to wait 30-60 seconds.

Step 2: Verify Calendar IDs

Your workflow has two Google Calendar nodes:

  1. Google_Calendar_Events (creates events)
  2. Google_Calendar_Disponibilidade (checks availability)

Ensure both use the same calendar ID:

  • In the Google_Calendar_Disponibilidade node, the Calendar field is set to:
    57190c329700ce4e213a1d7aa8d1dd1b4b0545c1b1b1b1b1b1b5242812bptoc78297a6765668-group.calendar.google.com  
    
    Confirm the Google_Calendar_Events node uses the exact same ID.

Step 3: Adjust Timezone Settings

The Google_Calendar_Disponibilidade node uses Europe/Paris as its timezone. If your primary calendar uses a different zone (e.g., America/Sao_Paulo), this causes mismatches.

Fix:

  • Update the Time Zone to match your Google Calendar’s setting.

Step 4: Validate Date/Time Formats

In the Google_Calendar_Events node, the Start and End fields map to $fromAI('Start', ..., 'string') and $fromAI('End', ..., 'string').

Common Issue:
If the AI agent returns dates in a format Google Calendar doesn’t recognize (e.g., 15h30 instead of 2024-05-28T15:30:00), event creation fails silently.

Solution:
Add a Function node after the AI agent to format dates:

// Example: Convert "15h30" to "2024-05-28T15:30:00"  
const date = new Date();  
const [hour, minute] = $json.Start.split('h');  
date.setHours(hour, minute);  

return {  
  start: date.toISOString(),  
  end: // similar logic for end time  
};  

Step 5: Enable Detailed Logging

Add Debug nodes after critical steps (event creation, availability check) to inspect:

  1. Whether the event was created successfully.
  2. If the availability check is querying the correct time range.

Adjusted Workflow:

Telegram → AI Agent → Function (format dates) → Google_Calendar_Events → Wait (60s) → Google_Calendar_Disponibilidade → Telegram  

If the Issue Persists:

  1. Review Google Permissions: Ensure your OAuth token has the scopes https://www.googleapis.com/auth/calendar.events and https://www.googleapis.com/auth/calendar.readonly.
  2. Test Manually: Use the Google API Explorer to create an event and check if it appears immediately.

Good luck! If you need further help, share a screenshot of the Google_Calendar_Events node logs.

Best regards,
Dandy

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.