See llms.txt for all machine-readable content.

Back to Templates

Send daily AI briefings from Postgres to Telegram with OpenAI

Quick overview

This workflow runs every morning, pulls operational and CRM data from PostgreSQL, checks two service health endpoints over HTTP, uses OpenAI to write a short prioritized daily briefing, and sends the briefing to a Telegram chat.

How it works

  1. Runs every day at 08:00 on a schedule.
  2. Queries PostgreSQL for up to 10 action logs that are pending approval, then fetches up to 10 overdue follow-ups and a pipeline status breakdown.
  3. Calls two HTTP health-check endpoints and converts their responses into a single UP/DOWN service status summary.
  4. Sends the PostgreSQL results and service status summary to OpenAI to generate a plain-text bullet briefing capped at 15 lines and ordered by urgency.
  5. Posts the generated briefing to the configured Telegram chat.

Setup

  1. Add PostgreSQL credentials and update the three SQL queries to match your tables and fields.
  2. Add an OpenAI API credential (or compatible OpenAI connection) and choose the chat model you want to use.
  3. Add Telegram bot credentials, then set your target Telegram chat ID in the Config values.
  4. Set the two health-check URLs in the Config values to endpoints that return HTTP 200 when healthy.
  5. Adjust the schedule time if 08:00 is not suitable for your timezone or routine.

Requirements

  • PostgreSQL database with your tasks, approvals or CRM data
  • OpenAI API key (any chat model supported by the AI Agent node also works)
  • Telegram bot token and the chat ID that should receive the briefing

Customization

  • Add more queries (invoices due, open tickets) and reference them in the agent prompt
  • Send the briefing to Slack, Microsoft Teams or email instead of Telegram
  • Swap OpenAI for Gemini, Claude or a local model, or run it twice a day

Additional info

Tested on self-hosted n8n with Postgres 16, OpenAI gpt-4.1-mini and Telegram, including the case where a health endpoint is unreachable (the briefing then opens with an alert) and the case where a query returns no rows. Health checks continue on error, so one failing service never stops the briefing.