rsendly-temp
v0.1.3
Published
Official TypeScript/JavaScript SDK for Rsendly SMS API
Downloads
15
Maintainers
Readme
Rsendly TypeScript/JavaScript SDK
Official TypeScript/JavaScript SDK for the Rsendly SMS Platform API.
Installation
npm install rsendly
# or
yarn add rsendlyQuick Start
TypeScript
import { Client } from 'rsendly';
// Initialize the client
const client = new Client({
authToken: 'your_auth_token',
senderToken: 'your_sender_token',
baseUrl: 'https://api.rsendly.com' // Optional, defaults to production
});
// Send a single SMS
const response = await client.sendSMS('+1234567890', 'Hello from Rsendly!');
console.log(`SMS sent: ${response.success}`);
// Send bulk SMS
const numbers = ['+1234567890', '+1234567891'];
const bulkResponse = await client.sendSMS(numbers, 'Bulk message!');
if ('total' in bulkResponse) {
console.log(`Sent ${bulkResponse.successful}/${bulkResponse.total} messages`);
}
// Check account balance
const balance = await client.getBalance();
console.log(`Balance: ${balance.balance} ${balance.currency}`);
// Get SMS history
const history = await client.getHistory({ limit: 10 });
console.log(`Total messages: ${history.pagination.total}`);
// Check number support
const numbersToCheck = ['+22612345678', '+1234567890'];
const support = await client.checkNumberSupport(numbersToCheck);
console.log(`Supported: ${support.supported}`);
console.log(`Unsupported: ${support.unsupported}`);JavaScript (ES6+)
const { Client } = require('rsendly');
const client = new Client({
authToken: 'your_auth_token',
senderToken: 'your_sender_token'
});
// Send SMS
client.sendSMS('+1234567890', 'Hello from JavaScript!')
.then(response => {
console.log(`SMS sent: ${response.success}`);
})
.catch(error => {
console.error(`Error: ${error.message}`);
});API Reference
Client
Constructor
new Client(config: ClientConfig)Where ClientConfig is:
interface ClientConfig {
authToken: string;
senderToken: string;
baseUrl?: string;
}Methods
sendSMS(to: string | string[], message: string): Promise<SMSResponse | BulkSMSResponse>
Send SMS message(s).
getSMSStatus(messageId: string): Promise<StatusResponse>
Check SMS delivery status.
getHistory(options?: HistoryOptions): Promise<HistoryResponse>
Get SMS history with pagination and filters.
interface HistoryOptions {
limit?: number;
offset?: number;
fromDate?: string;
toDate?: string;
status?: string;
}getBalance(): Promise<BalanceResponse>
Get account balance.
checkNumberSupport(numbers: string[]): Promise<NumberSupportResponse>
Check which phone numbers are supported.
getAPIInfo(): Promise<APIInfoResponse>
Get API information.
Types
The SDK includes full TypeScript definitions for all responses:
interface SMSResponse {
success: boolean;
messageId?: string;
error?: string;
historyId?: string;
}
interface BulkSMSResponse {
success: boolean;
total: number;
successful: number;
failed: number;
results: SMSResponse[];
}
interface BalanceResponse {
success: boolean;
balance: number;
currency: string;
senderId: string;
senderName: string;
workspaceId: string;
}
interface NumberSupportResponse {
supported: string[];
unsupported: string[];
}Error Handling
import { SMSPlatformError } from 'rsendly';
try {
const response = await client.sendSMS('+invalid', 'Test message');
} catch (error) {
if (error instanceof SMSPlatformError) {
console.error(`API Error: ${error.message}`);
if (error.statusCode) {
console.error(`Status Code: ${error.statusCode}`);
}
}
}Convenience Functions
import { sendQuickSMS } from 'rsendly';
// Quick SMS without creating client instance
const response = await sendQuickSMS(
'your_auth_token',
'your_sender_token',
'+1234567890',
'Quick message!'
);Browser Support
The SDK works in both Node.js and modern browsers. For browsers, ensure you handle CORS properly on your API server.
Requirements
- Node.js 14+
- TypeScript 4.0+ (if using TypeScript)
Development
# Install dependencies
npm install
# Build
npm run build
# Watch mode
npm run dev
# Run tests
npm test
# Lint
npm run lintLicense
MIT License - see LICENSE file for details.
