Skip to Content
The Makinari API repo now includes an MCP Server — connect your AI models directly. View on GitHub →

Main Functions

openChatWithWelcomeMessage()

Opens the chat displaying a personalized welcome message from the agent.

Syntax

window.MarketFit.openChatWithWelcomeMessage(welcomeMessage, options)

Parameters

  • welcomeMessage string (required): Welcome message to display
  • options object (optional): Additional configurations

Available Options

{ clearExistingMessages?: boolean; // default: false agentName?: string; // default: global configuration replaceWelcomeMessage?: boolean; // default: false newConversation?: boolean; // default: false }

Examples

Basic example:

window.MarketFit.openChatWithWelcomeMessage( "Hello! I saw you are browsing our products. Can I help you?" );

With options:

window.MarketFit.openChatWithWelcomeMessage( "Welcome to our premium support. How can we assist you?", { clearExistingMessages: true, newConversation: true, agentName: "Premium Support" } );

openChatWithTask()

A more versatile function that allows displaying welcome messages and/or pre-filling specific user tasks.

Syntax

window.MarketFit.openChatWithTask(options)

Parameters

  • options object (required): Chat task configuration

Available Options

{ welcomeMessage?: string; // Agent's welcome message task?: string; // Task to pre-fill for the user clearExistingMessages?: boolean; // default: false newConversation?: boolean; // default: false autoSend?: boolean; // default: false replaceWelcomeMessage?: boolean; // default: false }

Examples

Pre-fill user task:

window.MarketFit.openChatWithTask({ task: "I want to schedule a meeting to discuss pricing", clearExistingMessages: true });

Combine welcome and task:

window.MarketFit.openChatWithTask({ welcomeMessage: "Perfect! I'll help you schedule a meeting.", task: "I prefer a call on Monday or Tuesday morning", clearExistingMessages: true, newConversation: true });

Auto-send task:

window.MarketFit.openChatWithTask({ welcomeMessage: "I'll connect you with our sales team immediately.", task: "I want more information about the Enterprise plan", autoSend: true, clearExistingMessages: true });

identify()

Identifies the current user in the chat with their personal information and custom fields. This function is essential for providing a personalized experience and connecting conversations with specific users.

Syntax

window.MarketFit.identify(leadInfo)

Parameters

  • leadInfo object (required): User information to identify

leadInfo Properties

{ name?: string; // User's full name email?: string; // User's email phone?: string; // User's phone userId?: string; // Unique user ID in your system [key: string]: any; // Additional custom fields }

Return Value

Promise - Resolves when identification is successful

Examples

Basic identification:

// Identify user after login window.MarketFit.identify({ name: 'John Doe', email: 'john@example.com', phone: '+1 123 456 7890' });

With custom fields:

// Identify with additional information window.MarketFit.identify({ name: 'Mary Smith', email: 'mary@company.com', phone: '+1 987 654 3210', userId: 'user_12345', subscriptionType: 'Premium', company: 'Company Inc.', role: 'CEO' });

With promise handling:

// Handle identification result window.MarketFit.identify({ name: 'Charles Wright', email: 'charles@startup.com', userId: 'usr_98765' }) .then(() => { console.log('User identified successfully'); // Optional: open chat with personalized message window.MarketFit.openChatWithWelcomeMessage( `Hello Charles! How can I help you today?` ); }) .catch(error => { console.error('Error identifying user:', error); });

Integration with authentication system:

// Function to execute after login function onUserLogin(userData) { if (window.MarketFit) { window.MarketFit.identify({ name: userData.fullName, email: userData.email, phone: userData.phoneNumber, userId: userData.id, subscriptionType: userData.subscription, lastLogin: new Date().toISOString() }) .then(() => { console.log('User identified in chat'); }) .catch(error => { console.error('Error in identification:', error); }); } }

Best Practices

  • Execute after login: Call identify() immediately after the user authenticates.
  • Minimal information: Include at least name and email for effective identification.
  • Custom fields: Use additional fields for context (plan, company, role, etc.).
  • Error handling: Always handle promises to detect identification issues.
  • Check availability: Ensure the chat is initialized before calling identify().

Verify Identification State

// Verify if a user is identified const hasUser = window.MarketFit.hasIdentifiedUser(); console.log('User identified:', hasUser); // Verify current user information const currentUser = window.MarketFit.getCurrentUser(); console.log('User information:', currentUser); // You can also get the chat state which includes user info const chatState = window.MarketFit.chat.getState(); console.log('Full chat state:', chatState);
Last updated on