Skip to content

MsGineClient ​

Complete API reference for the MsGineClient class.

Constructor ​

new MsGineClient(config) ​

Creates a new MsGine SDK client instance.

typescript
import { MsGineClient } from '@msgine/sdk'

const client = new MsGineClient({
  apiKey: process.env.MSGINE_API_KEY!,
  baseUrl: 'https://api.msgine.net/api/v1', // optional
})

Parameters ​

ParameterTypeRequiredDescription
config.apiKeystringYesYour MsGine API key
config.baseUrlstringNoAPI base URL (default: https://api.msgine.net/api/v1)

Modules ​

The client exposes dedicated modules for each channel and resource type.

client.sms ​

sms.send(options) ​

Send an SMS message to one or more recipients.

typescript
const result = await client.sms.send({
  to: '+256701521269',
  message: 'Hello from MsGine!',
  from: 'MyApp'            // optional
})
ParameterTypeRequiredDescription
tostring | string[]YesRecipient phone number(s) in E.164 format
messagestringYesMessage content (max 1000 characters)
fromstringNoSender ID (max 11 alphanumeric characters)

Returns Promise<SendSmsResponse>:

typescript
{
  id: string              // Unique message identifier
  sid: string | null      // Provider-specific ID
  channel: string         // "sms"
  to: string[]           // Recipient phone numbers
  from: string           // Sender ID
  content: string        // Message content
  status: MessageStatus  // Current status
  cost: number          // Message cost in UGX
  currency: string      // "UGX"
  createdAt: string     // ISO 8601 timestamp
  updatedAt?: string    // ISO 8601 timestamp
}

Example:

typescript
try {
  const result = await client.sms.send({
    to: ['+256701521269', '+256701234567'],
    message: 'Welcome to MsGine!',
    from: 'MyApp'
  })

  console.log('Message sent:', result.id)
  console.log('Status:', result.status)
  console.log('Cost:', result.cost, result.currency)
} catch (error) {
  console.error('Failed to send SMS:', error)
}

sms.getHistory() ​

Retrieve SMS message history.

typescript
const history = await client.sms.getHistory()

client.email ​

email.send(options) ​

Send an email message.

typescript
const result = await client.email.send({
  to: 'user@example.com',
  subject: 'Welcome!',
  body: 'Thank you for signing up.',
})

client.push ​

push.send(options) ​

Send a push notification.

typescript
const result = await client.push.send({
  to: 'device-token',
  title: 'New message',
  body: 'You have a new notification',
})

client.analytics ​

analytics.overview() ​

Get a messaging analytics overview.

typescript
const overview = await client.analytics.overview()

analytics.daily() ​

Get daily analytics breakdown.

typescript
const daily = await client.analytics.daily()

client.messages ​

Access and retrieve message records.

Type Definitions ​

See the complete Type Reference for all available types and interfaces.

Error Handling ​

See the Error Handling Guide for detailed information about handling errors.

Next Steps ​

Released under the MIT License.