augstash-sdk
v1.0.0
Published
Official TypeScript/Node.js SDK for the AugStash WhatsApp BSP Platform
Maintainers
Readme
augstash-sdk — Node.js / TypeScript
Official TypeScript SDK for the AugStash WhatsApp BSP Platform by AugmenTrait Pvt. Ltd.
Installation
npm install augstash-sdk
# or
yarn add augstash-sdkRequirements: Node.js ≥ 18 (uses native
fetch).
Quick Start
import AugStashClient, { AugStashError } from "augstash-sdk";
const client = new AugStashClient(
"https://api.augstash.com", // your AugStash deployment URL
"as_live_xxxxxxxxxxxx" // API key from Settings → Developer
);
// List connected WABA accounts
const connections = await client.listWabaConnections();
console.log(connections);
// Send a WhatsApp message
const result = await client.sendMessage({
wabaId: "1234567890",
phoneNumberId: "9876543210",
contactPhone: "+919876543210",
metaPayloadJson: JSON.stringify({
messaging_product: "whatsapp",
to: "+919876543210",
type: "text",
text: { body: "Hello from AugStash!" }
})
});
console.log(result.metaMessageId);Authentication
Every API call requires a Bearer API key issued per tenant.
Generate your key: AugStash Dashboard → Settings → Developer → API Keys
const client = new AugStashClient(baseUrl, apiKey);Keep your API key secret. Never commit it to source control.
Use environment variables:process.env.AUGSTASH_API_KEY
API Reference
WABA Management
// List all connected WABA accounts
const connections = await client.listWabaConnections();
// List phone numbers (optionally filter by WABA)
const phones = await client.listPhoneNumbers();
const wabaPhones = await client.listPhoneNumbers("waba-uuid");
// Get WABA health — quality rating, tier, daily limit per phone
const health = await client.getWabaHealth("meta-waba-id");
// → { wabaId, connectionStatus, phones: [{ qualityRating, messagingTier, dailyLimit }] }
// Submit display name with SLM pre-check before Meta submission
const result = await client.submitDisplayName(
"waba-id", "Acme Pharma", "Acme Pharmaceuticals Ltd.", "phone-number-id"
);
// → { displayNameStatus: "PENDING" | "BLOCKED_BY_SLM", slmScore, slmFeedback }
// Disconnect a WABA cleanly (pauses campaigns, revokes webhook)
await client.disconnectWaba("waba-id");
// Complete credential rotation after token expiry
await client.completeCredentialRotation("waba-id", "new-meta-auth-code");Contacts
// List with pagination and search
const page = await client.listContacts({ page: 0, size: 50, search: "Ravi" });
// → { content: Contact[], totalElements, totalPages }
// Create contact
const contact = await client.createContact({
phone: "+919876543210",
name: "Ravi Kumar",
email: "[email protected]",
tags: ["vip", "mumbai"]
});
// Update contact
await client.updateContact("contact-uuid", { name: "Ravi K." });
// Bulk import (up to 1,000 contacts)
const summary = await client.bulkImportContacts([
{ phone: "+919876543210", name: "Ravi Kumar" },
{ phone: "+919123456789", name: "Priya Sharma" }
]);
// → { imported: 2, failed: 0 }
// Record opt-out
await client.optOutContact("contact-uuid");Campaigns
// Create a campaign
const campaign = await client.createCampaign({
name: "Diwali Offer 2025",
templateId: "template-uuid",
segmentId: "segment-uuid",
attributionGoal: "augvanta.finance.invoice.paid",
attributionWindowHours: 48
});
// Launch immediately
await client.launchCampaign(campaign.id!);
// Pause / Resume
await client.pauseCampaign(campaign.id!);
await client.resumeCampaign(campaign.id!);
// Full funnel analytics
const analytics = await client.getCampaignAnalytics(campaign.id!);
// → { sentCount, deliveredCount, readCount, repliedCount, goalCompletedCount,
// deliveryRate, readRate, optOutRate }
// Per-contact drill-down
const recipients = await client.getCampaignRecipients(campaign.id!, { page: 0, size: 100 });
// Export as CSV
const csv = await client.exportCampaignCsv(campaign.id!);
// csv is a string — save with fs.writeFileSync("report.csv", csv)Templates
// Create a template
await client.createTemplate({
name: "invoice_payment_reminder",
category: "UTILITY",
language: "en",
wabaId: "meta-waba-id",
components: JSON.stringify({
body: { type: "BODY", text: "Hi {{1}}, your invoice of ₹{{2}} is due on {{3}}." }
})
});
// Browse available template packs
const packs = await client.listTemplatePacks();
// → [{ id: "bfsi", name: "BFSI Template Pack", templateCount: "6" }, ...]
// Import a pack (creates PENDING drafts ready for Meta submission)
const result = await client.importTemplatePack("bfsi", "meta-waba-id");
// → { imported: 6, skipped: 0, total: 6 }Inbox
// List agent conversations
const inbox = await client.listConversations({ page: 0, size: 20 });
// Assign conversation
await client.assignConversation("conv-id", { agentId: "agent-user-id" });
// Reply (auto-translates to contact's preferred language)
await client.replyToConversation("conv-id", {
wabaId: "waba-id", phoneNumberId: "phone-id",
contactPhone: "+919876543210",
metaPayloadJson: JSON.stringify({
messaging_product: "whatsapp", to: "+919876543210",
type: "text", text: { body: "Your order is confirmed!" }
})
});
// Resolve (triggers CSAT request + SLM summary generation automatically)
await client.resolveConversation("conv-id");
// Get SLM reply suggestions
const suggestions = await client.getReplySuggestions("conv-id", "when will my order arrive?");
// → { suggestions: ["Your order will arrive by...", "Let me check...", "..."] }
// Get conversation summary
const summary = await client.getConversationSummary("conv-id");
// Canned responses
const responses = await client.listCannedResponses();
const matches = await client.searchCannedResponses({ shortcode: "/refund" });
// CSAT report
const csat = await client.getCsatReport();
// → { avgScore: 4.3, responseCount: 120, distribution: { 1: 2, 2: 5, 3: 10, 4: 45, 5: 58 } }FAQ Bot (A9.5)
// Upload FAQ content (extract text from PDF first using pdf-parse or similar)
import fs from "fs";
const faqText = fs.readFileSync("product-faq.txt", "utf-8");
await client.uploadFaq("Product FAQ v2.1", faqText);
// → { status: "UPLOADED", chunkCount: 23 }
// Check what's uploaded
const info = await client.getFaqInfo();
// → { title, chunkCount, uploadedAt, updatedAt }
// Test the bot
const answer = await client.askFaq("What is the return policy?");
// → { answer: "Our return policy is 30 days...", confidence: 0.87 }
// Delete FAQ knowledge base
await client.deleteFaq();Analytics
// Agent performance (A12.3)
const agentStats = await client.getAgentPerformance();
// → [{ agentId, displayName, totalConversations, avgCsatScore, available }]
// Contact health (A12.5)
const health = await client.getContactHealth();
// → { reachabilityPct, optOutsLast7Days, weeklyGrowth: [...], activeAnomalies }
// CTWA ROAS attribution (B2.2)
const roas = await client.getCtwaRoas();
// Flow funnel analytics (A8.4)
const funnel = await client.getFlowAnalytics("flow-definition-uuid");
// → { totalSessions, completionRate, nodeStats: [{ nodeId, entries, dropOffRate }] }
// Anomaly events (A9.6)
const anomalies = await client.getActiveAnomalies();
await client.resolveAnomaly(anomalies[0].id);Developer / Sandbox (A15.1–2)
// Enable sandbox — no real WhatsApp messages sent
await client.toggleSandbox(true);
const status = await client.getSandboxStatus();
// → { sandboxEnabled: true }
// Webhook delivery log
const log = await client.getWebhookLog(100);
// → { total, sent, suppressed, queued, deliveryRate, entries: [...] }
// Replay a failed message
await client.replayWebhook("augstash-message-id");Error Handling
import AugStashClient, { AugStashError } from "augstash-sdk";
try {
await client.launchCampaign("invalid-id");
} catch (err) {
if (err instanceof AugStashError) {
console.error(`API error ${err.statusCode}: ${err.message}`);
// statusCode: 400 | 401 | 403 | 404 | 422 | 429 | 500
}
}Environment Variables
AUGSTASH_API_KEY=as_live_xxxxxxxxxxxx
AUGSTASH_BASE_URL=https://api.augstash.comconst client = new AugStashClient(
process.env.AUGSTASH_BASE_URL!,
process.env.AUGSTASH_API_KEY!
);License
MIT © AugmenTrait Pvt. Ltd.
