Aimdoc AI SDKs

Aimdoc provides official SDKs for JavaScript/TypeScript and React so you can control chat behavior directly from your app.

Use these SDKs to:

  • Identify signed-in users when your embedded agent is running in App Mode
  • Open the chat programmatically
  • Send messages into the conversation flow
  • Attach host application context to the next user message

Official libraries

JavaScript / TypeScript SDK

Use @aimdoc/sdk to identify users, open chat, and send messages programmatically.

View package

JavaScript / TypeScript SDK logo

React SDK

Use @aimdoc/sdk-react with AimdocProvider and useAimdoc for React applications.

View package

React SDK logo

Install

Install the package that fits your stack:

# JavaScript / TypeScript
npm install @aimdoc/sdk

# React
npm install @aimdoc/sdk-react

JavaScript SDK

The JavaScript SDK exports a singleton aimdoc client:

import { aimdoc } from '@aimdoc/sdk'

aimdoc.identify({
  external_id: 'user_123',
  email: 'jane@company.com',
  first_name: 'Jane',
  last_name: 'Doe',
  company: 'Acme Inc',
  attributes: {
    plan: 'pro',
  },
})

aimdoc.openChat({ agentId: 'your-agent-id' })
aimdoc.sendMessage('Can you show enterprise pricing?', { agentId: 'your-agent-id' })
aimdoc.setNextMessageContext(
  `The user is viewing the onboarding checklist.
They have already connected Salesforce and imported teammates.
They are currently on the "Invite teammates" step, with the invite modal open.
The last invite attempt failed because the email domain did not match their company domain.`,
  { agentId: 'your-agent-id' },
)

Available methods

  • identify(user) — attach user identity and profile attributes for App Mode sessions.
  • openChat(options?) — open the chat launcher/widget.
  • sendMessage(message, options?) — send a message as the current visitor/user.
  • setNextMessageContext(context, options?) — add host application context to the next user message only.

agentId is optional in openChat, sendMessage, and setNextMessageContext. Provide it when your page can target multiple agents.

Use identify for durable user, company, or account attributes that should be attached to the contact profile. Use setNextMessageContext for transient app state that should help the agent answer the next message, such as where the user is in onboarding, what modal is open, which validation error just appeared, or what workflow step they are trying to complete. The context is added to the agent's prompt for one turn only, is not stored as a visible chat message, and is cleared after the next message payload is sent.

The first argument can be a string or any JSON-serializable value. Objects and arrays are serialized as formatted JSON before they are added to the agent prompt.

React SDK

The React SDK gives you AimdocProvider and useAimdoc.

'use client'

import { AimdocProvider } from '@aimdoc/sdk-react'

export default function AppRoot() {
  return (
    <AimdocProvider agentId="your-agent-id">
      <App />
    </AimdocProvider>
  )
}

Inside child components, call the SDK through the hook:

'use client'

import { useAimdoc } from '@aimdoc/sdk-react'

export function OpenChatButton() {
  const { identify, openChat } = useAimdoc()

  const onClick = () => {
    identify({
      external_id: 'user_123',
      email: 'jane@company.com',
      company: 'Acme Inc',
    })
    openChat()
  }

  return <button onClick={onClick}>Chat with sales</button>
}

AimdocProvider props

  • agentId (required) — your Aimdoc agent ID.
  • scriptUrl (optional) — custom script URL. Defaults to https://app.aimdoc.ai/embedded.bundle.js.

Next steps

Was this page helpful?