Skip to Content
Appwright
Examples

Slack Notifications

Post order events from Shopify Flow to a Slack channel

A worker that receives order data from a Shopify Flow workflow and posts a message to Slack via an incoming webhook.

Examples are deliberately generic — they’re here to show the moving parts, not to be pasted in verbatim. Comments mark the spots you’ll need to adapt to your own workflow and data.

Setup

  • A Slack incoming webhook URL, stored as a secret named SLACK_WEBHOOK_URL and enabled on this worker.
  • A Flow workflow (for example, triggered by Order created) with a Run worker action pointing at this worker’s handle, and a Request body using template variables — for example { "order": "{{ order.name }}", "total": "{{ order.totalPriceSet.shopMoney.amount }}" }.

The worker

// Runs when a Flow workflow's "Run worker" action fires.
// The workflow's configured "Request body" arrives as this request's POST body,
// with Flow template variables ({{ ... }}) already rendered into plain text.

// The body is whatever your workflow sent — JSON is a good convention.
let payload;
try {
  payload = await request.json();
} catch {
  // A 400 tells Flow this is a permanent failure — it won't retry.
  return new Response("Expected a JSON body", { status: 400 });
}

// Shape the Slack message from whatever fields your workflow passed through.
// Adjust these to match the variables in your Flow "Request body".
const message = {
  text: `🛒 New order ${payload.order ?? ""} — total ${payload.total ?? "?"}`,
};

// The webhook URL lives in a secret enabled on this worker — never in code.
const slack = await fetch(this.ctx.props.secrets.SLACK_WEBHOOK_URL, {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify(message),
});

if (!slack.ok) {
  // A 5xx is a transient failure — Flow will retry the run for up to ~36h.
  // Bound dedupes retries, so a retry after a lost response won't double-post
  // once a success has been recorded.
  return new Response("Slack delivery failed", { status: 502 });
}

// Whatever you return becomes the action's output ({{ runWorker.body }})
// for later workflow steps. Keep it small — responses are truncated at 45 KB.
return new Response("ok");

Notes

  • Use a 5xx response for failures Flow should retry and 400 for ones it shouldn’t (bad payload, misconfiguration).
  • If a later workflow step doesn’t reference the output, the Flow run log shows “No data returned” even on success — see Flow.