> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dolphinclaw.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a Groq AI-powered Discord reporter on Dolphinclaw

> Walk through building a Dolphinclaw agent that uses Groq's LLM API to generate reports and post them to a Discord webhook automatically.

This guide builds a complete Dolphinclaw agent that calls Groq's OpenAI-compatible API to generate a short daily topic update using the `llama-3.1-8b-instant` model, then posts the result to a Discord channel via a webhook. By the end you will have a working agent you can start from the Dolphinclaw dashboard with a custom topic.

## What this agent does

When started, the agent accepts an optional `topic` input (defaulting to `"crypto market"`). It sends a prompt to Groq asking for a three-sentence update on that topic, then posts the response to a Discord channel using a webhook URL. The agent returns a success status and exits.

## Prerequisites

Before you begin, make sure you have:

* A Groq API key from [console.groq.com](https://console.groq.com)
* A Discord webhook URL for the channel you want to post to

## Agent code

Create a file named `dolphinclaw.agent.ts` (or `index.js` if you prefer plain JavaScript) at the root of your project.

```typescript theme={null}
import axios from "axios";
import OpenAI from "openai";

// Groq uses an OpenAI-compatible API — point the client at Groq's base URL
const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: "https://api.groq.com/openai/v1",
});

// Read the webhook URL from an environment variable
const WEBHOOK = process.env.DISCORD_WEBHOOK_URL;

export const dailyAiReporter = {
  name: "daily-ai-reporter",
  description: "AI agent that sends daily reports to Discord",

  // setup() runs once before the first run()
  async setup(): Promise<void> {
    console.log("Daily AI agent ready");
  },

  async run(input: { topic?: string } = {}): Promise<{ success: boolean; message: string }> {
    // Fall back to "crypto market" if no topic is provided
    const topic = input.topic || "crypto market";

    // Ask Groq to generate a short update using llama-3.1-8b-instant
    const chat = await client.chat.completions.create({
      model: "llama-3.1-8b-instant",
      messages: [
        { role: "user", content: `Write a short daily update about ${topic} in 3 sentences` }
      ]
    });

    const text = chat.choices[0].message?.content ?? "No update available.";

    // Post the generated text to Discord
    await axios.post(WEBHOOK, {
      content: `📊 Daily ${topic} update\n\n${text}`,
    });

    return {
      success: true,
      message: `Agent scheduled. Daily updates about "${topic}".`,
    };
  },
};
```

## Dependencies

Add the following packages to your `package.json`:

```json theme={null}
{
  "dependencies": {
    "axios": "^1.0.0",
    "openai": "^4.0.0"
  }
}
```

Install them before pushing your code:

```bash theme={null}
npm install axios openai
```

## Environment variables

This agent requires two environment variables to be set in the Dolphinclaw dashboard before you start it:

| Variable              | Description                                                                                                                                |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `OPENAI_API_KEY`      | Your Groq API key. Despite the name, this is your Groq key — the `openai` package uses it to authenticate with Groq's compatible endpoint. |
| `DISCORD_WEBHOOK_URL` | The full webhook URL for the Discord channel to post into.                                                                                 |

See [Setting environment variables](/building/environment-variables) for instructions on adding these in the dashboard.

<Note>
  You can pass a custom `topic` value when starting the agent from the dashboard. Open the **Run** panel, add a JSON input object such as `{"topic": "AI news"}`, and the agent will generate an update on that topic instead of the default `"crypto market"`. If no input is provided, the agent falls back to `"crypto market"` automatically.
</Note>
