DrTalks.ai Documentation
Everything you need to get your DrTalks chat widget up and running on your website.
Once the DrTalks widget script is on your page, a global drtalksai object lets you control the chat widget from your own JavaScript — for example, opening it from a custom button.
drtalksai object.| Command | Returns | Description |
|---|---|---|
drtalksai.open() | void | Opens the chat window. |
drtalksai.close() | void | Closes the chat window. |
drtalksai.toggle() | void | Opens the window if closed, closes it if open. |
drtalksai.draft(text) | void | Opens the window and pre-fills the message box with your text (replacing anything already typed). Does not send. |
drtalksai.send(text) | Promise<boolean> | Opens the window and sends a message. Resolves true once dispatched, or false if it was blocked (empty text, too long, or rate-limited). |
drtalksai.getMessages() | { role, content, timestamp }[] | Returns the current conversation transcript for this browser tab. Reads the saved history, so it works whether the widget is open or closed. In-flight and errored messages are excluded; returns an empty array when there is no conversation yet. If an inline block with share-context is on the same page, the returned transcript is shared with that block. |
Open or toggle the widget from your own button:
<!-- Your own button anywhere on the page -->
<button onclick="drtalksai.open()">Chat with us</button>
<button onclick="drtalksai.toggle()">Toggle chat</button>Send (or pre-fill) a question from a call-to-action:
<button id="ask-hours">Ask about our hours</button>
<script>
document.getElementById('ask-hours').addEventListener('click', () => {
// Open the widget and send the question in one step
drtalksai.send('What are your opening hours?');
});
// Or pre-fill the box and let the visitor edit before sending:
// drtalksai.draft('I have a question about ...');
</script>Check whether a message was delivered:
const delivered = await drtalksai.send('Hello!');
if (!delivered) {
// Message was blocked (empty, too long, or rate-limited).
console.log('Message was not sent');
}Read the conversation transcript:
// Read the conversation so far (works open or closed)
const transcript = drtalksai.getMessages();
// → [
// { role: 'user', content: 'What are your hours?', timestamp: '2026-06-02T10:00:01.000Z' },
// { role: 'assistant', content: 'We are open 9–5.', timestamp: '2026-06-02T10:00:03.000Z' },
// ]
// Example: show a "continue your chat" prompt if the visitor already started one
if (transcript.length > 0) {
showResumeChatBanner();
}Shared with inline blocks: if you also embed a <drtalks-chat-block> with share-context on the same page, it shares this same saved conversation — so this method and that block's own getMessages() return the same transcript, and a message sent in either surface shows up in the other. Because it reads the saved history, call it after a reply has settled to see the latest turn.
window.DrTalksChat is kept as a legacy alias of drtalksai and exposes the same commands, so existing integrations keep working.