environment-setup-guide
Guide developers through setting up development environments with proper tools, dependencies, and configurations
documenso-core-workflow-b
Implement Documenso template-based workflows and direct signing links. Use when creating reusable templates, generating documents from templates, or implementing direct signing experiences. Trigger with phrases like "documenso template", "signing link", "direct template", "reusable document", "te...
Full skill instructions
Create reusable templates, generate documents from templates, and implement direct signing experiences with Documenso.
documenso-core-workflow-aimport { Documenso } from "@documenso/sdk-typescript";
import { openAsBlob } from "node:fs";
const documenso = new Documenso({
apiKey: process.env.DOCUMENSO_API_KEY ?? "",
});
interface CreateTemplateInput {
title: string;
pdfPath: string;
recipientRoles: Array<{
name: string; // e.g., "Employee", "Manager"
role: "SIGNER" | "APPROVER" | "VIEWER" | "CC";
signingOrder?: number;
}>;
}
async function createTemplate(
input: CreateTemplateInput
): Promise<string> {
const pdfBlob = await openAsBlob(input.pdfPath);
// Create the template
const template = await documenso.templates.createV0({
title: input.title,
file: pdfBlob,
});
const templateId = template.templateId!;
console.log(`Created template: ${templateId}`);
// Add recipient placeholders
for (const role of input.recipientRoles) {
await documenso.templatesRecipients.createV0({
templateId,
name: role.name,
role: role.role,
signingOrder: role.signingOrder,
});
console.log(`Added role: ${role.name}`);
}
return templateId;
}
// Example: Create NDA template
const templateId = await createTemplate({
title: "Non-Disclosure Agreement",
pdfPath: "./templates/nda.pdf",
recipientRoles: [
{ name: "Disclosing Party", role: "SIGNER", signingOrder: 1 },
{ name: "Receiving Party", role: "SIGNER", signingOrder: 2 },
],
});
interface TemplateFieldInput {
recipientIndex: number; // Index of recipient in the roles array
type: "SIGNATURE" | "INITIALS" | "NAME" | "EMAIL" | "DATE" | "TEXT";
page: number;
x: number;
y: number;
width?: number;
height?: number;
}
async function addTemplateFields(
templateId: string,
fields: TemplateFieldInput[]
): Promise<void> {
// Get template recipients to map indices to IDs
const template = await documenso.templates.getV0({ templateId });
const recipientIds = template.recipients?.map(r => r.id!) ?? [];
for (const field of fields) {
const recipientId = recipientIds[field.recipientIndex];
if (!recipientId) {
console.error(`No recipient at index ${field.recipientIndex}`);
continue;
}
await documenso.templatesFields.createV0({
templateId,
recipientId,
type: field.type,
page: field.page,
positionX: field.x,
positionY: field.y,
width: field.width ?? 200,
height: field.height ?? 60,
});
console.log(`Added ${field.type} field for recipient ${field.recipientIndex}`);
}
}
// Example: Add fields to NDA template
await addTemplateFields(templateId, [
// Disclosing Party fields (index 0)
{ recipientIndex: 0, type: "SIGNATURE", page: 2, x: 100, y: 400 },
{ recipientIndex: 0, type: "NAME", page: 2, x: 100, y: 350 },
{ recipientIndex: 0, type: "DATE", page: 2, x: 350, y: 400 },
// Receiving Party fields (index 1)
{ recipientIndex: 1, type: "SIGNATURE", page: 2, x: 100, y: 200 },
{ recipientIndex: 1, type: "NAME", page: 2, x: 100, y: 150 },
{ recipientIndex: 1, type: "DATE", page: 2, x: 350, y: 200 },
]);
interface UseTemplateInput {
templateId: string;
title?: string;
recipients: Array<{
email: string;
name: string;
}>;
sendImmediately?: boolean;
}
async function createFromTemplate(
input: UseTemplateInput
): Promise<{ documentId: string }> {
// Use the template to create a new document
const result = await documenso.envelopes.useV0({
templateId: input.templateId,
title: input.title,
recipients: input.recipients.map((r, index) => ({
email: r.email,
name: r.name,
signerIndex: index,
})),
});
const documentId = result.envelopeId!;
console.log(`Created document from template: ${documentId}`);
// Send if requested
if (input.sendImmediately) {
await documenso.envelopes.distributeV0({
envelopeId: documentId,
});
console.log("Document sent to recipients");
}
return { documentId };
}
// Example: Create NDA from template
const document = await createFromTemplate({
templateId,
title: "NDA - Acme Corp Partnership",
recipients: [
{ email: "[email protected]", name: "Your Company Legal" },
{ email: "[email protected]", name: "Acme Corp Representative" },
],
sendImmediately: true,
});
Direct templates allow signers to access and sign documents without pre-registration.
async function createDirectTemplateLink(
templateId: string
): Promise<{ directLink: string }> {
// Get template direct link settings
const template = await documenso.templates.getV0({ templateId });
// The direct link is available when template is published
const directLink = template.directLink;
if (!directLink) {
console.log("Template direct link not enabled. Enable in dashboard.");
throw new Error("Direct link not available");
}
return { directLink };
}
// Example usage with direct link
// Users can access: https://app.documenso.com/d/{directLinkToken}
// Get signing token for embedding
async function getSigningToken(
documentId: string,
recipientEmail: string
): Promise<{ signingToken: string; signingUrl: string }> {
// Get document with recipients
const doc = await documenso.documents.getV0({ documentId });
const recipient = doc.recipients?.find(r => r.email === recipientEmail);
if (!recipient) {
throw new Error(`Recipient ${recipientEmail} not found`);
}
// The signing token can be used for embedding
return {
signingToken: recipient.signingToken!,
signingUrl: recipient.signingUrl!,
};
}
// For React embedding, use @documenso/embed-react
// npm install @documenso/embed-react
// React component example:
/*
import { EmbedDirectTemplate } from '@documenso/embed-react';
function SigningComponent({ signingToken }) {
return (
<EmbedDirectTemplate
token={signingToken}
host="https://app.documenso.com"
onDocumentReady={() => console.log('Ready')}
onDocumentCompleted={() => console.log('Completed')}
onDocumentError={(error) => console.error(error)}
/>
);
}
*/
interface PrefillInput {
templateId: string;
recipients: Array<{
email: string;
name: string;
prefillFields?: Array<{
fieldId: string;
value: string;
}>;
}>;
}
async function createWithPrefill(
input: PrefillInput
): Promise<{ documentId: string }> {
const result = await documenso.envelopes.useV0({
templateId: input.templateId,
recipients: input.recipients.map((r, index) => ({
email: r.email,
name: r.name,
signerIndex: index,
prefillFields: r.prefillFields,
})),
});
return { documentId: result.envelopeId! };
}
// Example: Pre-fill contract details
await createWithPrefill({
templateId,
recipients: [
{
email: "[email protected]",
name: "Client Name",
prefillFields: [
{ fieldId: "company_name_field", value: "Acme Corporation" },
{ fieldId: "contract_amount_field", value: "$50,000" },
],
},
],
});
async function duplicateTemplate(
templateId: string,
newTitle: string
): Promise<string> {
const duplicate = await documenso.templates.duplicateV0({
templateId,
title: newTitle,
});
console.log(`Duplicated template: ${duplicate.templateId}`);
return duplicate.templateId!;
}
// Example: Create region-specific variants
const usTemplateId = await duplicateTemplate(templateId, "NDA - US Version");
const euTemplateId = await duplicateTemplate(templateId, "NDA - EU Version");
// 1. Create template once
const salesContractTemplate = await createTemplate({
title: "Sales Agreement",
pdfPath: "./templates/sales-agreement.pdf",
recipientRoles: [
{ name: "Sales Rep", role: "SIGNER", signingOrder: 1 },
{ name: "Customer", role: "SIGNER", signingOrder: 2 },
{ name: "Legal Review", role: "APPROVER", signingOrder: 3 },
],
});
// 2. Use for each deal
async function createSalesContract(deal: DealInfo) {
return createFromTemplate({
templateId: salesContractTemplate,
title: `Sales Agreement - ${deal.customerName}`,
recipients: [
{ email: deal.salesRepEmail, name: deal.salesRepName },
{ email: deal.customerEmail, name: deal.customerName },
{ email: "[email protected]", name: "Legal Team" },
],
sendImmediately: true,
});
}
// Customer visits your site, fills form, and signs
async function selfServiceSigning(customerInfo: CustomerInfo) {
// Create document from template with customer info pre-filled
const doc = await createWithPrefill({
templateId: selfServiceTemplateId,
recipients: [
{
email: customerInfo.email,
name: customerInfo.name,
prefillFields: [
{ fieldId: "customer_name", value: customerInfo.name },
{ fieldId: "customer_address", value: customerInfo.address },
],
},
],
});
// Get signing URL for immediate redirect
const { signingUrl } = await getSigningToken(
doc.documentId,
customerInfo.email
);
return { signingUrl };
}
| Error | Cause | Solution |
|---|---|---|
| Template not found | Invalid ID or deleted | Verify template exists |
| Recipient mismatch | Wrong number of recipients | Match template roles |
| Field not found | Invalid field ID for prefill | Get field IDs from template |
| Direct link disabled | Feature not enabled | Enable in template settings |
| Duplicate failed | Template in use | Try with different title |
For error handling patterns, see documenso-common-errors.
Guide developers through setting up development environments with proper tools, dependencies, and configurations
Implement Exa lint rules, policy enforcement, and automated guardrails. Use when setting up code quality rules for Exa integrations, implementing pre-commit hooks, or configuring CI policy checks for Exa best practices. Trigger with phrases like "exa policy", "exa lint", "exa guardrails", "exa be...
Configure CI/CD pipelines for Documenso integrations. Use when setting up automated testing, deployment pipelines, or continuous integration for Documenso projects. Trigger with phrases like "documenso CI", "documenso GitHub Actions", "documenso pipeline", "documenso automated testing".
Build check model availability and implement fallback chains. Use when building resilient systems or handling model outages. Trigger with phrases like 'openrouter availability', 'openrouter fallback', 'openrouter model down', 'openrouter health check'.
Configure Langfuse enterprise organization management and access control. Use when implementing team access controls, configuring organization settings, or setting up role-based permissions for Langfuse projects. Trigger with phrases like "langfuse RBAC", "langfuse teams", "langfuse organization"...
Execute compliance and security auditing for Cursor usage. Triggers on "cursor compliance", "cursor audit", "cursor security review", "cursor soc2", "cursor gdpr". Use when analyzing or auditing cursor compliance audit. Trigger with phrases like "cursor compliance audit", "cursor audit", "cursor".
Configure Apollo.io CI/CD integration. Use when setting up automated testing, continuous integration, or deployment pipelines for Apollo integrations. Trigger with phrases like "apollo ci", "apollo github actions", "apollo pipeline", "apollo ci/cd", "apollo automated tests".
Create robust Python automation with full logging and safety checks. Use when tasks need complex data processing, authenticated API work, conditional file operations, or error handling beyond simple shell commands.
Configure PostHog across development, staging, and production environments. Use when setting up multi-environment deployments, configuring per-environment secrets, or implementing environment-specific PostHog configurations. Trigger with phrases like "posthog environments", "posthog staging", "po...
Expert in designing and building autonomous AI agents. Masters tool use, memory systems, planning strategies, and multi-agent orchestration. Use when: build agent, AI agent, autonomous agent, tool use, function calling.
Validate insecure deserialization checker operations. Auto-activating skill for Security Fundamentals. Triggers on: insecure deserialization checker, insecure deserialization checker Part of the Security Fundamentals skill category. Use when working with insecure deserialization checker functiona...
Manage path traversal finder operations. Auto-activating skill for Security Fundamentals. Triggers on: path traversal finder, path traversal finder Part of the Security Fundamentals skill category. Use when working with path traversal finder functionality. Trigger with phrases like "path traversa...
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience