Custom data lets you pass context about your logged-in users — email, plan, account ID, Stripe customer ID, and more — from your server to Megadesk. This context is available to the chatbot, your Actions, and your support team in the ticket view.
How it works
- You add an endpoint on your domain, e.g.
/api/megadesk-identity. - The endpoint encrypts the custom data payload with your shared key and returns
{ identity: "<encrypted-token>" }. - The embed passes that encrypted value to Megadesk; the platform decrypts it using the Encryption Key you find in the developer settings.
- The
userDetail.*is visible to the chatbot, meanwhile theintegrations.*is only accessible with actions on the server or prebuilt integrations.
Payload shape
{
"userDetail": {
"email": "user@example.com",
"name": "Ada Lovelace",
"plan": "pro",
"id": "user-123"
},
"integrations": {
"stripe": {
"customerId": "cus_123",
}
}
}
Recommended fields — These are used in the Megadesk UI:
userDetail.email— shown in ticket list and chat historyuserDetail.name— displayed alongside the emailintegrations.stripe.customerId— enables refunds and subscription actions
Any other fields you add to userDetail, like id and plan and will render in the ticket page when working with tickets. Include whatever context helps your team (plan, account age, etc.). All paths under userDetail.* and integrations.* are also available for use in Actions.
If the visitor is logged out, return { identity: null }.
How custom data appears in tickets
When a ticket is submitted, all custom data from userDetail is displayed as key-value pairs in a sidebar panel next to the chat. Your support team can see fields like plan, id, or any other values you include — right alongside the conversation — without having to look them up elsewhere.
For example, if you pass plan: "pro" and id: "user-123", the ticket sidebar will show:
Fields like email and name are surfaced more prominently in the ticket header, while all remaining userDetail fields appear as a data table in the sidebar.
How the chatbot uses it
Once custom data is available, the chatbot uses it to give more relevant, personalized responses without asking the user to repeat themselves. For example, if userDetail.email is set, the bot already knows who it's talking to and won't prompt for an email when submitting a ticket. If userDetail.plan is set, the bot can tailor answers based on what the user has access to. The data is also injected into any Actions you configure — so when the bot calls an external API on the user's behalf, it can pass fields like userDetail.id or integrations.stripe.customerId directly into the request without any manual input from the user.
Example (Next.js 16 route)
app/api/megadesk-identity/route.js
import { NextResponse } from "next/server";
import { cookies } from "next/headers";
import * as jose from "jose";
// import your auth/session helpers
// import { getUserFromSession } from "@/lib/auth";
export async function GET() {
const cookieStore = await cookies();
const sessionToken = cookieStore.get("session")?.value;
// Replace with your auth lookup
const user = { email: "user@example.com", name: "Ada Lovelace", id: "user-123", plan: "pro" }
const payload = {
userDetail: {
email: user.email,
name: user.name,
plan: user.plan,
id: user.id
},
integrations: {
stripe: {
customerId: "cus_123",
}
}
};
const encryptKey = MEGADESK_IDENTITY_SECRET // same key from Settings > Custom data
const identity = await new jose.EncryptJWT(payload)
.setProtectedHeader({ alg: "dir", enc: "A128GCM" })
.setIssuedAt()
.setExpirationTime("1h")
.encrypt(Buffer.from(encryptKey, "hex"));
return NextResponse.json({ identity });
}
Notes:
- Use your own session/auth lookup; only return data for authenticated users.
- Keep the route private to your site; it should rely on your existing auth cookies and must not leak sensitive data.
Connect it in Megadesk
- Go to Settings > Custom data.
- Set the Identity Endpoint to your route, e.g.
/api/megadesk-identity. - Copy the Encryption Key and add it to your route. Keep it secret and store it as an environment variable.
After this, custom data fields like userDetail.email can be used in Actions (headers/body placeholders), to avoid re-asking known info in chat, and will automatically appear as key-value pairs in the ticket sidebar whenever a ticket is submitted.
