MessagesAPI Documentation

MessagesAPI is a JavaScript library for interacting with various APIs, including Messages, Conversations, Applications, and conv.php.

Setup

Include the messages.js file in your HTML:

<script src="messages.js"></script>

Set your API key after the script is loaded. The MessagesAPI object is globally accessible as window.Messages:

<script>
  window.Messages.setApiKey('YOUR_API_KEY_HERE');
</script>

APIs

1. Messages API

Methods for managing messages:

2. Conversations API

Methods for managing conversations:

3. Applications API

Methods for managing applications:

4. conv.php API

Methods for retrieving conversations for a specific user:

5. Start API

Methods for starting a new conversation with the first message:

6. Reads API

Methods for marking messages as read:

TypeScript Type Declarations

Below are the TypeScript interfaces for the API responses:

// Message API Response
interface Message {
  id: number;
  conversationId: number;
  userId: number;
  toUserId: number;
  type: string;
  typeId: number;
  metadata: Record<string, any>;
  text: string;
  createdAt: string;
  updatedAt: string;
}

// Conversation API Response
interface Conversation {
  id: number;
  applicationId: number;
  type: string;
  typeId: number;
  metadata: Record<string, any>;
  status: string;
  createdAt: string;
  updatedAt: string;
  messages: Message[]; // Associated messages
}

// Application API Response
interface Application {
  id: number;
  name: string;
  apiKey: string;
  ownerUserId: number;
  createdAt: string;
  updatedAt: string;
}

// Start API Response
interface StartResponse {
  conversation: Conversation;
  message: Message;
}

// General API Error Response
interface ApiError {
  error: string;
  message: string;
}