Telegram Weather Bot with R Script Data Visualization - n8n Workflow

Use this advanced n8n workflow to create a Telegram bot that fetches live weather data, processes it into CSV, executes an R script for image generation (ggplot2), and returns the visualization to the user. Leverage the Execute Command n8n node.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Developers looking for advanced n8n templates integrating external command-line tools (like R or Python).
Data scientists who want to expose complex data visualizations via messaging apps.
Users needing a robust example of custom code scripting within an n8n workflow.
Anyone building a conversational chat bot requiring dynamic image generation.

Overview

This sophisticated n8n workflow demonstrates how to extend the core capabilities of n8n by integrating external scripting languages, specifically R, for advanced data processing and visualization. The primary goal is to provide a user-friendly weather report visualized as a ggplot2 chart delivered directly through Telegram. The workflow handles incoming commands via a Telegram n8n trigger, uses the OpenWeatherMap API to gather current weather metrics for several European capitals, formats the data into a CSV file, and then executes a local R script via the Execute Command n8n node to turn that CSV into a dumbbell plot PNG image. This flexible n8n workflow provides robust error handling for both API connection failures and R script execution failures, ensuring a highly functional automation solution.

How it Works

The n8n workflow starts with the Telegram Trigger n8n node, which listens for incoming messages directed at the configured bot.


  1. Command Handling: A Switch n8n node checks the user's message text, acting as the core logic flow control.

If the command is /start, the bot sends a welcoming message (msggreet).
If the command is /getweather, the bot immediately sends a "Please wait" message (msg
pleasewait) and proceeds with the complex data processing pipeline.
* Any other command results in a "command not recognized" message (msgwrongcommand).

  1. Data Acquisition: The workflow uses a Set n8n node (Filename) to construct unique, timestamped filenames and necessary filepaths (/home/node/.n8n/weather-bot/). A Function n8n node (City List) provides a hardcoded list of European cities.

  2. API Fetching and Error Check: The Get weather data HTTP Request n8n node fetches real-time temperature data from the OpenWeatherMap API. An If n8n node (Any errors API?) immediately checks for connection failures or bad API responses, redirecting to msgerrorAPI if necessary.

  3. CSV Generation: If successful, the data is converted and cleaned using the Convert API response Function n8n node. The Spreadsheet File n8n node formats this data into a binary CSV object, which is then saved to the local file system using the Write csv n8n node.

  4. Custom Code Scripting: The Run R script Execute Command n8n node is executed. It calls the external R script, passing the generated CSV file path as the input argument and the desired PNG output path.

  5. Delivery: An If n8n node (R successful?) checks the exit code of the R script. If the code is 0, the Read Binary File n8n node retrieves the newly created PNG image, and the msggetweather Telegram n8n node sends the visualization back to the user. If the R script fails, an error notification (msgerrorR) is sent instead.

Installation Guide


  1. Import the n8n Workflow: Import the provided n8n workflow JSON into your self-hosted or cloud n8n instance.

  2. Credential Setup: Configure and link your Telegram API credentials to all Telegram n8n nodes.

  3. API Key Configuration: Update the URL parameter in the Get weather data HTTP Request n8n node with your valid OpenWeatherMap API key.

  4. External Environment Setup (Critical): This step is essential because the n8n workflow relies on the Execute Command n8n node.

Ensure your n8n environment (e.g., Docker container) has the R interpreter and necessary libraries (like ggplot2) installed and accessible.
Create the target folder path (/home/node/.n8n/weather-bot/) within your n8n volume.
* Obtain the required R script (dumbbell_plot.R, referenced in the JSON) and place it within the target folder.

  1. Activate: Set the Telegram Trigger n8n trigger to active to start processing incoming messages.

Node Details

Telegram Trigger: Function: Initiates the n8n workflow upon receiving any message in the linked Telegram bot.
Switch: Function: Provides essential core logic flow control, routing the flow based on the command received (e.g., /getweather).
Set (Filename): Function: Dynamically generates file names and folder paths, which are crucial for the Execute Command n8n node and file operations.
Function (City List / Convert API response): Function: Defines the city list for the API calls and transforms the raw JSON response into a normalized data structure suitable for CSV creation.
HTTP Request (Get weather data): Function: Calls the external OpenWeatherMap API to retrieve real-time weather data.
Spreadsheet File: Function: Converts the structured data into a CSV binary file format, preparing it for the external R script.
Write Binary File (Write csv): Function: Saves the CSV binary data to the local disk, making it accessible for the external R processing command.
Execute Command (Run R script): Function: The key custom code scripting element. Executes an external command-line process (Rscript) to generate a PNG image visualization based on the input CSV file.
If (R successful?): Function: Checks the exit code of the command execution to ensure the R script ran without errors before attempting to read the output image. This provides robust error handling to the n8n workflow.
Telegram (msg_getweather): Function: Uses binary data to send the final, generated PNG image back to the user.

Related n8n Workflows

Free

Nodes: 12 Nodes
Updated: December 26 2025
View all
Created by

Featured*