Step-by-step guide to integrate the Workflon copilot in a notes application — actions, context, and UX tips.
In this guide, you’ll wire up Workflon to a notes application so users can create and update notes using natural language. You will:
Preview the experience at /notes-demo
.
Place the script in your page (or inject after mount):
<script src="/api/script/YOUR_PUBLIC_KEY" async></script>
useEffect(() => {
const pk = process.env.NEXT_PUBLIC_WORKFLON_PUBLIC_KEY;
if (!pk) return;
const id = "-script";
if (!document.getElementById(id)) {
const s = document.createElement("script");
s.id = id;
s.async = true;
s.src = `/api/script/${pk}`;
document.body.appendChild(s);
}
}, []);
Design clear, minimal actions and return confirmations. Example:
declare global {
interface Window {
Workflon?: {
setActions: (
actions: Record<string, (params: any) => Promise<any>>,
) => void;
setUserContext: (ctx: Record<string, any[]>) => void;
show: () => void;
};
}
}
window.Workflon?.setActions({
createNote: async ({ title, category, content }) => {
// Validate params, create via API, update UI
return `Created note: ${title}`;
},
updateNote: async ({ noteId, title, content, category, dueDate }) => {
// Partial update; persist to backend; update UI
return `Updated note ${noteId}`;
},
});
Param tips:
category
and dueDate
formats before persisting.Supply a compact view of your notes so the copilot can reason about them:
window.Workflon?.setUserContext({
notes: notes.map(({ id, title, category }) => ({ id, title, category })),
});
Update context after actions to reflect the latest state. Include IDs and key fields; avoid large bodies when not required.
window.Workflon?.show()
.createNote
, select and scroll to the new note.updateNote
, flash a success toast.The /notes-demo
shows a working example of:
createNote
, updateNote
)setUserContext
with note summariesUse it as a starting point and adapt to your storage/API.
setActions
runs after script load.setUserContext
after action side-effects.