Skip to content

msgcore/msgcore-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@msgcore/sdk

TypeScript SDK for MsgCore - Universal messaging gateway API.

Auto-generated from backend contracts - Do not edit manually

Installation

npm install @msgcore/sdk

Quick Start

import { MsgCore } from '@msgcore/sdk';

const gk = new MsgCore({
  apiUrl: 'https://api.msgcore.dev',
  apiKey: 'msc_live_your_api_key_here',
});

// Send a message
const result = await gk.messages.send({
  targets: [{ platformId: 'platform-id', type: 'user', id: '123' }],
  content: { text: 'Hello from MsgCore!' },
});

Features

  • âś… Full type safety - TypeScript types auto-generated from backend
  • âś… Perfect sync - Always matches backend API contracts
  • âś… Zero duplication - Single source of truth from contracts
  • âś… Error handling - Built-in error types and authentication handling
  • âś… Rate limiting - Automatic rate limit detection

API Reference

ApiKeys

Generate a new API key

// Create messaging API key
await gk.apikeys.create(data);

List all API keys for project

// List all API keys
await gk.apikeys.list();

Auth

Create a new user account (first user becomes admin)

// Create first admin user
await gk.auth.signup(data);

Login with email and password

// Login with email and password
await gk.auth.login(data);

Identities

Create a new identity with platform aliases

// Create identity with Discord and Telegram aliases
await gk.identities.create(data);

List all identities for a project

// List all identities
await gk.identities.list();

Members

List all members of a project

// List all project members
await gk.members.list();

Add a member to a project

// Add a member with admin role
await gk.members.add(data);

Messages

List received messages for a project

// Get latest 50 messages
await gk.messages.list(data);

Get message statistics for a project

// Get message statistics
await gk.messages.stats();

Platform Logs

List platform processing logs for a project

// List recent platform logs
await gk.platformLogs.list();

List logs for a specific platform configuration

// List logs for specific platform
await gk.platformLogs.get('platformId');

Platforms

Configure a new platform integration

// Add Discord bot
await gk.platforms.create(data);

List configured platforms for project

// List all platforms
await gk.platforms.list();

Projects

Create a new project

// Create a simple project
await gk.projects.create(data);

List all projects

// List all projects
await gk.projects.list();

Webhooks

Create a new webhook for event notifications

// Create webhook for all message events
await gk.webhooks.create(data);

List all webhooks for a project

// List all webhooks
await gk.webhooks.list();

Authentication

API Key (Recommended)

const gk = new MsgCore({
  apiUrl: 'https://api.msgcore.dev',
  apiKey: 'msc_live_your_api_key_here',
  defaultProject: 'my-project', // optional
});

JWT Token

const gk = new MsgCore({
  apiUrl: 'https://api.msgcore.dev',
  jwtToken: 'your-jwt-token',
});

Error Handling

import { MsgCoreError, AuthenticationError, RateLimitError } from '@msgcore/sdk';

try {
  await gk.messages.send({ ... });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Invalid credentials');
  } else if (error instanceof RateLimitError) {
    console.error('Rate limit exceeded');
  } else if (error instanceof MsgCoreError) {
    console.error(`API error: ${error.message}`);
  }
}

Links

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published