Quick Start
Get started with Advanced iMessage Kit SDK in just a few minutes. This guide walks you through creating a simple auto-reply bot that responds to incoming messages.Step 1: Install the SDK
If you haven’t already, install the SDK:Step 2: Initialize the SDK
Create a new file and import the SDK:index.ts
The
SDK() function is a singleton that returns the same instance across your application. You can call it multiple times without creating duplicate connections.Step 3: Listen for Events
Set up event listeners to handle incoming messages:index.ts
Step 4: Connect to the Server
Establish the connection to the iMessage server:index.ts
Complete Example
Here’s the full auto-reply bot in one file:auto-reply.ts
Run Your Bot
Run the example:Understanding the Code
SDK Initialization
The
SDK() function creates or returns the singleton instance with your server configuration. The serverUrl points to your Advanced iMessage Kit server, and apiKey authenticates your connection (if required).Event Listeners
The SDK is event-driven. The
ready event fires when connected and authenticated. The new-message event fires whenever a new message arrives in any chat.Message Filtering
The
message.isFromMe property identifies messages you sent, preventing the bot from replying to itself. The message.chats array contains the conversations this message belongs to.Sending Messages
Use
sdk.messages.sendMessage() to send a message. The chatGuid identifies the conversation, and messages are automatically queued to ensure delivery order.Available Events
The SDK emits several events you can listen to:ready- Connection established and authenticatednew-message- New message receivedupdated-message- Message status updated (delivered, read)typing-indicator- Someone is typinggroup-name-change- Group chat name changedparticipant-added- Participant added to groupparticipant-removed- Participant removed from grouperror- An error occurreddisconnect- Connection lost
See the Events API reference for the complete list of events and their payloads.
Next Steps
Configuration
Learn about all configuration options for the SDK
API Reference
Explore the complete API documentation
Examples
Browse more examples and use cases
Messages API
Deep dive into the Messages module