# Examples

Practical transformations you can adapt. Each reads the incoming `request` and returns a [message object](/introduction/justpush-studio/writing-code/the-message-object.md).

> These examples assume the [execution model](/introduction/justpush-studio/writing-code/execution-model.md): the webhook is available as `request`, and you send a notification by returning a message.

## Minimal message

```javascript
return {
    title: "Hello from Studio",
    message: "It works! 🎉",
    topic: "Default"
}
```

## Use values from the payload

```javascript
const { customer, amount } = request.body

return {
    title: "New payment",
    message: `${customer} paid €${amount}`,
    topic: "Payments",
    sound: "CASHREGISTER"
}
```

## Only notify on certain events

```javascript
const event = request.body.event

// Ignore everything except failures
if (event !== "alert.firing") {
    return
}

return {
    title: "🚨 Service down",
    message: request.body.summary,
    topic: "Alerts",
    priority: 4,          // highest — get my attention
    sound: "SIREN",
    requires_acknowledgement: true
}
```

## Green / red status alert

```javascript
const success = request.body.status === "success"

return {
    title: success ? "✅ Deploy succeeded" : "❌ Deploy failed",
    message: `${request.body.repo} → ${request.body.environment}`,
    topic: "Deploys",
    priority: success ? 1 : 4,
    sound: success ? "MAGIC" : "SPACEALARM"
}
```

## Add a button to the relevant page

```javascript
const issue = request.body.issue

return {
    title: `New issue: ${issue.title}`,
    message: issue.body?.slice(0, 200),
    topic: "GitHub",
    buttons: [
        { cta: "Open issue", url: issue.html_url }
    ]
}
```

## Include an image

```javascript
return {
    title: "New screenshot uploaded",
    message: request.body.filename,
    topic: "Uploads",
    images: [
        { url: request.body.url, caption: request.body.filename }
    ]
}
```

## Guard against missing data

```javascript
const body = request.body || {}

if (!body.message) {
    console.log("No message field in payload — skipping")
    return
}

return {
    title: body.title || "Notification",
    message: body.message,
    topic: body.topic || "Default"
}
```

> **Tip:** Use the [Test runner](/introduction/justpush-studio/testing-and-monitoring/testing-your-code.md) to paste a real payload and confirm your code produces the message you expect before going live.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.justpush.io/introduction/justpush-studio/writing-code/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
