Skip to content

Commit 2e24f34

Browse files
jzongkerclaude
andcommitted
texting: add Nalo Solutions (Ghana) SMS provider
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 23164de commit 2e24f34

6 files changed

Lines changed: 115 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@churchapps/texting": minor
3+
---
4+
5+
Add Nalo Solutions (Ghana) SMS provider

‎texting/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ export {
1717
export { TextInChurchProvider } from "./providers/textInChurch/index.js";
1818
export { ClearstreamProvider } from "./providers/clearstream/index.js";
1919
export { MutualMinistryProvider } from "./providers/mutualMinistry/index.js";
20+
export { NaloProvider } from "./providers/nalo/index.js";

‎texting/src/providers/index.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TextInChurchProvider } from "./textInChurch/index.js";
33
import { ClearstreamProvider } from "./clearstream/index.js";
44
import { MutualMinistryProvider } from "./mutualMinistry/index.js";
55
import { MinistryStuffProvider } from "./ministryStuff/index.js";
6+
import { NaloProvider } from "./nalo/index.js";
67

78
const providers = new Map<string, ITextingProvider>();
89

@@ -11,6 +12,7 @@ providers.set("textinchurch", new TextInChurchProvider());
1112
providers.set("clearstream", new ClearstreamProvider());
1213
providers.set("mutualministry", new MutualMinistryProvider());
1314
providers.set("ministrystuff", new MinistryStuffProvider());
15+
providers.set("nalo", new NaloProvider());
1416

