Really informative plot!

Summary

User supplied summary for the plot

Norway's top 10 weekly Google Trends: What Norwegians are searching for the most in the last 24 Hours!

Description

The below description is supplied in free-text by the user

Integrating Discord with Novem Plots

This guide explains how to automatically post a Novem plot as an image to a Discord channel (or thread) every time your job runs.


Step 1: Get your Discord Webhook URL

  1. Open Discord and go to the channel you want to post in
  2. Click Edit ChannelIntegrationsWebhooksNew Webhook (If you dont have permission to create webhook URL's please ask a moderator for it)
  3. Copy the webhook URL — it looks like: https://discord.com/api/webhooks/{webhook_id}/{webhook_token}

If you want to post into a thread, you also need the thread ID:

  • Right-click the thread name in Discord
  • Click Copy Thread ID (requires Developer Mode to be enabled in Discord settings)

Step 2: Store credentials as ENV variables

In your Novem job, add the following environment variables:

Variable Description
discord_webhook_url The full webhook URL
discord_thread_id (Optional) Thread ID to post into a specific thread
discord_thread_name (Optional) Fallback thread name if no ID is provided

Never hardcode the webhook URL in your script — always use env vars.


Step 3: Fetch the plot PNG from Novem

After your job updates the plot data, wait a few seconds for it to re-render, then fetch the PNG via the Novem API:

import time, requests

def fetch_plot_image(api_base: str, token: str, plot_name: str) -> bytes:
    time.sleep(8)  # wait for render
    url = f"{api_base}/vis/plots/{plot_name}/files/plot.png"
    resp = requests.get(url, headers={"Authorization": f"Bearer {token}"}, timeout=60)
    resp.raise_for_status()
    return resp.content

Note: The correct path is /files/plot.png — not /f/plot.png. The novem_token and api_base are auto-injected by the Novem job runner.


Step 4: Post to Discord with text, image and plot link

Send the image as a multipart/form-data request. The content field is the text message that appears above the image in Discord. You can include anything here — a description, a link to the Novem plot, or both.

To link to your Novem plot, use the format: https://novem.io/u/{your_username}/p/{plot_name}

import json, requests

def post_to_discord(webhook_url, image_bytes, geo, plot_name, thread_id=""):
    url = f"{webhook_url}?thread_id={thread_id}" if thread_id else webhook_url

    # Text that appears above the image in Discord
    # Add the Novem plot URL so readers can open the interactive version
    content = (
        f"Todays most trending searches in Norway\n"
        f"https://novem.io/u/yourusername/p/{plot_name}"
    )

    resp = requests.post(
        url,
        files={"file": ("plot.png", image_bytes, "image/png")},
        data={"payload_json": json.dumps({"content": content})},
        timeout=30,
    )
    resp.raise_for_status()

Important: You must use multipart/form-data with both a file field and a payload_json field. Sending only JSON will not attach the image. The content key inside payload_json is the text message.


Full job flow

1. Fetch data from source (API, database, etc.)
2. Update the Novem plot via POST /vis/plots/{name}/data
3. Wait ~8 seconds for the plot to re-render
4. Fetch the PNG from GET /vis/plots/{name}/files/plot.png
5. POST the image + message to the Discord webhook URL