@waapcoders/sdk
v1.0.0
Published
Official Node.js SDK for SaaS Chatbot Platform - Easy integration with chatbot APIs
Maintainers
Readme
SaaS Chatbot SDK for Node.js
Official Node.js/TypeScript SDK for SaaS Chatbot Platform. Easily integrate chatbot APIs into your Node.js applications.
🚀 Features
- ✅ Full API Coverage - All chatbot endpoints supported
- ✅ TypeScript Support - Full type definitions included
- ✅ Promise-based - Modern async/await support
- ✅ Zero Dependencies - Uses only Node.js built-ins
- ✅ Error Handling - Comprehensive error management
- ✅ Multi-Channel - WhatsApp, Telegram, Web, API channels
- ✅ Ticket System - Support ticket management
- ✅ Company Isolation - Multi-tenant ready
- ✅ ESM & CommonJS - Works in all environments
- ✅ Well Documented - Complete API reference
📦 Installation
npm
npm install @saaschatbot/sdkyarn
yarn add @saaschatbot/sdkpnpm
pnpm add @saaschatbot/sdk🎯 Quick Start
Basic Setup
const ChatbotSDK = require('@saaschatbot/sdk');
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
sdkURL: 'https://chat.waapcoders.in',
accessToken: 'YOUR_JWT_TOKEN'
});
// Create a bot
const bot = await sdk.createBot({
botName: 'My Bot',
description: 'Customer support bot'
});
console.log('Bot created:', bot);TypeScript
import ChatbotSDK from '@saaschatbot/sdk';
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
sdkURL: 'https://chat.waapcoders.in',
accessToken: 'YOUR_JWT_TOKEN'
});
const bot = await sdk.createBot({
botName: 'My Bot',
description: 'Support bot'
});ES Modules
import ChatbotSDK from '@saaschatbot/sdk';
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
accessToken: 'YOUR_JWT_TOKEN'
});📚 API Reference
Bot Management
Create Bot
const bot = await sdk.createBot({
botName: 'My Chatbot',
description: 'Customer support chatbot'
});Get Bot
const bot = await sdk.getBot('bot-id');List Bots
const bots = await sdk.listBots();Update Bot
const updated = await sdk.updateBot('bot-id', {
botName: 'Updated Name',
description: 'New description'
});Delete Bot
await sdk.deleteBot('bot-id');Channel Management
Setup WhatsApp
await sdk.setupWhatsApp('bot-id', {
phoneNumberId: 'YOUR_PHONE_NUMBER_ID',
accessToken: 'YOUR_WHATSAPP_TOKEN',
displayPhoneNumber: '+1234567890'
});Setup Telegram
await sdk.setupTelegram('bot-id', {
botToken: 'YOUR_TELEGRAM_BOT_TOKEN',
webhookUrl: 'https://yourserver.com/telegram/webhook'
});Get Channels
const channels = await sdk.getChannels('bot-id');Test WhatsApp
const result = await sdk.testWhatsApp('bot-id', '+1234567890');Test Telegram
const result = await sdk.testTelegram('bot-id');Chat & Messaging
Send Message
const response = await sdk.sendMessage({
botId: 'bot-id',
botToken: 'bot-token',
message: 'Hello! How can I help?',
userId: 'user-id',
sessionId: 'session-id',
channel: 'web'
});Get Conversation
const messages = await sdk.getConversation('session-id');Ticket Management
Create Ticket
const ticket = await sdk.createTicket({
botId: 'bot-id',
subject: 'Customer Issue',
description: 'User reported an issue',
priority: 'high',
channel: 'web',
customerEmail: '[email protected]',
customerName: 'John Doe'
});Get Ticket
const ticket = await sdk.getTicket('ticket-id');List Tickets
const tickets = await sdk.listTickets('bot-id');Update Ticket Status
await sdk.updateTicketStatus('ticket-id', 'resolved');Assign Ticket
await sdk.assignTicket('ticket-id', 'agent-id');Add Ticket Reply
await sdk.addTicketReply('ticket-id', {
message: 'Thank you for reporting',
isCustomerReply: false,
repliedBy: 'agent-name'
});Get Ticket Metrics
const metrics = await sdk.getTicketMetrics('bot-id');Company Management (SuperAdmin only)
Create Company
const company = await sdk.createCompany({
name: 'Acme Corp',
email: '[email protected]',
phone: '+1234567890'
});List Companies
const companies = await sdk.listCompanies();Get Company
const company = await sdk.getCompany('company-id');Update Company
await sdk.updateCompany('company-id', {
name: 'New Name',
email: '[email protected]'
});Settings
Get Settings
const settings = await sdk.getSettings();Update Settings
await sdk.updateSettings({
apiKey: 'new-api-key',
webhookUrl: 'https://yourserver.com/webhook'
});Get 2FA Status
const twoFaStatus = await sdk.get2FAStatus();⚙️ Configuration
SDKConfig Interface
interface SDKConfig {
baseURL: string; // Required: API base URL
sdkURL?: string; // Optional: SDK CDN URL
accessToken?: string; // JWT token for authenticated endpoints
apiKey?: string; // Alternative: API key authentication
timeout?: number; // Request timeout in ms (default: 30000)
debug?: boolean; // Enable debug logging (default: false)
}Environment Variables
# .env file
CHATBOT_API_URL=https://smile.waapcoders.in
CHATBOT_SDK_URL=https://chat.waapcoders.in
CHATBOT_ACCESS_TOKEN=your_jwt_token_hereUsage with Environment Variables
const sdk = new ChatbotSDK({
baseURL: process.env.CHATBOT_API_URL,
sdkURL: process.env.CHATBOT_SDK_URL,
accessToken: process.env.CHATBOT_ACCESS_TOKEN,
debug: process.env.NODE_ENV === 'development'
});🔐 Authentication
The SDK supports two authentication methods:
JWT Token (Recommended)
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
});API Key
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
apiKey: 'your-api-key'
});❌ Error Handling
The SDK provides structured error objects:
try {
const bot = await sdk.getBot('invalid-id');
} catch (error) {
console.error('Status:', error.status); // HTTP status code
console.error('Message:', error.message); // Error message
console.error('Details:', error.data); // Full response data
}Common Errors
// 404 - Bot not found
// 401 - Unauthorized (invalid token)
// 400 - Bad request (invalid parameters)
// 500 - Server error📋 Examples
Complete Bot Setup Example
const ChatbotSDK = require('@saaschatbot/sdk');
async function setupBot() {
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
accessToken: process.env.JWT_TOKEN
});
try {
// 1. Create bot
const bot = await sdk.createBot({
botName: 'Support Bot',
description: 'Customer support automation'
});
console.log('✓ Bot created:', bot.botId);
// 2. Setup WhatsApp channel
await sdk.setupWhatsApp(bot.botId, {
phoneNumberId: process.env.WHATSAPP_PHONE_ID,
accessToken: process.env.WHATSAPP_TOKEN,
displayPhoneNumber: '+1234567890'
});
console.log('✓ WhatsApp channel configured');
// 3. Setup Telegram channel
await sdk.setupTelegram(bot.botId, {
botToken: process.env.TELEGRAM_TOKEN,
webhookUrl: 'https://myserver.com/telegram'
});
console.log('✓ Telegram channel configured');
// 4. Test channels
await sdk.testWhatsApp(bot.botId, '+1234567890');
await sdk.testTelegram(bot.botId);
console.log('✓ Channels tested successfully');
return bot;
} catch (error) {
console.error('Setup failed:', error.message);
throw error;
}
}
setupBot().then(bot => {
console.log('Bot setup complete!', bot);
}).catch(err => {
process.exit(1);
});Ticket Management Example
async function handleTickets() {
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
accessToken: process.env.JWT_TOKEN
});
// Create ticket from chat escalation
const ticket = await sdk.createTicket({
botId: 'bot-123',
subject: 'User reported issue',
description: 'Customer cannot complete purchase',
priority: 'high',
channel: 'web',
customerEmail: '[email protected]',
customerName: 'Alice'
});
console.log('Ticket created:', ticket.ticketId);
// List all tickets
const tickets = await sdk.listTickets('bot-123');
console.log(`Found ${tickets.length} tickets`);
// Get metrics
const metrics = await sdk.getTicketMetrics('bot-123');
console.log('Metrics:', metrics);
}🧪 Testing
# Run all tests
npm test
# Run tests in watch mode
npm test:watch
# Run with coverage
npm test -- --coverage📦 Building
# Build everything (compile, minify, docs)
npm run build
# Build only (compile + minify)
npm run build:dist
# Clean build
npm run clean && npm run build
# Minify only
npm run minify
# Generate docs
npm run build:docs🚀 Publishing to npm
Setup (First Time)
# Create npm account if you don't have one
npm adduser
# Verify you're logged in
npm whoamiPublishing
# Publish to npm
npm run publish:npm
# Or use npm directly
npm publish --access public
# For beta versions
npm run publish:betaVersioning
# Update version (major.minor.patch)
npm version patch # 1.0.0 → 1.0.1
npm version minor # 1.0.0 → 1.1.0
npm version major # 1.0.0 → 2.0.0
# This will auto-commit and push to git🔗 Integration Examples
Express.js Backend
const express = require('express');
const ChatbotSDK = require('@saaschatbot/sdk');
const app = express();
const sdk = new ChatbotSDK({
baseURL: process.env.CHATBOT_API_URL,
accessToken: process.env.CHATBOT_TOKEN
});
app.post('/api/bots', async (req, res) => {
try {
const bot = await sdk.createBot(req.body);
res.json(bot);
} catch (error) {
res.status(error.status || 500).json({ error: error.message });
}
});
app.listen(3000);Next.js API Route
// pages/api/bots.js
import ChatbotSDK from '@saaschatbot/sdk';
const sdk = new ChatbotSDK({
baseURL: process.env.CHATBOT_API_URL,
accessToken: process.env.CHATBOT_TOKEN
});
export default async function handler(req, res) {
if (req.method === 'POST') {
try {
const bot = await sdk.createBot(req.body);
res.status(200).json(bot);
} catch (error) {
res.status(error.status || 500).json({ error: error.message });
}
}
}📖 Documentation
🐛 Troubleshooting
Connection Issues
// Enable debug mode to see detailed logs
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
accessToken: 'your-token',
debug: true // Shows all API calls
});Authentication Errors
// Verify token is valid and not expired
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
accessToken: process.env.CHATBOT_TOKEN // Use env variables
});
// Check token claims
console.log('Token:', sdk.accessToken);Timeout Issues
// Increase timeout for slow connections
const sdk = new ChatbotSDK({
baseURL: 'https://smile.waapcoders.in',
accessToken: 'your-token',
timeout: 60000 // 60 seconds
});🤝 Contributing
Contributions welcome! Please see CONTRIBUTING.md
📄 License
MIT - See LICENSE
🆘 Support
- 📧 Email: [email protected]
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
🔗 Related Resources
Made with ❤️ by SaaS Chatbot Team
