DevHub Node.js SDK 📡

Official Node.js SDK for the DevHub Communication API.
📦 Installation
npm i @devotel/devhub
🔧 Module Compatibility
This SDK supports both ESM (ES Modules) and CommonJS module systems:
ESM (ES Modules)
import DevHubSDK from "@devotel/devhub";
import { DevHubSDK } from "@devotel/devhub";
const devhub = new DevHubSDK({
apiKey: "<your-api-key>",
});
CommonJS
const DevHubSDK = require("@devotel/devhub").default;
const { DevHubSDK } = require("@devotel/devhub");
const devhub = new DevHubSDK({
apiKey: "<your-api-key>",
});
🚀 Quick Start
import DevHubSDK from "@devotel/devhub";
const devhub = new DevHubSDK({
apiKey: "your-api-key",
});
await devhub.sms.send({
recipient: "+1234567890",
message: "Hello from DevHub!",
sender: "<sender>",
});
await devhub.email.send({
recipient: "user@example.com",
subject: "Hello",
body: "<h1>Hello from DevHub!</h1>",
sender: "sender@example.com",
});
await devhub.whatsapp.sendNormalMessage({
account_id: "your-account-id",
to: "+1234567890",
type: "text",
text: { body: "Hello from DevHub!" },
});
📚 API Reference
SMS Service
await devhub.sms.send({
recipient: "+1234567890",
message: "Your message",
sender: "optional-sender-id",
});
await devhub.sms.getSenders();
await devhub.sms.buyNumber({
country_code: "US",
area_code: "555",
});
await devhub.sms.getNumbers();
Email Service
await devhub.email.send({
recipient: "recipient@example.com",
subject: "Subject",
body: "<p>HTML content</p>",
sender: "sender@example.com",
});
WhatsApp Service
await devhub.whatsapp.getAccounts();
await devhub.whatsapp.sendTemplateMessage("account-id", {
to: "+1234567890",
template: {
name: "template-name",
language: { code: "en" },
},
});
await devhub.whatsapp.sendNormalMessage({
account_id: "your-account-id",
to: "+1234567890",
type: "text",
text: { body: "Hello!" },
});
await devhub.whatsapp.getTemplates();
Contacts Service
await devhub.contacts.getContacts();
await devhub.contacts.createContact({
firstName: "John",
lastName: "Doe",
phoneNumber: "+1234567890",
email: "john@example.com",
});
await devhub.contacts.updateContact("contact-id", {
firstName: "Jane",
});
await devhub.contacts.createCustomField({
label: "Company",
component: "Input",
required: false,
});
RCS Service
await devhub.rcs.getAccounts();
await devhub.rcs.send({
account_id: "your-account-id",
number: "+1234567890",
contentMessage: {
text: "Hello from RCS!",
},
});
await devhub.rcs.createTemplate({
name: "greeting",
content: "Hello {{name}}!",
});
Contact Groups Service
await devhub.contactGroups.getContactGroups();
await devhub.contactGroups.createContactGroup({
name: "VIP Customers",
description: "High value customers",
});
await devhub.contactGroups.updateContactGroup("group-id", {
name: "Premium Customers",
});
Unified Messages Service
await devhub.messages.send({
channel: "SMS",
sms: {
sender: "DevHub",
recipient: "+1234567890",
message: "Hello!",
},
});
⚠️ Error Handling
All methods return a response object with the following structure:
{
success: boolean,
data?: any,
error?: string
}
Example:
const result = await devhub.sms.send({
recipient: "+1234567890",
message: "Hello!",
});
if (result.success) {
console.log("Message sent:", result.data);
} else {
console.error("Error:", result.error);
}
🔷 TypeScript Support
The SDK is written in TypeScript and provides full type definitions. Available types:
Core Types
import { DevHubConfig, ApiResponse, ChannelType } from "@devotel/devhub";
SMS Types
import { SmsMessage, BuyNumberRequest } from "@devotel/devhub";
const smsData: SmsMessage = {
recipient: "+1234567890",
message: "Hello!",
sender: "DevHub",
};
Email Types
import { EmailMessage } from "@devotel/devhub";
const emailData: EmailMessage = {
recipient: "user@example.com",
subject: "Hello",
body: "<h1>Hello!</h1>",
sender: "sender@example.com",
};
WhatsApp Types
import { WhatsAppTemplate, WhatsAppNormalMessage } from "@devotel/devhub";
const templateData: WhatsAppTemplate = {
to: "+1234567890",
template: {
name: "hello_world",
language: { code: "en" },
},
};
const normalData: WhatsAppNormalMessage = {
account_id: "your-account-id",
to: "+1234567890",
type: "text",
text: { body: "Hello!" },
};
Contact Types
import { Contact, CustomField } from "@devotel/devhub";
const contactData: Contact = {
firstName: "John",
lastName: "Doe",
email: "john@example.com",
phoneNumber: "+1234567890",
};
const fieldData: CustomField = {
label: "Company",
component: "Input",
required: false,
};
RCS Types
import { RcsMessage } from "@devotel/devhub";
const rcsData: RcsMessage = {
account_id: "your-account-id",
number: "+1234567890",
contentMessage: {
text: "Hello from RCS!",
},
};
Unified Messages
import { UnifiedMessage } from "@devotel/devhub";
const unifiedData: UnifiedMessage = {
channel: "SMS",
sms: {
sender: "DevHub",
recipient: "+1234567890",
message: "Hello!",
},
};
📄 License
MIT