
Research
/Security News
Popular Go Decimal Library Targeted by Long-Running Typosquat with DNS Backdoor
A long-running Go typosquat impersonated the popular shopspring/decimal library and used DNS TXT records to execute commands.
textmagic-client
Advanced tools
This library provides you with an easy way of sending SMS and receiving replies by integrating the TextMagic SMS Gateway into your JavaScript application.
TextMagic's application programming interface (API) provides the communication link between your application and TextMagic's SMS Gateway, allowing you to send and receive text messages and to check the delivery status of text messages you've already sent.
npm install textmagic-client --save
yarn add textmagic-client
This SDK uses Babel to transpile modern ES6+ code to CommonJS for maximum compatibility.
The SDK source code is written in ES6+ (located in src/) and is automatically transpiled to ES5/CommonJS (in dist/) during installation:
npm install # Automatically runs: npm run build
If you need to rebuild the SDK manually:
npm run build
This will transpile all files from src/ to dist/ using Babel.
const TextMagicClient = require('textmagic-client');
// Get your credentials from: https://app.textmagic.com/settings/api
const defaultClient = TextMagicClient.ApiClient.instance;
const BasicAuth = defaultClient.authentications['BasicAuth'];
BasicAuth.username = 'YOUR_USERNAME';
BasicAuth.password = 'YOUR_API_KEY';
const api = new TextMagicClient.TextMagicApi();
// Test connection
api.ping()
.then(data => {
console.log('Ping successful:', data.ping);
})
.catch(error => {
console.error('API Error:', error);
});
const TextMagicClient = require('textmagic-client');
async function main() {
const defaultClient = TextMagicClient.ApiClient.instance;
const BasicAuth = defaultClient.authentications['BasicAuth'];
BasicAuth.username = 'YOUR_USERNAME';
BasicAuth.password = 'YOUR_API_KEY';
const api = new TextMagicClient.TextMagicApi();
try {
// Test connection
const pingResult = await api.ping();
console.log('Ping successful:', pingResult.ping);
} catch (error) {
console.error('API Error:', error);
}
}
main();
const TextMagicClient = require('textmagic-client');
async function sendMessage() {
const defaultClient = TextMagicClient.ApiClient.instance;
const BasicAuth = defaultClient.authentications['BasicAuth'];
BasicAuth.username = 'YOUR_USERNAME';
BasicAuth.password = 'YOUR_API_KEY';
const api = new TextMagicClient.TextMagicApi();
const sendMessageRequest = new TextMagicClient.SendMessageRequest();
sendMessageRequest.text = 'Hello from TextMagic Node.js SDK!';
sendMessageRequest.phones = '+19993322111,+19993322110';
try {
const result = await api.sendMessage(sendMessageRequest);
console.log('Message sent! Session ID:', result.id);
} catch (error) {
console.error('Failed to send message:', error);
}
}
sendMessage();
const TextMagicClient = require('textmagic-client');
async function getMessages() {
const defaultClient = TextMagicClient.ApiClient.instance;
const BasicAuth = defaultClient.authentications['BasicAuth'];
BasicAuth.username = 'YOUR_USERNAME';
BasicAuth.password = 'YOUR_API_KEY';
const api = new TextMagicClient.TextMagicApi();
try {
const result = await api.getAllOutboundMessages(1, 10);
result.resources.forEach(message => {
console.log('Message ID:', message.id);
console.log('Text:', message.text);
console.log('Status:', message.status);
console.log('---');
});
} catch (error) {
console.error('Error:', error);
}
}
getMessages();
const TextMagicClient = require('textmagic-client');
const fs = require('fs');
async function uploadAvatar() {
const defaultClient = TextMagicClient.ApiClient.instance;
const BasicAuth = defaultClient.authentications['BasicAuth'];
BasicAuth.username = 'YOUR_USERNAME';
BasicAuth.password = 'YOUR_API_KEY';
const api = new TextMagicClient.TextMagicApi();
try {
const fileStream = fs.createReadStream('avatar.jpg');
const result = await api.uploadListAvatar(fileStream, 3223); // 3223 is sample list ID
console.log('Avatar uploaded successfully!');
} catch (error) {
console.error('Upload failed:', error);
}
}
uploadAvatar();
The SDK uses Promises and can throw errors that should be properly handled:
const TextMagicClient = require('textmagic-client');
async function handleErrors() {
const defaultClient = TextMagicClient.ApiClient.instance;
const BasicAuth = defaultClient.authentications['BasicAuth'];
BasicAuth.username = 'YOUR_USERNAME';
BasicAuth.password = 'YOUR_API_KEY';
const api = new TextMagicClient.TextMagicApi();
try {
const result = await api.sendMessage({
text: 'Test message',
phones: '+1234567890'
});
console.log('Success:', result);
} catch (error) {
// Handle different types of errors
if (error.response) {
// API returned an error response
console.error('API Error:', error.response.status);
console.error('Error details:', error.response.body);
} else if (error.request) {
// Request was made but no response received
console.error('Network Error:', error.message);
} else {
// Something else went wrong
console.error('Error:', error.message);
}
}
}
handleErrors();
For complete API documentation, including all available methods, parameters, and response formats, please visit:
The SDK provides access to all TextMagic API endpoints through the TextMagicApi class. Some commonly used methods include:
Messaging:
sendMessage(request) - Send SMS messagesgetAllOutboundMessages(page, limit) - Get sent messagesgetAllInboundMessages(page, limit) - Get received messagesdeleteMessage(id) - Delete a messageContacts:
createContact(request) - Create a new contactgetContact(id) - Get contact detailsupdateContact(id, request) - Update contact informationdeleteContact(id) - Delete a contactgetAllContacts(page, limit) - Get all contactsLists:
createList(request) - Create a contact listgetList(id) - Get list detailsgetAllLists(page, limit) - Get all listsassignContactsToList(request) - Add contacts to a listAccount:
ping() - Test API connectiongetUser() - Get account informationgetUserBalance() - Get account balanceFor a complete list of available methods, please refer to the generated SDK documentation in the docs/ directory.
v2.x:
"node": ">=6.0.0"
v3.x:
"node": ">=18.0.0"
Action Required: Upgrade your Node.js version to 18.0.0 or later.
# Check your Node.js version
node -v
# Should output: v18.x.x or higher
v2.x:
"superagent": "^3.5.2"
v3.x:
"superagent": "^10.2.2",
"@babel/cli": "^7.24.0"
Note:
ā Module structure - No changes required:
const TextMagicClient = require('textmagic-client');
const api = new TextMagicClient.TextMagicApi();
ā Authentication - Configuration remains the same:
const BasicAuth = defaultClient.authentications['BasicAuth'];
BasicAuth.username = 'YOUR_USERNAME';
BasicAuth.password = 'YOUR_API_KEY';
ā API Methods - All methods remain the same:
api.sendMessage(request);
api.getAllOutboundMessages(page, limit);
api.getContact(id);
// ... all other methods unchanged
Upgrade Node.js to 18.0.0+
# Using nvm (recommended)
nvm install 18
nvm use 18
# Verify
node -v
Update Package Dependencies
# Update to latest version
npm install textmagic-client@latest --save
# Or update all dependencies
npm update
Update Your Code to Use async/await (Recommended)
Before (v2.x):
api.ping().then(function(data) {
console.log(data.ping);
}).catch(function(err) {
console.error(err);
});
After (v3.x):
try {
const data = await api.ping();
console.log(data.ping);
} catch (error) {
console.error(error);
}
Test Your Application
# Run your tests
npm test
# Or test manually
node your_script.js
| Feature | v2.x | v3.x | Compatible? |
|---|---|---|---|
| Node.js 6-16 | ā | ā | ā No |
| Node.js 18+ | ā | ā | ā Yes |
| API Methods | Same | Same | ā Yes |
| Models | Same | Same | ā Yes |
| Authentication | Same | Same | ā Yes |
| Promises | ā | ā | ā Yes |
| async/await | ā | ā | ā Yes |
The library is available as open source under the terms of the MIT License.
FAQs
JavaScript wrapper library for TextMagic API
The npm package textmagic-client receives a total of 2,535 weekly downloads. As such, textmagic-client popularity was classified as popular.
We found that textmagic-client 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.

Research
/Security News
A long-running Go typosquat impersonated the popular shopspring/decimal library and used DNS TXT records to execute commands.

Research
Active npm supply chain attack compromises @antv packages in a fast-moving malicious publish wave tied to Mini Shai-Hulud.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.