# Daily buddy: a conversation widget

A friendly widget that answers taps: a tip, a joke or a quote, written by a model the moment the user taps.

**Sizes:** small (the message), medium and large (message and buttons)
**Interaction:** buttons, answered by a listener on the user's computer
**Freshness:** each tap; nothing scheduled

## Widget

```json
{
  "slug": "buddy",
  "title": "Buddy",
  "symbol": "face.smiling",
  "accent": "#5E5CE6",
  "blocks": [
    { "type": "text", "text": "Good morning! What would help most today? Tap one." },
    { "type": "buttons", "items": [
      { "label": "Tip", "id": "tip", "symbol": "lightbulb.fill" },
      { "label": "Joke", "id": "joke", "symbol": "theatermasks.fill" },
      { "label": "Quote", "id": "quote", "symbol": "quote.bubble.fill" }
    ] },
    { "type": "text", "text": "Buddy" },
    { "type": "list", "title": "Earlier", "items": [
      "Tip: water before coffee",
      "Quote: Well begun is half done",
      "Joke: the one about the owl"
    ] }
  ],
  "sizes": { "small": [0], "medium": [0, 1], "large": [0, 3, 1] },
  "lock": { "circular": 2, "inline": "Buddy: tap for a tip" }
}
```

The message is over 45 characters, so it spans medium's width. The buttons are pinned to the bottom as equal tiles; with three, each short label fits (four tiles leave room for about four letters each). Small shows the message only; large adds what Buddy said earlier. Block 2 is just for the round Lock Screen widget.

## Handler (Node.js and the Claude API)

```javascript
// buddy-handler.mjs
import { readFileSync, writeFileSync, existsSync } from "node:fs";
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();
const event = JSON.parse(readFileSync(0, "utf8"));

const prompts = {
  tip: "Give one practical life tip in one sentence, under 100 characters.",
  joke: "Tell one clean, clever joke, under 100 characters.",
  quote: "Share a real, attributed quote, under 100 characters: 'Quote' (Author)",
};

const buttons = { type: "buttons", items: [
  { label: "Tip", id: "tip", symbol: "lightbulb.fill" },
  { label: "Joke", id: "joke", symbol: "theatermasks.fill" },
  { label: "Quote", id: "quote", symbol: "quote.bubble.fill" },
] };
const HISTORY = "/tmp/droplet-buddy-history.json";
const history = existsSync(HISTORY) ? JSON.parse(readFileSync(HISTORY, "utf8")) : [];
const earlier = () => ({ type: "list", title: "Earlier", items: history.length ? history.slice(0, 3) : ["Nothing yet"] });
// Same four blocks every time, so sizes and lock stay valid.
const show = (text) => console.log(JSON.stringify({ blocks: [{ type: "text", text }, buttons, { type: "text", text: "Buddy" }, earlier()] }));

show("Thinking about it. Your answer lands here in a moment.");   // on the phone in about a second

const message = await client.messages.create({
  model: "claude-haiku-4-5",
  max_tokens: 100,
  messages: [{ role: "user", content: prompts[event.target] ?? "Say something kind, under 100 characters." }],
});
const answer = message.content[0].text.trim().slice(0, 120);
show(answer);                                        // the answer replaces "Thinking about it"
writeFileSync(HISTORY, JSON.stringify([`${event.target}: ${answer}`.slice(0, 60), ...history].slice(0, 3)));
```

```bash
DROPLET_TOKEN=dp_... ANTHROPIC_API_KEY=sk-ant-... node listen.mjs --widget buddy --on-tap "node buddy-handler.mjs"
```

- Two lines, two updates: "Thinking about it" lands at once, the answer a moment later.
- Every line has the same four blocks, so the buttons stay and `sizes` and `lock` stay valid. When you send `blocks`, the whole list is replaced, so send all four.
- Text is cut at 120 characters, what medium shows in 3 lines.

## Don't

```bash
node listen.mjs --widget buddy --on-tap "claude -p 'respond to this tap'"
```

Starting a whole agent per tap takes minutes; the user sees Sent and gives up. Call a model API directly as above.

No listener running? Use `url` buttons or a checklist instead; see [interactive.md](../references/interactive.md#way-4-nothing-running-hosted-and-chat-only-agents).
