IMKIT Platform API
website·Indexed 32 days ago
https://docs.imkit.io/Core API service for the IMKIT Chat Server developed by FUNTEK. Provides comprehensive tools for messaging backend services, including user management, token issuance, chat room administration, and message operations such as sending, recalling, and pinning messages.
What's inside IMKIT
- IMKIT Platform API is a core API service developed by FUNTEK for developers using the IMKIT SDK. It provides a ready-to-use backend for real-time messaging services, supporting 1-on-1 private conversations and multi-user group chats. The service handles automatic message routing and storage, allowing developers to integrate chat functionality without building their own chat servers.
Overview of External Token Assignment in IMKIT
IMKIT allows applications with existing authentication systems to generate and verify their own user tokens and assign them to the IMKIT Chat Server. In this mode, IMKIT handles messaging while the developer's system manages the token lifecycle and verification logic.
Implementation Flow:
- Generate a custom token in your own system.
- Use the
/admin/clientsAPI to create a Client, providing the custom token and an expiration date. - Manage the token using the 'Update Token' or 'Revoke Token' APIs as needed.
- Handle all token verification logic within your own system.
Understand the IMKIT Client Key
The Client Key (IM-CLIENT-KEY) is a public authentication key used to identify applications in the IMKIT Platform API. Unlike the API Key, which provides administrative access, the Client Key is designed for frontend use and must be paired with a user Token (IM-Authorization) to perform operations on behalf of a specific user. It is primarily used for SDK initialization, establishing WebSocket connections, and user-level API operations.Understand User Groups vs Group Chat Rooms
A User Group is a virtual user identity representing a team or organizational unit. It is distinct from a Group Chat Room. When a User Group ID is added to a chat room's members or invitees list, all individual members within that group share access to that chat room and can send/receive messages there. This is primarily used for team management (e.g., Customer Service teams) and organizational structure (e.g., Project teams).Understand the IMKIT API Key (`IM-API-KEY`)
The API Key (IM-API-KEY) is a long-lived, Base64-encoded authentication key used exclusively for backend services. It grants full management permissions, allowing the holder to operate as a platform administrator. Unlike the Client Key, it is used independently and does not require a user Token. Because it provides full control over user management, chat rooms, and system settings, it must be kept strictly confidential and never exposed on the frontend.Socket Event Reference Overview
Once authenticated, clients can receive the following real-time events:
chat message: New message received.room: Chat room properties (members, settings) changed.lastRead: Member updated their last read marker.typing: Member is typing.ai_streaming: AI message streamed in chunks.roomPref: User updated a room preference.myPrefChange: User updated a personal preference.myPrefDelete: User deleted a personal preference.invitation: Group invitation received.userDeleteMessages: User deleted their own view of messages.messageDeleted: Admin permanently deleted a message.
Retrieve the current user's block list
Use the
GET /blockStatus/myendpoint to retrieve a complete list of users blocked by the current authenticated user. The response includes detailed information about the blocked user (blockee), the user who performed the block (blocker), the associated chatroom, and the timestamps for when the block was created and updated. This is used for privacy management, such as reviewing blocked users or implementing an unblock interface.Constraints & Notes:
- Users can only retrieve block relationships they created themselves.
- The API supports both direct and group chatroom block relationships.
- If no users are blocked, the API returns an empty array.
curl -X "GET" "https://your-app.imkit.io/blockStatus/my" \ -H 'IM-CLIENT-KEY: {IM-CLIENT-KEY}' \ -H 'IM-Authorization: {IM-Authorization}'const response = await axios.get( `https://your-app.imkit.io/blockStatus/my`, { headers: { "IM-CLIENT-KEY": IM_CLIENT_KEY, "IM-Authorization": TOKEN, }, } );Authenticate the IMKIT socket connection
Authentication is required after establishing a connection; otherwise, the client cannot receive events. Use theauth2event. If authentication fails, the server will close the connection, and the client should trigger its reconnect flow. Note thatauth2must be called again after every socket reconnection.function auth() { const token = "{IM-Authorization}"; const extra = { deviceId: "iphone-15-pro-uuid-001" // Should match value used for push token registration }; socket.emit("auth2", token, extra, (ack) => { console.log("[socket] auth ack:", ack); }); }Implement incremental synchronization for room lists
To avoid full data pulls and improve performance, use theupdatedAfterparameter. Store the timestamp from the last successful request and pass it into the next request to fetch only rooms that have new messages or were created since that time.Guidelines for managing runtime configuration deletion
When deleting runtime configurations (such as sensitive word censorship), keep the following constraints and recommendations in mind:
- Immediate Effect: Changes apply instantly; the associated feature (e.g., filtering) will be disabled immediately.
- Irreversibility: Deletions cannot be undone. Back up configurations before performing this action.
- Scope: This only affects runtime configurations, not file-based configurations.
- Dependencies: Verify that no other system features depend on the configuration key before deleting it.
- Monitoring: Monitor system functionality after deletion to ensure stability.
Mute push notifications for a user in a specific chatroom
Administrators can mute a specific chatroom's notifications for a specified user. This action prevents the user from receiving push notifications from that chatroom, but does not affect their participation permissions or ability to interact within the room. The setting takes effect immediately without requiring the user to re-login and is persistent until manually changed.Establish a Socket.IO connection to IMKIT
To enable real-time communication for messages, read-states, and typing indicators, use the Socket.IO client to connect to the IMKIT socket endpoint. It is recommended to usetransports: ['websocket']andforceNew: trueto ensure a clean connection.import { io } from "socket.io-client"; const socket = io("https://your-app.imkit.io", { forceNew: true, transports: ["websocket"] }); socket.on("connect", () => { console.log("[socket] connected"); });