Telegram Bot for Chat and Image Responses

This workflow creates an AI-powered Telegram bot API using OpenAI for chat and image generation. Key nodes include Webhook (handles POST requests at /api/telegram-bot), Input Validation (processes message and user data), Check Input Message (validates input), Configure Settings (sets AI parameters), Route Command (handles /start, /image, or chat), OpenAI nodes (Generate Greeting, Generate Image, Generate Chat Response using gpt-4), Format Response nodes, Success Response (returns JSON), and Error Response (handles invalid inputs). Customize by updating system_command in Configure Settings.\n\nSetup Requirements and Configuration: Install n8n from n8n.io for self-hosting or sign up at cloud.n8n.io. Obtain an OpenAI API key from platform.openai.com under ‘API Keys.’ Import the JSON workflow in n8n. Configure Generate Greeting, Generate Image, and Generate Chat Response nodes with the OpenAI API key under ‘Credentials.’ Set the Webhook node to use HTTPS and path ‘api/telegram-bot’ under Settings > Webhook. Ensure your server supports HTTPS for secure webhook access. For local testing, use a tunneling service like ngrok. Verify internet connectivity for OpenAI API requests. No Telegram API credentials are needed, as the workflow processes external Telegram requests.\n\nTesting and Deployment Steps: Activate the workflow to get the Webhook URL (e.g., https://your-n8n-instance/api/telegram-bot). Test with POST requests, e.g., { "message": "/start", "user_name": "John", "language_code": "en" } or { "message": "/image cute kitten" }. Success responses return JSON with text (greeting/chat) or image_url (image generation). Error response (HTTP 400) occurs for missing message fields. Check n8n logs for errors like ‘Invalid OpenAI API key’ or ‘Webhook not accessible.’ Validate outputs: ensure greeting includes user_name, image_url is valid, and chat responses match input language with emojis. Debug using n8n logs for credential or network issues. Ensure stable internet for reliable webhook and API performance. Update the message or language_code in the POST body for different interactions.

$6.99

Workflow steps: 14

Integrated apps: webhook, set, if

Telegram Bot for Chat and Image Responses preview