TextNow Unofficial API
TypeScript client for the TextNow messaging service.
Installation
npm install textnow-unofficial-api
Authentication
TextNow uses cookie-based authentication. You need to extract cookies from your browser:
- Log into TextNow in your browser
- Open DevTools → Application → Cookies
- Copy the values for:
connect.sid,_csrf,XSRF-TOKEN - Get your username from the URL (textnow.com/messaging shows it)
import { createTextNowClientWithCredentials } from 'textnow-unofficial-api';
const cookies = 'connect.sid=xxx; _csrf=xxx; XSRF-TOKEN=xxx';
const client = createTextNowClientWithCredentials('your-username', cookies);
Important: The XSRF-TOKEN cookie value is used for the X-CSRF-Token header (not _csrf).
Usage
Send SMS
await client.send('+15551234567', 'Hello from TextNow!');
Send Media
// From file path
await client.sendImage('+15551234567', '/path/to/image.jpg');
// From buffer
await client.sendImageBuffer('+15551234567', buffer, 'photo.jpg', 'image/jpeg');
// Audio
await client.sendAudio('+15551234567', '/path/to/audio.mp3');
Get Messages
// All recent messages
const { messages } = await client.getMessages({ limit: 50 });
// From specific contact
const msgs = await client.getMessagesFrom('+15551234567');
Get Conversations
const { conversations } = await client.getConversations();
Credential Storage
Credentials are stored in ~/.textnow/credentials.json with restricted permissions.
import {
loadCredentials,
hasStoredCredentials,
clearCredentials
} from 'textnow-unofficial-api';
// Check if credentials exist
if (hasStoredCredentials()) {
const creds = loadCredentials();
console.log(`Logged in as: ${creds.username}`);
}
// Clear stored credentials
clearCredentials();
API Reference
TextNowAPI
send(to: string, message: string)- Send SMSsendMedia(options: SendMediaRequest)- Send media attachmentsendImage(to: string, filePath: string)- Send image filesendImageBuffer(to: string, buffer: Buffer, filename?, contentType?)- Send image from buffersendAudio(to: string, filePath: string)- Send audio filegetMessages(params?)- Get messagesgetMessagesFrom(contactNumber: string, limit?)- Get messages from contactgetConversations(params?)- Get conversations listgetUploadUrl(mediaType?)- Get presigned upload URL
TextNowAuth
setCredentials(username, cookies, save?)- Set auth credentialsgetAuthHeaders()- Get headers for API requestsisAuthenticated()- Check auth statuslogout(clearStored?)- Clear auth state
License
MIT