ssms
v1.0.2
Published
Self SMS gateway designed for droid send to be using your phone as SMS gateway
Downloads
6
Maintainers
Readme
SSMS API Node.js Implementation
This module provides functions for interacting with the DroidSend API to send, retrieve, and resend SMS and MMS messages. It includes functionality for detailed message management, including sending to individual numbers, groups, and contacts.
Installation
First, install the required dependencies:
npm install ssms
Configuration
Before you start, set up the necessary configuration values:
const API_KEY = "";
Functions
sendSingleMessage
Send a single message to a mobile number.
Parameters:
number
: The mobile number to which the message will be sent.message
: The message text.device
: (Optional) The ID of the device to be used for sending the message.schedule
: (Optional) The timestamp for scheduling the message.isMMS
: (Optional) Set totrue
for sending an MMS message.attachments
: (Optional) Comma-separated list of image URLs to attach (for MMS).prioritize
: (Optional) Set totrue
to prioritize the message.
Example:
const deviceID = 17373
async function start() {
await sendSingleMessage(API_KEY, "12837373", "Test message", 1,deviceID);
}
start();
sendMessages
Send bulk messages to multiple recipients.
Parameters:
messages
: An array containing objects withnumber
andmessage
fields.option
: Specifies how to use devices/SIMs. Use constants:USE_SPECIFIED
,USE_ALL_DEVICES
, orUSE_ALL_SIMS
.devices
: (Optional) An array of device IDs to be used for sending messages.schedule
: (Optional) The timestamp for scheduling the messages.useRandomDevice
: (Optional) Set totrue
to send messages using only one random device from selected devices.
Example:
const messages = [
{ number: "+11234567890", message: "Test message 1" },
{ number: "+11234567891", message: "Test message 2" }
];
try {
const result = await sendMessages(messages);
console.log(result);
} catch (err) {
console.error(err);
}
sendMessageToContactsList
Send a message to all contacts in a specified list.
Parameters:
listID
: The ID of the contacts list.message
: The message text.option
: Specifies how to use devices/SIMs.devices
: (Optional) An array of device IDs to be used.schedule
: (Optional) The timestamp for scheduling the message.isMMS
: (Optional) Set totrue
for sending an MMS message.attachments
: (Optional) Comma-separated list of image URLs to attach (for MMS).
Example:
try {
const result = await sendMessageToContactsList(1, "This is a test message to a list.");
console.log(result);
} catch (err) {
console.error(err);
}
getMessageByID
Retrieve the details of a message using its ID.
Parameters:
id
: The ID of the message.
Example:
try {
const message = await getMessageByID(123);
console.log(message);
} catch (err) {
console.error(err);
}
getMessagesByGroupID
Retrieve messages by their group ID.
Parameters:
groupID
: The group ID of the messages.
Example:
try {
const messages = await getMessagesByGroupID("group123");
console.log(messages);
} catch (err) {
console.error(err);
}
getDevices
Retrieve all enabled devices.
Example:
try {
const devices = await getDevices();
console.log(devices);
} catch (err) {
console.error(err);
}
sendUssdRequest
Send a USSD request using a specified device and SIM slot.
Parameters:
request
: The USSD request (e.g.,*150#
).device
: The ID of the device.simSlot
: (Optional) The SIM slot to use (0 for the first SIM, 1 for the second SIM).
Example:
try {
const ussd = await sendUssdRequest("*150#", 1, 0);
console.log(ussd);
} catch (err) {
console.error(err);
}
getUssdRequestByID
Retrieve details of a USSD request using its ID.
Parameters:
id
: The ID of the USSD request.
Example:
try {
const ussd = await getUssdRequestByID(123);
console.log(ussd);
} catch (err) {
console.error(err);
}
Usage
Ensure that you have correctly configured your SERVER
and API_KEY
constants before using any of the functions.
Example: Sending a Single Message
async function sendSingleMessage(number, message, device = 0, schedule = null, isMMS = false, attachments = null, prioritize = false) {
const url = `${SERVER}/services/send.php`;
const postData = {
number,
message,
schedule,
key: API_KEY,
devices: device,
type: isMMS ? "mms" : "sms",
attachments,
prioritize: prioritize ? 1 : 0,
};
try {
const response = await axios.post(url, postData);
return response.data.messages[0];
} catch (err) {
throw new Error(err.response ? err.response.data.error.message : err.message);
}
}
try {
const msg = await sendSingleMessage("+11234567890", "This is a test message.");
console.log("Message sent:", msg);
} catch (err) {
console.error("Failed to send message:", err.message);
}
License
This project is licensed under the MIT License.