JavaScript SDK
Official TypeScript-first SDK for Node.js and browser environments.
Installation
npm
npm install @chatmefy/sdkyarn
yarn add @chatmefy/sdkQuick Start
TypeScript
import { Chatmefy } from '@chatmefy/sdk';
// Initialize the client
const chatmefy = new Chatmefy({
apiKey: process.env.CHATMEFY_API_KEY,
});
// List recent leads
const leads = await chatmefy.leads.list({
limit: 10,
scoreMin: 70,
});
console.log(leads.data);
// Get a specific conversation
const conversation = await chatmefy.conversations.get('conv_abc123');
console.log(conversation.messages);
// Send a message as an agent
await chatmefy.messages.create('conv_abc123', {
content: 'Hi, I am taking over this conversation!',
role: 'agent',
});Available Methods
chatmefy.leads
.list(options)List all leads with filters.get(id)Get a single lead.update(id, data)Update lead fields.delete(id)Delete a leadchatmefy.conversations
.list(options)List all conversations.get(id)Get conversation with messages.end(id)End a conversationchatmefy.messages
.list(conversationId)List messages in conversation.create(conversationId, data)Send a messagechatmefy.bots
.list()List all bots.get(id)Get bot configuration.update(id, data)Update bot settingsTypeScript Support
The SDK is written in TypeScript and includes full type definitions:
Full autocomplete support in VS Code and other editors
Type-safe API responses
Inline documentation with JSDoc
Exported types for all objects (Lead, Conversation, Message, etc.)
Error Handling
import { Chatmefy, ChatmefyError } from '@chatmefy/sdk';
try {
const lead = await chatmefy.leads.get('invalid_id');
} catch (error) {
if (error instanceof ChatmefyError) {
console.log(error.code); // 'not_found'
console.log(error.message); // 'Lead not found'
console.log(error.status); // 404
}
}