1517
const providerMeta: Record<string, Omit<ProviderInfo, "id">> = {
1618
clearstream: {
@@ -40,6 +42,13 @@ const providerMeta: Record<string, Omit<ProviderInfo, "id">> = {
4042
requiresSecret: false,
4143
settingsUrl: "https://ministrystuff.org",
4244
helpText: "Flat-rate monthly texting credits. No API key needed - your MinistryStuff subscription is linked to your church automatically."
45+
},
46+
nalo: {
47+
name: "Nalo Solutions",
48+
requiresApiKey: true,
49+
requiresSecret: false,
50+
settingsUrl: "https://www.nalosolutions.com",
51+
helpText: "Ghana SMS gateway. Enter the auth key from your Nalo account and a sender ID that Nalo has approved for your account."
4352
}
4453
};
4554

@@ -74,3 +83,4 @@ export { TextInChurchProvider } from "./textInChurch/index.js";
7483
export { ClearstreamProvider } from "./clearstream/index.js";
7584
export { MutualMinistryProvider } from "./mutualMinistry/index.js";
7685
export { MinistryStuffProvider } from "./ministryStuff/index.js";
86+
export { NaloProvider } from "./nalo/index.js";
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import axios from "axios";
2+
import { ITextingProvider, TextingProviderConfig, TextingSendResult, ProviderCapabilities, SubscriberResult, ListsResult } from "../../interfaces.js";
3+
4+
const DEFAULT_BASE_URL = "https://sms.nalosolutions.com/smsbackend";
5+
const SUCCESS = "1701";
6+
7+
export class NaloProvider implements ITextingProvider {
8+
readonly name = "Nalo Solutions";
9+
readonly capabilities: ProviderCapabilities = { addSubscriber: false, getLists: false };
10+
11+
// ponytail: local Ghana numbers (0XXXXXXXXX) become 233XXXXXXXXX; other formats pass through as digits.
12+
static normalizeNumber(phone: string) {
13+
const digits = phone.replace(/\D/g, "");
14+
return /^0\d{9}$/.test(digits) ? "233" + digits.substring(1) : digits;
15+
}
16+
17+
private async send(config: TextingProviderConfig, recipients: string[], message: string): Promise<TextingSendResult> {
18+
try {
19+
const response = await axios.post(
20+
`${config.baseUrl || DEFAULT_BASE_URL}/Resl_Nalo/send-message/`,
21+
{ key: config.apiKey, msisdn: recipients.map(NaloProvider.normalizeNumber).join(","), message, sender_id: config.fromNumber || "" },
22+
{ headers: { "Content-Type": "application/json" } }
23+
);
24+
if (String(response.data?.status) === SUCCESS) return { success: true, providerMessageId: response.data?.job_id };
25+
return { success: false, error: this.errorText(response.data) };
26+
} catch (error: any) {
27+
return { success: false, error: this.errorText(error.response?.data) || error.message };
28+
}
29+
}
30+
31+
private errorText(data: any): string {
32+
if (!data) return "";
33+
if (data.code) return `${data.code}: ${data.message || ""}`.trim();
34+
return typeof data === "string" ? data : JSON.stringify(data);
35+
}
36+
37+
sendMessage(config: TextingProviderConfig, to: string, message: string): Promise<TextingSendResult> {
38+
return this.send(config, [to], message);
39+
}
40+
41+
async sendBulk(config: TextingProviderConfig, recipients: string[], message: string): Promise<TextingSendResult[]> {
42+
const result = await this.send(config, recipients, message);
43+
return recipients.map(() => ({ ...result }));
44+
}
45+
46+
// Nalo validates fields before auth and has no account endpoint, so a key can't be checked without sending.
47+
async validateCredentials(config: TextingProviderConfig): Promise<boolean> {
48+
return !!config.apiKey && !!config.fromNumber;
49+
}
50+
51+
async addSubscriber(): Promise<SubscriberResult> {
52+
return { success: false, error: "Nalo Solutions does not support subscriber management" };
53+
}
54+
55+
async getLists(): Promise<ListsResult> {
56+
return { success: false, error: "Nalo Solutions does not support lists" };
57+
}
58+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { NaloProvider } from "./NaloProvider.js";

‎texting/tests/naloProvider.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { test } from "node:test";
2+
import assert from "node:assert/strict";
3+
import axios from "axios";
4+
5+
import { NaloProvider } from "../src/providers/nalo/NaloProvider.js";
6+
import { getProvider } from "../src/providers/index.js";
7+
8+
const config = { churchId: "church1", apiKey: "auth-key", apiSecret: "", fromNumber: "MyChurch" };
9+
const provider = new NaloProvider();
10+
11+
test("registered as nalo", () => {
12+
assert.ok(getProvider("Nalo") instanceof NaloProvider);
13+
});
14+
15+
test("normalizeNumber converts local Ghana numbers and strips formatting", () => {
16+
assert.equal(NaloProvider.normalizeNumber("024 407 1872"), "233244071872");
17+
assert.equal(NaloProvider.normalizeNumber("+233 24 407 1872"), "233244071872");
18+
assert.equal(NaloProvider.normalizeNumber("+1 (555) 123-4567"), "15551234567");
19+
});
20+
21+
test("sendBulk posts one request with comma-joined msisdn and maps 1701 success", async (t) => {
22+
const post = t.mock.method(axios, "post", async () => ({ data: { status: "1701", job_id: "api.1", msisdn: "233244071872" } }) as any);
23+
const results = await provider.sendBulk(config, ["0244071872", "+233501371674"], "hi");
24+
assert.deepEqual(results, [{ success: true, providerMessageId: "api.1" }, { success: true, providerMessageId: "api.1" }]);
25+
assert.equal(post.mock.callCount(), 1);
26+
const [url, body] = post.mock.calls[0].arguments as any[];
27+
assert.equal(url, "https://sms.nalosolutions.com/smsbackend/Resl_Nalo/send-message/");
28+
assert.deepEqual(body, { key: "auth-key", msisdn: "233244071872,233501371674", message: "hi", sender_id: "MyChurch" });
29+
});
30+
31+
test("sendMessage maps a 412 error code response", async (t) => {
32+
t.mock.method(axios, "post", async () => { throw { response: { data: { code: 1713, message: "Invalid auth key" } }, message: "412" }; });
33+
const result = await provider.sendMessage(config, "0244071872", "hi");
34+
assert.deepEqual(result, { success: false, error: "1713: Invalid auth key" });
35+
});
36+
37+
test("validateCredentials requires key and sender id", async () => {
38+
assert.equal(await provider.validateCredentials(config), true);
39+
assert.equal(await provider.validateCredentials({ ...config, fromNumber: "" }), false);
40+
});

0 commit comments

Comments
 (0)