### Run live-cli example with environment variables Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Runs the live-cli example using tsx with required environment variables for API key, account ID, and base URL. The base URL points to the sandbox environment. Requires the repository's development dependencies installed. ```Bash ASSINAFY_API_KEY=... \ ASSINAFY_ACCOUNT_ID=... \ ASSINAFY_BASE_URL=https://sandbox.assinafy.com.br/v1 \ npx tsx examples/live-cli.ts ``` -------------------------------- ### Install @assinafy/chat-sdk from npm Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Install the package from the public npm registry. Requires Node.js 24 LTS for server applications. ```bash npm install @assinafy/chat-sdk ``` -------------------------------- ### Start cloudflared HTTPS tunnel for OAuth example Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Starts a temporary HTTPS tunnel using cloudflared to expose the local OAuth example server. The generated HTTPS URL must be registered in the application's redirect URIs. ```Bash cloudflared tunnel --url http://localhost:8787 ``` -------------------------------- ### POST /users/self/mfa/totp Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Starts the TOTP MFA setup process. Requires API authentication. ```APIDOC ## POST /users/self/mfa/totp ### Description Starts the TOTP MFA setup process. Requires API authentication. ### Method POST ### Endpoint /users/self/mfa/totp ### Parameters #### Request Body - (not specified) ### Request Example (not provided) ### Response #### Success Response (200) - (not specified) #### Response Example (not provided) ``` -------------------------------- ### client.auth.startTotp() Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Starts authenticator enrollment. Returns the secret and the otpauth:// URI once. ```APIDOC ## client.auth.startTotp() ### Description Starts authenticator enrollment. Returns the secret and the otpauth:// URI once. ### Method Async method ### Endpoint N/A ### Parameters None ### Request Example ```ts const totp = await client.auth.startTotp(); ``` ### Response #### Success Response Returns an object containing the secret and the `otpauth://` URI. #### Response Example ```ts const totp = await client.auth.startTotp(); ``` ``` -------------------------------- ### Run oauth-connect example with environment variables Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Runs the oauth-connect example with client ID, redirect URI, and production base URL. The redirect URI must match the registered tunnel URL exactly. Requires an HTTPS tunnel because http://localhost cannot be registered as a redirect URI. ```Bash ASSINAFY_CLIENT_ID=your-client-id \ ASSINAFY_REDIRECT_URI=https://your-tunnel.example.com/oauth/callback \ ASSINAFY_BASE_URL=https://api.assinafy.com.br/v1 \ npx tsx examples/oauth-connect.ts ``` -------------------------------- ### signature.startIdentityVerification(accessCode, input) Source: https://github.com/assinafy/chat-sdk/blob/main/docs/API_REFERENCE.md Starts a new identity verification session for a signer. Requires explicit consent from the signer and can only be started when `can_start` is true. ```APIDOC ## signature.startIdentityVerification(accessCode, input) ### Description Starts a new identity verification session for a signer. Requires explicit consent from the signer and can only be started when `can_start` is true. ### Method POST ### Endpoint signature.startIdentityVerification(accessCode, input) ### Parameters #### Path Parameters - **accessCode** (string) - Required - The access code for the signing session. #### Request Body - **consent** (boolean) - Required - Must be `true`; missing or false consent rejects with `ConfigurationError`. ### Request Example ```json { "consent": true } ``` ### Response #### Success Response (200) - **id** (string) - Session identifier. - **url** (string) - Capture URL. - **expires_at** (string, nullable) - Expiration timestamp. #### Response Example ```json { "id": "identity-session-1", "url": "https://example.test/capture/session#t=placeholder", "expires_at": "2026-10-17T21:18:47Z" } ``` ``` -------------------------------- ### startTotp Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/auth.md Starts TOTP enrollment and returns a secret and provisioning URI. ```APIDOC ## [POST] /users/self/mfa/totp ### Description Starts TOTP enrollment and returns a secret and provisioning URI. ### Method POST ### Endpoint /users/self/mfa/totp ### Parameters #### Request Body - **label** (string, optional) - Label for the authenticator app. ### Request Example ```json { "label": "My App" } ``` ### Response #### Success Response (200) - **secret** (string) - TOTP secret. - **provisioning_uri** (string) - otpauth:// URI. #### Response Example ```json { "secret": "JBSWY3DPEHPK3PXP", "provisioning_uri": "otpauth://totp/MyApp?secret=..." } ``` ``` -------------------------------- ### StartIdentityVerificationInput Interface Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/types-entities.md Input for starting identity verification. ```APIDOC ## StartIdentityVerificationInput Interface ### Description Input for starting identity verification. ### Fields - **consent** (true) - Required - Must be set to true. ### Example ```ts const input: StartIdentityVerificationInput = { consent: true }; ``` ``` -------------------------------- ### AssinafyClient.fromEnv() Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Creates a client by reading configuration from environment variables. Reads ASSINAFY_API_KEY, ASSINAFY_ACCESS_TOKEN, ASSINAFY_BASE_URL, and ASSINAFY_ACCOUNT_ID. ```APIDOC ## AssinafyClient.fromEnv() ### Description Creates a client by reading configuration from environment variables. Reads ASSINAFY_API_KEY, ASSINAFY_ACCESS_TOKEN, ASSINAFY_BASE_URL, and ASSINAFY_ACCOUNT_ID. ### Method Static method ### Endpoint N/A ### Parameters #### Environment Variables - **ASSINAFY_API_KEY** (string) - Optional - API key, sent as `X-Api-Key` - **ASSINAFY_ACCESS_TOKEN** (string) - Optional - Bearer token, used instead of an API key - **ASSINAFY_BASE_URL** (string) - Optional - Default `https://api.assinafy.com.br/v1`; set to `https://sandbox.assinafy.com.br/v1` for sandbox - **ASSINAFY_ACCOUNT_ID** (string) - Optional - Default account id, readable back as `client.accountId` ### Request Example ```ts const client = AssinafyClient.fromEnv(); ``` ### Response #### Success Response Returns an `AssinafyClient` instance. #### Response Example ```ts const client = AssinafyClient.fromEnv(); ``` ``` -------------------------------- ### GET /signers/identity-verification Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/signature.md Retrieves the signer's identity verification status and session details. Use this to check if a capture can be started. ```APIDOC ## GET /signers/identity-verification ### Description Retrieves the signer's identity verification status and session details. ### Method GET ### Endpoint /signers/identity-verification ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example No request body required. ### Response #### Success Response (200) - **can_start** (boolean) - Whether a capture can be started - **status** (string) - Verification status (e.g., 'InReview', 'Expired') - **url** (string) - Verification URL - **expires_at** (string) - Expiration timestamp - **completed_at** (string) - Completion timestamp #### Response Example { "can_start": true, "status": "InReview", "url": "https://verify.example.com/session/abc", "expires_at": "2025-01-01T00:00:00Z", "completed_at": null } ``` -------------------------------- ### POST /v1/users/self/mfa/totp Source: https://github.com/assinafy/chat-sdk/blob/main/docs/API_COVERAGE.md Starts the setup of a TOTP-based multi-factor authentication method for the current user. Requires Bearer token or API key authentication. ```APIDOC ## POST /v1/users/self/mfa/totp ### Description Starts the setup of a TOTP-based multi-factor authentication method for the current user. Requires Bearer token or API key authentication. ### Method POST ### Endpoint /v1/users/self/mfa/totp ### Authentication Bearer / API key ### SDK Method client.auth.startTotp ``` -------------------------------- ### constructor(options) Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/client.md Creates a new AssinafyClient instance with the provided options. The options can include API key, access token, base URL, and account ID. ```APIDOC ## Constructor ### Description Creates a new AssinafyClient instance with the provided options. ### Signature ```ts constructor(options: AssinafyClientOptions = {}) ``` ### Parameters - **options** (AssinafyClientOptions) - Optional - Configuration options for the client. ``` -------------------------------- ### Initialize AssinafyClient and list documents Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Creates a stateless client using ASSINAFY_ACCOUNT_ID and ASSINAFY_API_KEY environment variables. Lists documents with status 'pending_signature' and perPage 20, logging the returned data and pagination. Catches ApiError to log status, method, path, and body before rethrowing. ```TypeScript import { AssinafyClient, ApiError } from "@assinafy/chat-sdk/client"; const accountId = process.env.ASSINAFY_ACCOUNT_ID; if (!accountId) throw new Error("ASSINAFY_ACCOUNT_ID is required"); const apiKey = process.env.ASSINAFY_API_KEY; if (!apiKey) throw new Error("ASSINAFY_API_KEY is required"); const client = new AssinafyClient({ apiKey, accountId, baseUrl: "https://sandbox.assinafy.com.br/v1", // omit for production }); try { const { data: documents, pagination } = await client.documents.list(accountId, { status: "pending_signature", perPage: 20, }); console.log(documents, pagination); } catch (error) { if (error instanceof ApiError) { console.error(error.status, error.method, error.path, error.body); } throw error; } ``` -------------------------------- ### get Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/fields.md Retrieves a single field definition by ID. Sends a GET request to /accounts/{accountId}/fields/{fieldId}. ```APIDOC ## GET /accounts/{accountId}/fields/{fieldId} ### Description Retrieves a single field definition by ID. ### Method GET ### Endpoint /accounts/{accountId}/fields/{fieldId} ### Parameters #### Path Parameters - **accountId** (string) - Required - The account ID. - **fieldId** (string) - Required - The field ID. ### Response #### Success Response (200) - **FieldDefinition** - The field definition. #### Response Example { "id": "field_id", "name": "CPF", "type": "text", "regex": "^\\d{11}$", "is_required": true } ``` -------------------------------- ### Set up Chat with adapters and state, handle /status command Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Initializes the Assinafy client, memory adapters, and Chat instance. Registers a slash command handler for 'status' that fetches a document and posts a card with its preview. Demonstrates sending a test message and logging the last sent output. ```TypeScript import { AssinafyClient, Card, Chat, DocumentPreview, MemoryStateAdapter, createMemoryAdapter, } from "@assinafy/chat-sdk"; const client = AssinafyClient.fromEnv(); if (!process.env.ASSINAFY_API_KEY && !process.env.ASSINAFY_ACCESS_TOKEN) { throw new Error("ASSINAFY_API_KEY or ASSINAFY_ACCESS_TOKEN is required"); } const memory = createMemoryAdapter(); const chat = new Chat({ userName: "Assinafy Bot", adapters: { memory }, state: new MemoryStateAdapter(), client, }); chat.onCommand("status", async (thread, message) => { const documentId = message.text.replace(/^[/!]status\s*/i, "").trim(); const document = await client.documents.get(documentId); await thread.post( Card({ title: "Document status", children: [ DocumentPreview({ documentId: document.id, name: document.name, status: document.status, signingUrl: document.signing_url ?? undefined, }), ], }), ); }); await memory.receive({ text: "/status doc_01J00000000000000000000000", isMention: true }); console.log(memory.lastSent); ``` -------------------------------- ### get method signature Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/fields.md Retrieves a single field definition. Sends GET /accounts/{accountId}/fields/{fieldId}. ```ts get(accountId: string, fieldId: string): Promise ``` -------------------------------- ### get method signature Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/signers.md Fetches a single signer by ID via GET /accounts/{accountId}/signers/{signerId}. ```ts get(accountId: string, signerId: string): Promise ``` -------------------------------- ### startTyping(): Promise Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/memory-adapter.md Indicates that the bot is typing. This is a no-op in the memory adapter. ```APIDOC ## startTyping(): Promise ### Description Indicates that the bot is typing. This is a no-op in the memory adapter. ### Method startTyping ### Parameters None ### Returns Promise ``` -------------------------------- ### Run integration tests Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Executes the live integration suite, including sandbox and contract tests. Requires sandbox credentials and refuses non-sandbox base URLs. Creates and deletes disposable resources. ```bash npm run test:integration ``` -------------------------------- ### Basic API-key client initialization Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/client.md Creates an AssinafyClient using an API key and account ID from environment variables, then lists documents for the account. ```TypeScript import { AssinafyClient } from "@assinafy/chat-sdk/client"; const client = new AssinafyClient({ apiKey: process.env.ASSINAFY_API_KEY!, accountId: process.env.ASSINAFY_ACCOUNT_ID!, }); const { data: docs } = await client.documents.list(client.accountId); ``` -------------------------------- ### GET /v1/documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification Source: https://github.com/assinafy/chat-sdk/blob/main/docs/API_COVERAGE.md Gets signer identity review details. Requires Bearer or API key authentication. ```APIDOC ## GET /v1/documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification ### Description Gets signer identity review details. ### Method GET ### Endpoint /v1/documents/{documentId}/assignments/{assignmentId}/signers/{signerId}/identity-verification ### Path Parameters - **documentId** (string) - Required - The document identifier. - **assignmentId** (string) - Required - The assignment identifier. - **signerId** (string) - Required - The signer identifier. ### Authentication Bearer / API key ``` -------------------------------- ### get(path: string, init: RequestInit = {}): Promise Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/http-client.md Performs an HTTP GET request and returns the unwrapped data. Convenience verb that returns the `data` field from the response envelope. ```APIDOC ## get(path: string, init: RequestInit = {}): Promise ### Description Performs an HTTP GET request and returns the unwrapped data. Convenience verb that returns the `data` field from the response envelope. ### Method get ### Parameters - **path** (string) - Required - The request path. - **init** (RequestInit) - Optional - Fetch request options. ### Returns - **Promise** - The unwrapped response data. ``` -------------------------------- ### client.auth.login({ email, password }) Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Authenticates a user with email and password. Returns a session with access_token, or an MFA challenge with mfa_token if two-factor authentication is enabled. ```APIDOC ## client.auth.login({ email, password }) ### Description Authenticates a user with email and password. Returns a session with access_token, or an MFA challenge with mfa_token if two-factor authentication is enabled. ### Method Async method ### Endpoint N/A ### Parameters #### Request Body - **email** (string) - Required - User email - **password** (string) - Required - User password ### Request Example ```ts const result = await client.auth.login({ email, password }); ``` ### Response #### Success Response Returns `LoginResponse | MfaChallenge`. #### Response Example ```ts const result = await client.auth.login({ email, password }); const session = "mfa_token" in result ? await client.auth.verifyMfa({ mfa_token: result.mfa_token, code }) : result; ``` ``` -------------------------------- ### fromEnv(env) Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/client.md Static factory method that builds an AssinafyClient from environment variables. Maps ASSINAFY_API_KEY, ASSINAFY_ACCESS_TOKEN, ASSINAFY_BASE_URL, and ASSINAFY_ACCOUNT_ID to client options. ```APIDOC ## Static factory — `fromEnv` ### Description Builds a client from environment variables. ### Signature ```ts static fromEnv( env = (globalThis as { process?: { env?: Readonly> } }).process?.env ?? {}, ): AssinafyClient ``` ### Parameters - **env** (object) - Optional - Environment variables object. Defaults to `process.env`. ### Environment Variables | Variable | Mapped option | | --- | --- | | `ASSINAFY_API_KEY` | `apiKey` | | `ASSINAFY_ACCESS_TOKEN` | `accessToken` | | `ASSINAFY_BASE_URL` | `baseUrl` (defaults to production when unset) | | `ASSINAFY_ACCOUNT_ID` | `accountId` | ### Returns - **AssinafyClient** - A new client instance. Returns an unauthenticated client if neither key nor token is set. ``` -------------------------------- ### GET /assignments Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Lists assignments with pagination support. ```APIDOC ## GET /assignments ### Description Lists assignments with pagination support. ### Method GET ### Endpoint /assignments ### Parameters #### Query Parameters - **page** (integer) - Optional - Page number. - **per-page** (integer) - Optional - Number of items per page. ### Response #### Success Response (200) - **assignments** (array) - List of assignments. #### Response Example { "assignments": [] } ``` -------------------------------- ### get Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/thread.md Retrieves a value from the thread's key-value store. ```APIDOC ## get ### Description Retrieves a value from the thread's key-value store. ### Method get(key: string): Promise ### Parameters - **key** (string) - Required - The key to look up. ### Returns - **Promise** - The stored value, or undefined if not found. ``` -------------------------------- ### new AssinafyClient({ apiKey }) Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Creates an authenticated client using a long-lived API key. The API key is sent as the X-Api-Key header and acts on your own workspace. ```APIDOC ## new AssinafyClient({ apiKey }) ### Description Creates an authenticated client using a long-lived API key. The API key is sent as the X-Api-Key header and acts on your own workspace. ### Method Constructor ### Endpoint N/A ### Parameters #### Constructor Options - **apiKey** (string) - Required - API key sent as `X-Api-Key` ### Request Example ```ts new AssinafyClient({ apiKey: "api-key" }); ``` ### Response #### Success Response Returns an `AssinafyClient` instance. #### Response Example ```ts const client = new AssinafyClient({ apiKey: "api-key" }); ``` ``` -------------------------------- ### GET /webhooks/event-types Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Lists all available webhook event types. ```APIDOC ## GET /webhooks/event-types ### Description Lists all available webhook event types. ### Method GET ### Endpoint `/webhooks/event-types` ### Response #### Success Response (200) - **eventTypes** (array) - List of event type strings. #### Response Example ```json { "eventTypes": [] } ``` ``` -------------------------------- ### auth.startTotp(label?) Source: https://github.com/assinafy/chat-sdk/blob/main/docs/API_REFERENCE.md Starts TOTP enrollment for the authenticated user. The HTTP operation is POST /users/self/mfa/totp and requires account authentication. ```APIDOC ## POST /users/self/mfa/totp ### Description Starts TOTP enrollment for the authenticated user. ### Method POST ### Endpoint /users/self/mfa/totp ### Parameters #### Request Body - **label** (string) - Optional - A label for the TOTP enrollment. ### Response #### Success Response (200) - **TotpEnrollment** - The TOTP enrollment details. ``` -------------------------------- ### Instantiate AssinafyClient with API key or access token Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Creates a client using either a long-lived API key (sent as X-Api-Key) or a bearer access token. Passing both throws ConfigurationError. Use an API key for your own workspace; use OAuth for user-connected workspaces. ```TypeScript import { AssinafyClient } from "@assinafy/chat-sdk/client"; new AssinafyClient({ apiKey: "api-key" }); new AssinafyClient({ accessToken: "bearer-token" }); ``` -------------------------------- ### GET /field-types Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves a list of available field types. ```APIDOC ## GET /field-types ### Description Retrieves a list of available field types. ### Method GET ### Endpoint /field-types ### Response #### Success Response (200) - **field_types** (array) - List of field type objects. #### Response Example { "field_types": [] } ``` -------------------------------- ### client.auth.listMfaMethods() Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Lists the MFA methods configured for the user. ```APIDOC ## client.auth.listMfaMethods() ### Description Lists the MFA methods configured for the user. ### Method Async method ### Endpoint N/A ### Parameters None ### Request Example ```ts const methods = await client.auth.listMfaMethods(); ``` ### Response #### Success Response Returns a list of MFA methods. #### Response Example ```ts const methods = await client.auth.listMfaMethods(); ``` ``` -------------------------------- ### GET /documents/{documentId} Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves a specific document by ID. ```APIDOC ## GET /documents/{documentId} ### Description Retrieves a specific document by ID. ### Method GET ### Endpoint /documents/{documentId} ### Parameters #### Path Parameters - **documentId** (string) - Required - The document identifier. ### Response #### Success Response (200) - **document** (object) - The document details. #### Response Example { "document": {} } ``` -------------------------------- ### GET /documents/statuses Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves the list of possible document statuses. ```APIDOC ## GET /documents/statuses ### Description Retrieves the list of possible document statuses. ### Method GET ### Endpoint /documents/statuses ### Response #### Success Response (200) - **statuses** (array) - List of statuses. #### Response Example { "statuses": [] } ``` -------------------------------- ### Sandbox client with default-account convenience Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/client.md Creates a client pointing to the sandbox base URL with a sandbox API key from environment variables. ```TypeScript const client = new AssinafyClient({ baseUrl: "https://sandbox.assinafy.com.br/v1", apiKey: process.env.ASSINAFY_SANDBOX_API_KEY!, }); ``` -------------------------------- ### Instantiate a template with signer roles Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Templates turn steps 2-5 into a single call. Define roles rather than signers; instantiation binds a concrete signer to each role. Use client.templates.estimateCost() to price an instantiation. ```typescript const { data: templates } = await client.templates.list(accountId, { perPage: 10 }); const template = await client.templates.get(accountId, templates[0]!.id); const roles = template.roles!.filter((role) => role.assignment_type !== "Editor"); const created = await client.templates.instantiate(accountId, template.id, { name: "nda-acme.pdf", signers: roles.map((role) => ({ role_id: role.id, id: signer.id })), }); ``` -------------------------------- ### GET /public/documents/{documentId} Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves a document publicly without authentication. ```APIDOC ## GET /public/documents/{documentId} ### Description Retrieves a document publicly without authentication. ### Method GET ### Endpoint /public/documents/{documentId} ### Parameters #### Path Parameters - **documentId** (string) - Required - The document identifier. ### Response #### Success Response (200) - **document** (object) - The public document details. #### Response Example { "document": {} } ``` -------------------------------- ### GET /documents/{documentId}/activities Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves the activity log for a document. ```APIDOC ## GET /documents/{documentId}/activities ### Description Retrieves the activity log for a document. ### Method GET ### Endpoint /documents/{documentId}/activities ### Parameters #### Path Parameters - **documentId** (string) - Required - The document identifier. ### Response #### Success Response (200) - **activities** (array) - List of activities. #### Response Example { "activities": [] } ``` -------------------------------- ### client.templates.instantiate Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Instantiates a template by binding concrete signers to roles. ```APIDOC ## client.templates.instantiate ### Description Instantiates a template by binding concrete signers to roles. ### Method POST ### Endpoint client.templates.instantiate(accountId, template.id, { name: "nda-acme.pdf", signers: [{ role_id: role.id, id: signer.id }] }) ### Parameters #### Path Parameters - **accountId** (string) - Required - The ID of the account. - **template.id** (string) - Required - The ID of the template. #### Request Body - **name** (string) - Required - The name of the instantiated document. - **signers** (array) - Required - List of signers, each with `role_id` and `id`. ### Request Example ```json { "name": "nda-acme.pdf", "signers": [ { "role_id": "role-id", "id": "signer-id" } ] } ``` ### Response #### Success Response (200) - **assignment** (object) - The created assignment object. #### Response Example ```json { "id": "assignment-id", "status": "pending" } ``` ``` -------------------------------- ### GET /accounts/{accountId}/documents/search Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Searches documents within an account. ```APIDOC ## GET /accounts/{accountId}/documents/search ### Description Searches documents within an account. ### Method GET ### Endpoint /accounts/{accountId}/documents/search ### Parameters #### Path Parameters - **accountId** (string) - Required - The account identifier. ### Query Parameters - **search** (string) - Optional - Search query. ### Response #### Success Response (200) - **documents** (array) - List of matching documents. #### Response Example { "documents": [] } ``` -------------------------------- ### get method signature Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/accounts.md Fetches a single workspace account by ID. ```typescript get(accountId: string): Promise // src/client/accounts.ts:53 ``` -------------------------------- ### client.auth.startTotp Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/auth.md Starts the enrollment of a new TOTP authenticator. Returns a provisioning URI to display as a QR code and an enrollment ID for confirmation. ```APIDOC ## client.auth.startTotp ### Description Starts the enrollment of a new TOTP authenticator. Returns a provisioning URI to display as a QR code and an enrollment ID for confirmation. ### Method startTotp ### Parameters - **label** (string) - Required - A label for the authenticator (e.g., "My laptop") ### Request Example ```ts const enrollment = await client.auth.startTotp("My laptop"); ``` ### Response - Returns an enrollment object containing: - `id` (string) - Enrollment ID for confirmation - `provisioning_uri` (string) - URI to display as a QR code ``` -------------------------------- ### HttpClient.get Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/http-client.md Performs a GET request and returns the response body. ```APIDOC ## HttpClient.get ### Description Performs a GET request and returns the response body. ### Method GET ### Endpoint `get(path)` ### Parameters #### Path Parameters - **path** (string) - Required - The endpoint path, e.g., `/signers/self?signer-access-code=…`. ### Request Example ```ts const signer = await anonymous.get("/signers/self?signer-access-code=…"); ``` ### Response #### Success Response Returns the response body of type `T`. #### Response Example ```ts const signer = await anonymous.get("/signers/self?signer-access-code=…"); ``` ``` -------------------------------- ### Complete virtual-signature flow with polling (TypeScript) Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Walks through the full document-signing lifecycle: create signer, upload PDF (max 25 MB, 2,000 pages), wait for metadata_ready, estimate cost, create assignment, poll until certificated, and download the certificated artifact. Requires ASSINAFY_ACCOUNT_ID and either ASSINAFY_API_KEY or ASSINAFY_ACCESS_TOKEN. Production should use a webhook instead of polling. ```TypeScript import { readFile } from "node:fs/promises"; import { AssinafyClient } from "@assinafy/chat-sdk/client"; const client = AssinafyClient.fromEnv(); const accountId = client.accountId; if (!accountId) throw new Error("ASSINAFY_ACCOUNT_ID is required"); if (!process.env.ASSINAFY_API_KEY && !process.env.ASSINAFY_ACCESS_TOKEN) { throw new Error("ASSINAFY_API_KEY or ASSINAFY_ACCESS_TOKEN is required"); } // 1. Signers are account-scoped records, reusable across documents. const signer = await client.signers.create(accountId, { full_name: "Example Signer", email: "signer@example.test", }); // 2. Upload. `body` accepts a Blob, ArrayBuffer, or Uint8Array — a Node Buffer // is a Uint8Array, so `readFile` output works directly. const document = await client.documents.upload(accountId, { filename: "contract.pdf", body: await readFile("contract.pdf"), contentType: "application/pdf", }); // 3. Metadata processing renders page images and assigns page ids. async function waitForStatus( documentId: string, accepted: ReadonlySet, timeoutMs = 120_000, ) { const deadline = Date.now() + timeoutMs; while (Date.now() < deadline) { const current = await client.documents.get(documentId); if (accepted.has(current.status)) return current; if (["failed", "expired", "rejected_by_signer", "rejected_by_user"].includes(current.status)) { throw new Error(`Document entered terminal status: ${current.status}`); } await new Promise((resolve) => setTimeout(resolve, 1_000)); } throw new Error("Timed out waiting for document status"); } await waitForStatus(document.id, new Set(["metadata_ready"])); // 4. Price the request before committing to it. const estimate = await client.assignments.estimateCost(document.id, { method: "virtual", signers: [{ verification_method: "Email", notification_methods: ["Email"] }], }); if (estimate.has_sufficient_resources === false) { throw new Error(estimate.message ?? estimate.blocking_reason ?? "Insufficient resources"); } // 5. Creating the assignment sends the notifications. const assignment = await client.assignments.create(document.id, { method: "virtual", signers: [ { id: signer.id, verification_method: "Email", notification_methods: ["Email"], step: 1, }, ], message: "Please sign by Friday.", }); console.log(`Assignment created: ${assignment.id}`); // 6 and 7. The signer completes the link Assinafy delivered; resume from a // webhook in production, or keep the bounded polling shown here. await waitForStatus(document.id, new Set(["certificated"])); const certificated = await client.documents.download(document.id, "certificated"); const bytes = new Uint8Array(await certificated.arrayBuffer()); console.log(`Downloaded ${bytes.byteLength} certificated bytes`); ``` -------------------------------- ### Environment-driven client with destructured resources Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/client.md Creates a client from environment variables using fromEnv(), destructures signers, documents, and assignments, then lists signers with pagination. ```TypeScript const client = AssinafyClient.fromEnv(); const { signers, documents, assignments } = client; const { data: signerPage } = await signers.list(client.accountId, { perPage: 25 }); ``` -------------------------------- ### assignments.list(query?) Source: https://github.com/assinafy/chat-sdk/blob/main/docs/API_REFERENCE.md Lists assignments for the account. Corresponds to GET /assignments. ```APIDOC ## GET /assignments ### Description Lists assignments for the account. ### Method GET ### Endpoint /assignments ### Parameters #### Query Parameters - **query** (ListAssignmentsQuery) - Optional - Query parameters for filtering and pagination. ### Response #### Success Response (200) - **Page** - A paginated list of assignments. ``` -------------------------------- ### whenReady() Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/chat.md Resolves once every adapter's initialize() has completed; rejects if any failed. Awaiting is optional — dispatch entry points await it internally. Useful for fail-fast startup. ```APIDOC ## whenReady() ### Description Resolves once every adapter's `initialize()` has completed; rejects if any failed. Awaiting is optional — dispatch entry points await it internally. Useful for fail-fast startup. ### Method `whenReady` ### Signature ```ts whenReady(): Promise ``` ### Returns - `Promise` - Resolves when all adapters are initialized, rejects if any failed. ``` -------------------------------- ### GET /documents/{documentId}/thumbnail Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves the document thumbnail as a raw response. ```APIDOC ## GET /documents/{documentId}/thumbnail ### Description Retrieves the document thumbnail as a raw response. ### Method GET ### Endpoint /documents/{documentId}/thumbnail ### Parameters #### Path Parameters - **documentId** (string) - Required - The document identifier. ### Response #### Success Response (200) - **body** (file) - The thumbnail image. ``` -------------------------------- ### OAuth Round Trip: Create Authorization URL Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Mints PKCE and state, builds the consent URL. No credentials needed; the OAuth endpoints authenticate the application. Redirect must be a full page load, not fetch(). ```TypeScript import { AssinafyClient, OAuthError } from "@assinafy/chat-sdk/client"; // No credentials needed — the OAuth endpoints authenticate the application. const client = new AssinafyClient(); // 1. Before redirecting: mint PKCE + state and build the consent URL. const request = await client.oauth.createAuthorizationUrl({ clientId: process.env.ASSINAFY_CLIENT_ID!, redirectUri: "https://myapp.example/oauth/callback", scopes: ["documents:read", "documents:write", "offline_access"], }); session.oauth = request; // keep the whole object: state, issuer, codeVerifier response.redirect(request.url); // a full page load, not fetch() ``` -------------------------------- ### GET /accounts/{accountId}/signers/{signerId} Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves a specific signer by ID. ```APIDOC ## GET /accounts/{accountId}/signers/{signerId} ### Description Retrieves a specific signer by ID. ### Method GET ### Endpoint /accounts/{accountId}/signers/{signerId} ### Parameters #### Path Parameters - **accountId** (string) - Required - The account identifier. - **signerId** (string) - Required - The signer identifier. ### Response #### Success Response (200) - **signer** (object) - The signer details. #### Response Example { "signer": {} } ``` -------------------------------- ### client.tags.create Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Creates a colored account-level tag. ```APIDOC ## client.tags.create ### Description Creates a colored account-level tag. ### Method POST ### Endpoint client.tags.create(accountId, { name: "Legal", color: "#2563EB" }) ### Parameters #### Path Parameters - **accountId** (string) - Required - The ID of the account. #### Request Body - **name** (string) - Required - The name of the tag. - **color** (string) - Required - The color of the tag in hex format. ### Request Example ```json { "name": "Legal", "color": "#2563EB" } ``` ### Response #### Success Response (200) - **tag** (object) - The created tag object. #### Response Example ```json { "id": "tag-id", "name": "Legal", "color": "#2563EB" } ``` ``` -------------------------------- ### GET /users/self/stats Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves statistics for the current user. Requires API authentication. ```APIDOC ## GET /users/self/stats ### Description Retrieves statistics for the current user. Requires API authentication. ### Method GET ### Endpoint /users/self/stats ### Parameters #### Query Parameters - (not specified) ### Request Example (not provided) ### Response #### Success Response (200) - (not specified) #### Response Example (not provided) ``` -------------------------------- ### Headless CLI bot example using createMemoryAdapter Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/memory-adapter.md Shows a headless CLI bot that uses the memory adapter to simulate a conversation and inspect sent messages. It demonstrates receiving a command, posting a response, and checking sentCount and lastSent. ```typescript import { Chat, AssinafyClient, createMemoryAdapter, MemoryStateAdapter } from "@assinafy/chat-sdk"; const client = AssinafyClient.fromEnv(); const memory = createMemoryAdapter(); const chat = new Chat({ userName: "Assinafy", adapters: { memory }, state: new MemoryStateAdapter(), client, }); chat.onCommand("docs", async (thread) => { const page = await client.documents.list(process.env.ASSINAFY_ACCOUNT_ID!, { perPage: 5 }); await thread.post(page.data.map((d) => d.name).join("\n")); }); // Drive a synthetic conversation and inspect what the bot "sent": await memory.receive({ text: "/docs" }); console.log(memory.sentCount); // number of outbound messages console.log(memory.lastSent?.text); // "…" memory.reset(); // clear between test cases ``` -------------------------------- ### GET /accounts Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Lists accounts. Authenticated with workspace credentials (API class). ```APIDOC ## GET /accounts ### Description Lists accounts. ### Method GET ### Endpoint `/accounts` ### Authentication API (X-Api-Key or Authorization: Bearer ) ### SDK Method `accounts.list` ### Response Responses are unwrapped from the `{ status, message, data }` envelope; pagination is carried by `X-Pagination-*` headers. ``` -------------------------------- ### get Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/accounts.md Fetches a single workspace account by its ID. Returns the Account object. ```APIDOC ## [GET] /accounts/{accountId} ### Description Fetches a single workspace account by its ID. ### Method GET ### Endpoint /accounts/{accountId} ### Parameters #### Path Parameters - **accountId** (string) - Required - The ID of the account ### Response #### Success Response (200) - **Account** - The account object #### Response Example ```json { "id": "string", "name": "string", "roles": ["string"] } ``` ``` -------------------------------- ### Upload and verify document (README pattern) Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/documents.md Uploads a PDF file using AssinafyClient.fromEnv() and logs the document ID and status. The status transitions from 'uploaded' to 'metadata_processing' to 'metadata_ready'. The body parameter accepts a Buffer as a Uint8Array. ```TypeScript import { readFile } from "node:fs/promises"; import { AssinafyClient } from "@assinafy/chat-sdk/client"; const client = AssinafyClient.fromEnv(); const pdf = await readFile("contract.pdf"); const doc = await client.documents.upload(accountId, { filename: "contract.pdf", body: pdf, // Buffer is a Uint8Array contentType: "application/pdf", }); console.log(doc.id, doc.status); // "uploaded" → "metadata_processing" → "metadata_ready" ``` -------------------------------- ### PUT /users/self/mfa/totp/confirm Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Confirms the TOTP MFA setup. Requires API authentication. ```APIDOC ## PUT /users/self/mfa/totp/confirm ### Description Confirms the TOTP MFA setup. Requires API authentication. ### Method PUT ### Endpoint /users/self/mfa/totp/confirm ### Parameters #### Request Body - (not specified) ### Request Example (not provided) ### Response #### Success Response (200) - (not specified) #### Response Example (not provided) ``` -------------------------------- ### Basic Chat wiring with memory adapter Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/chat.md Sets up a Chat instance with a memory adapter and a mention handler. Adapted from examples/basic-bot.ts. The example sends a test mention to the memory adapter to trigger the handler. ```ts import { Chat, createMemoryAdapter, MemoryStateAdapter, AssinafyClient } from "@assinafy/chat-sdk"; const client = AssinafyClient.fromEnv(); const memory = createMemoryAdapter(); const chat = new Chat({ userName: "Assinafy Bot", client, adapters: { memory }, state: new MemoryStateAdapter(), }); chat.onNewMention(async (thread, message) => { await thread.subscribe(); await thread.post(`Got it: "${message.text}"`); }); await memory.receive({ text: "hello", isMention: true }); ``` -------------------------------- ### GET /signers/self Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves the current signer's information. Requires Code authentication. ```APIDOC ## GET /signers/self ### Description Retrieves the current signer's information. ### Method GET ### Endpoint /signers/self ### Authentication Code ### Response #### Success Response (200) - No response schema documented. #### Response Example No response example provided. ``` -------------------------------- ### Run full verification suite Source: https://github.com/assinafy/chat-sdk/blob/main/README.en.md Runs all CI checks: type-checking, linting, unit tests with coverage thresholds, build, and smoke tests for ES module and CommonJS exports. ```bash npm run verify ``` -------------------------------- ### GET /documents/{documentId}/assignments/{assignmentId}/whatsapp-notifications Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/endpoints.md Retrieves WhatsApp notifications for an assignment. ```APIDOC ## GET /documents/{documentId}/assignments/{assignmentId}/whatsapp-notifications ### Description Retrieves WhatsApp notifications for an assignment. ### Method GET ### Endpoint /documents/{documentId}/assignments/{assignmentId}/whatsapp-notifications ### Parameters #### Path Parameters - **documentId** (string) - Required - The document identifier. - **assignmentId** (string) - Required - The assignment identifier. ### Response #### Success Response (200) - **notifications** (array) - List of WhatsApp notifications. #### Response Example { "notifications": [] } ``` -------------------------------- ### HttpClient constructor example Source: https://github.com/assinafy/chat-sdk/blob/main/docs/API_REFERENCE.md Creates an HttpClient with sandbox base URL and apiKey authentication. Supports retries and rate-limit handling. ```TypeScript const http = new HttpClient({ baseUrl: "https://sandbox.assinafy.com.br/v1", auth: { kind: "apiKey", apiKey: "api-key" }, maxRetries: 2, retryBaseDelayMs: 250, }); ``` -------------------------------- ### Instantiate a template example Source: https://github.com/assinafy/chat-sdk/blob/main/_autodocs/api-reference/templates.md Creates a document from a template with signer bindings, editor fields, a message, and an expiration date. This is the README pattern for using `client.templates.instantiate`. ```TypeScript const doc = await client.templates.instantiate(accountId, templateId, { name: "Contract — Acme", signers: [ { role_id: "role_owner", id: ownerSignerId, verification_method: "Whatsapp", notification_methods: ["Whatsapp", "Email"] }, { role_id: "role_signer", id: anaSignerId }, ], editor_fields: [{ field_id: "field_company", value: "ACME Ltda." }], message: "Please sign", expires_at: "2025-12-31T23:59:59Z", }); ```