
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
witty-flow-sms
Advanced tools
A modern Node.js SDK for the Witty Flow SMS API with full TypeScript support. Send SMS messages, flash messages, check delivery status, and manage your account balance with complete type safety and IntelliSense.
npm install witty-flow-sms
yarn add witty-flow-sms
TypeScript users: No additional
@types
package needed! Type definitions are included out of the box.
const { WFClient } = require('witty-flow-sms');
// Initialize the client
const smsClient = new WFClient('your_app_id', 'your_app_secret');
// Send a message
async function sendMessage() {
try {
const result = await smsClient.sendSms('MyApp', '0244123456', 'Hello World!');
console.log('Message sent:', result);
} catch (error) {
console.error('Error:', error.message);
}
}
sendMessage();
import { WFClient, WittyFlowResponse, MessageData } from 'witty-flow-sms';
// Initialize with type safety
const smsClient: WFClient = new WFClient('your_app_id', 'your_app_secret');
// Send a message with full typing
async function sendMessage(): Promise<void> {
try {
// TypeScript knows the exact return type
const result: WittyFlowResponse<MessageData> = await smsClient.sendSms(
'MyApp',
'0244123456',
'Hello TypeScript!'
);
// Full autocomplete and type checking
console.log(`Message sent: ${result.data.message_id}`);
console.log(`Cost: ${result.data.cost}`);
console.log(`Status: ${result.data.status}`);
console.log(`Segments: ${result.data.message_segments}`);
} catch (error: unknown) {
if (error instanceof Error) {
console.error('Error:', error.message);
}
}
}
sendMessage();
Key TypeScript Benefits:
The package includes comprehensive example files that demonstrate all features:
# Run the JavaScript demo
npm run demo
# Or run directly
node example.js
# Run the TypeScript demo (requires TypeScript)
npm run demo:ts
# Or install TypeScript and run directly
npm install -g typescript ts-node
npx ts-node example.ts
Note: Remember to replace 'your_app_id'
and 'your_app_secret'
in the example files with your actual Witty Flow credentials before running the demos.
Install the package (types included automatically):
npm install witty-flow-sms
Import with full typing:
import { WFClient, WittyFlowResponse, MessageData } from 'witty-flow-sms';
Get instant IntelliSense:
const client = new WFClient('app_id', 'secret');
// Your editor now provides autocomplete and type checking!
💡 TypeScript Users: All methods below include full type definitions. Your editor will provide autocomplete, parameter hints, and return type information automatically.
JavaScript:
const client = new WFClient(appId, appSecret);
TypeScript:
const client: WFClient = new WFClient(appId, appSecret);
Parameters:
appId
(string, required) - Your Witty Flow application IDappSecret
(string, required) - Your Witty Flow application secretThrows: Error if appId
or appSecret
is missing
sendSms(from, to, message)
Send a regular SMS message.
Parameters:
from
(string) - Sender ID (maximum 14 characters)to
(string) - Recipient phone number in format 0244XXXXXX
message
(string) - Message content (maximum 180 characters)Returns: Promise - API response with message details
JavaScript Example:
const response = await smsClient.sendSms('MyCompany', '0244123456', 'Your order is ready!');
console.log(response);
TypeScript Example:
import { WittyFlowResponse, MessageData } from 'witty-flow-sms';
const response: WittyFlowResponse<MessageData> = await smsClient.sendSms(
'MyCompany',
'0244123456',
'Your order is ready!'
);
// Full type safety and autocomplete
console.log(`Message ID: ${response.data.message_id}`);
console.log(`Cost: ${response.data.cost}`);
Success Response:
{
"status": "success",
"code": 2020,
"message": "Accepted for delivery",
"data": {
"status": "accepted",
"message_id": "ebb04f7f-147f-4d17-877b-8dd8af4ed2fe",
"message": "Your order is ready!",
"date_created": "2020-08-24T00:17:09.000000Z",
"direction": "MT",
"from": "MyCompany",
"to": "233244123456",
"type": "plain",
"message_segments": 1,
"cost": "0.03",
"service_rate": "0.030000",
"callback_url": null
}
}
sendFlashMessage(from, to, message)
Send a flash SMS message (displays immediately on recipient's screen).
Parameters:
from
(string) - Sender ID (maximum 14 characters)to
(string) - Recipient phone number in format 0244XXXXXX
message
(string) - Message content (maximum 180 characters)Returns: Promise - API response with message details
Example:
const response = await smsClient.sendFlashMessage('Alert', '0244123456', 'Emergency: Please check your email');
console.log(response);
getSmsStatus(messageId)
Check the delivery status of a sent message.
Parameters:
messageId
(string) - Message ID returned from sendSms()
or sendFlashMessage()
Returns: Promise - Message status information
Example:
const status = await smsClient.getSmsStatus('ebb04f7f-147f-4d17-877b-8dd8af4ed2fe');
console.log(status);
Success Response:
{
"status": "success",
"code": 2000,
"message": "Message retrieved",
"data": {
"message_id": "ebb04f7f-147f-4d17-877b-8dd8af4ed2fe",
"status": "delivered",
"message": "Your order is ready!",
"date": "2020-08-23T23:54:04.000000Z",
"readable_date": "Sun August 23, 2020 11:54:04 PM",
"direction": "MT",
"type": "1",
"sender": "MyCompany",
"recipient": "233244123456",
"message_segments": 1,
"cost": "0.03",
"rate": "0.030000",
"billing": "charged"
}
}
getAccountBalance()
Get your current account balance.
Returns: Promise - Account balance information
Example:
const balance = await smsClient.getAccountBalance();
console.log(`Balance: ${balance.data.balance} ${balance.data.currency}`);
Success Response:
{
"status": "success",
"code": 2000,
"message": "Balance Retrieved",
"data": {
"balance": "19.19",
"currency": "GHS"
}
}
const { WFClient } = require('witty-flow-sms');
async function smsExample() {
// Initialize client
const client = new WFClient('your_app_id', 'your_app_secret');
try {
// Check account balance
const balance = await client.getAccountBalance();
console.log(`Account Balance: ${balance.data.balance} ${balance.data.currency}`);
// Send a message
const messageResponse = await client.sendSms(
'MyApp',
'0244123456',
'Hello! This is a test message.'
);
console.log('Message sent successfully:', messageResponse.data.message_id);
// Check message status
const status = await client.getSmsStatus(messageResponse.data.message_id);
console.log('Message status:', status.data.status);
} catch (error) {
console.error('SMS Error:', error.message);
}
}
smsExample();
The SDK provides detailed error messages for different scenarios:
try {
await smsClient.sendSms('', '0244123456', 'Test');
} catch (error) {
if (error.message.includes('API Error')) {
// Handle API errors (4xx, 5xx responses)
console.log('API Error:', error.message);
} else if (error.message.includes('Network Error')) {
// Handle network connectivity issues
console.log('Network Error:', error.message);
} else {
// Handle other errors (validation, etc.)
console.log('Error:', error.message);
}
}
Important: Phone numbers must be in Ghana format starting with 0
:
0244123456
, 0501234567
, 0201234567
, 0262345678
+233244123456
, 233244123456
, 244123456
, 0123456789
Validation Rules:
0
024XXXXXXX
, 025XXXXXXX
, 026XXXXXXX
, 027XXXXXXX
, 050XXXXXXX
The SDK automatically converts 0244123456
to 233244123456
for the API and validates the format before sending.
This package is built with first-class TypeScript support. No additional setup required!
import {
// Main Classes
WFClient, // SMS client class
// Response Types
WittyFlowResponse<T>, // Generic API response wrapper
// Data Interfaces
MessageData, // SMS send response data
MessageStatusData, // Message status response data
BalanceData, // Account balance data
} from 'witty-flow-sms';
import { WFClient } from 'witty-flow-sms';
// Type-safe client initialization
const client: WFClient = new WFClient('your_app_id', 'your_app_secret');
import { WFClient, WittyFlowResponse, MessageData } from 'witty-flow-sms';
async function sendTypedSMS(): Promise<string> {
const client = new WFClient('app_id', 'secret');
// TypeScript knows the exact return type
const response: WittyFlowResponse<MessageData> = await client.sendSms(
'MyApp',
'0244123456',
'Hello from TypeScript!'
);
// Autocomplete works for all properties
return response.data.message_id; // Type: string
}
import { WFClient, MessageData, BalanceData } from 'witty-flow-sms';
class SMSService {
private client: WFClient;
constructor(appId: string, appSecret: string) {
this.client = new WFClient(appId, appSecret);
}
async sendWithBalanceCheck(
from: string,
to: string,
message: string
): Promise<{ sent: boolean; messageId?: string; balance: string }> {
try {
// Check balance first - TypeScript knows the return type
const balanceResponse = await this.client.getAccountBalance();
const balance: string = balanceResponse.data.balance;
if (parseFloat(balance) < 0.05) {
return { sent: false, balance };
}
// Send message - TypeScript provides full autocomplete
const smsResponse = await this.client.sendSms(from, to, message);
return {
sent: true,
messageId: smsResponse.data.message_id,
balance: balance
};
} catch (error: unknown) {
if (error instanceof Error) {
throw new Error(`SMS service error: ${error.message}`);
}
throw error;
}
}
}
// All response data follows this structure
interface WittyFlowResponse<T> {
status: 'success';
code: number;
message: string;
data: T;
}
// SMS send response data
interface MessageData {
status: string;
message_id: string;
message: string;
date_created: string;
direction: string;
from: string;
to: string;
type: string;
message_segments: number;
cost: string;
service_rate: string;
callback_url: string | null;
}
// Message status response data
interface MessageStatusData {
message_id: string;
status: string;
message: string;
date: string;
readable_date: string;
direction: string;
type: string;
sender: string;
recipient: string;
message_segments: number;
cost: string;
rate: string;
billing: string;
}
// Account balance response data
interface BalanceData {
balance: string;
currency: string;
}
Add to your tsconfig.json
for optimal experience:
{
"compilerOptions": {
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node"
}
}
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ for the Ghanaian developer community
FAQs
Witty Flow SMS API Wrapper For Node.js
The npm package witty-flow-sms receives a total of 10 weekly downloads. As such, witty-flow-sms popularity was classified as not popular.
We found that witty-flow-sms demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.