End-to-end guide to embed the Workflon product copilot in your email client — from setup to actions and context.
This guide shows how to integrate Workflon — your AI product copilot — into a mail application. You will:
If you want to see it in action first, try the demo at /mail-demo
.
/dashboard
and select or create an organization.Billing
if you need higher limits; otherwise Free plan is fine to start.pk_
).Add the script to your app’s HTML (or load it dynamically once you have the public key):
<!-- Replace YOUR_PUBLIC_KEY -->
<script src="/api/script/YOUR_PUBLIC_KEY" async></script>
In React, you can dynamically inject it after mount:
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);
}
}, []);
Expose the actions your copilot can perform. The copilot will call these handlers with structured parameters extracted from user prompts.
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({
sendEmail: async ({ to, subject, body }) => {
// Validate recipient, send via your mail API, persist, update UI
return `Sent email to ${to} with subject "${subject}".`;
},
archiveEmail: async ({ emailId }) => {
// Update storage and UI
return `Archived email ${emailId}.`;
},
markAsSpam: async ({ emailId }) => {
return `Marked email ${emailId} as spam.`;
},
deleteEmail: async ({ emailId }) => {
return `Deleted email ${emailId}.`;
},
});
Tips:
Ground the copilot with relevant, up-to-date context (emails, contacts, folders). This improves accuracy and reduces follow-up questions.
window.Workflon?.setUserContext({
emails: emails.map(({ id, subject, fromName, to, status }) => ({
id,
subject,
from: fromName,
to,
folder: status,
})),
contacts, // e.g. [{ id, name, email }]
});
Best practices:
window.Workflon?.show()
./dashboard
.Our /mail-demo
contains a working integration: script loading, actions, and context setup. Use it as a blueprint and adapt it to your data model and API.
window.Workflon.setActions
runs after the script loads.setUserContext
values and refresh after each action.