For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.

AI agent and chatbot integration

Add your own AI agent or chatbot to a conversation as a participant that reads and sends messages.

View as Markdown

In TalkJS, an AI agent or chatbot is a user like any other, and it joins 1-on-1 chats and group chats as a participant. You bring the model. Your server receives new messages, asks the model for a reply, and sends it as the agent.

Four steps: a person sends a message in a 1-on-1 or group chat; TalkJS tells your server through a message.sent webhook or the Data API; your server asks your model; your server sends the reply with the REST API, as the agent.

How an AI agent answers in a TalkJS conversation

How to add an AI agent or chatbot to conversations between users

  1. Create a user for the agent with the name and photo people should see: create or update a user.
  2. Add the agent to a conversation: join conversation. The agent can read the messages sent before it joined.
  3. Listen for new messages with a webhook for the message.sent event, or connect as the agent with the JavaScript Data API. The Data API needs no public URL, but your server has to stay connected.
  4. Send the reply as the agent: send a message with the agent's ID as the sender.

AI chatbot integration in group chats

In a group chat, an agent that answers every message gets in the way. Each message.sent event has a mentionedUserIds list, so your agent can stay quiet until someone mentions it.

Chat API features for AI agents and chatbots

AI agent and chatbot integration guides