Usage
Create a client
import MagFa from "magfa-sdk";
const sms = new MagFa(
"username", // MagFa username
"password", // MagFa password
"domain", // MagFa domain
"3000xxxxxxx", // sender line (from)
);
Auth is sent as HTTP Basic: username/domain + password against
https://sms.magfa.com/api/http/sms/v2.
Balance
const result = await sms.balance();
if (result.status === 0) {
console.log(result.balance);
} else {
console.log(sms.error(result.status));
}
Send
recipients and messages are parallel arrays (same length). Sender is filled from the from you passed to the constructor.
const recipients = ["0912xxxxxxx", "0935xxxxxxx"];
const messages = ["Hello", "Hi there"];
const result = await sms.send(recipients, messages);
console.log(result.messages);
// each item includes status and a human-readable message on success/error
Inbox (incoming)
const result = await sms.messages();
if (result.status === 0) {
console.log(result.messages);
} else {
console.log(sms.error(result.status));
}
Delivery status
const result = await sms.status(messageId);
console.log(result.dlrs); // status text attached per DLR
Errors
On HTTP failures the SDK returns the API error payload when available (it does not always throw).