Skip to content

Commit d139dda

Browse files
committed
Fix console S/MMS compose
1 parent 71d5cd9 commit d139dda

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

bin/txms

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function parseArgs(argv) {
4242
break;
4343
case '--getendpoint':
4444
args.kind = 'getendpoint';
45-
args.value = value; // Network type for getEndpoint
45+
args.value = value || 1; // Network type for getEndpoint
4646
break;
4747
case '--sms':
4848
args.kind = 'sms';
@@ -89,7 +89,7 @@ function parseArgs(argv) {
8989
break;
9090
case '-g':
9191
args.kind = 'getendpoint';
92-
args.value = value;
92+
args.value = value || 1;
9393
break;
9494
case '-s':
9595
args.kind = 'sms';
@@ -239,13 +239,11 @@ async function run(kind, value, output, countryCodes, phoneNumbers, download, fi
239239
process.stdout.write(endpointString + newline);
240240
process.exit(0);
241241
} else if (kind === 'sms') {
242-
const message = txms.encode(value);
243-
const sms = txms.sms(phoneNumbers ? phoneNumbers.split(',') : true, message);
242+
const sms = txms.sms(phoneNumbers ? phoneNumbers.split(',') : true, value);
244243
process.stdout.write(sms + newline);
245244
process.exit(0);
246245
} else if (kind === 'mms') {
247-
const message = txms.encode(value);
248-
const mms = txms.mms(phoneNumbers ? phoneNumbers.split(',') : true, message);
246+
const mms = txms.mms(phoneNumbers ? phoneNumbers.split(',') : true, value);
249247
process.stdout.write(mms + newline);
250248
process.exit(0);
251249
} else {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "txms.js",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "Transaction messaging service protocol",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -46,7 +46,7 @@
4646
"author": "@bchainhub",
4747
"license": "CORE",
4848
"devDependencies": {
49-
"@types/node": "^22.5.1",
49+
"@types/node": "^22.5.2",
5050
"@typescript-eslint/eslint-plugin": "^8.3.0",
5151
"@typescript-eslint/parser": "^8.3.0",
5252
"eslint": "^9.9.1",

test/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@ describe('CLI Tests', () => {
316316
assert.strictEqual(parseInt(result.stdout.toString(), 10), samples.valid[0].length);
317317
});
318318

319+
test('Should compose SMS link with piping', () => {
320+
const hexValue = samples.valid[0].hex;
321+
const echo = spawnSync('echo', [hexValue]);
322+
const result = spawnSync('node', [txmsPath, '--encode', '-s'], {
323+
input: echo.stdout
324+
});
325+
assert.strictEqual(result.status, 0);
326+
assert.match(result.stdout.toString(), /^sms:\+12019715152\?body=/);
327+
});
328+
319329
test('Should print help text', () => {
320330
const result = spawnSync('node', [txmsPath, '--help']);
321331
assert.strictEqual(result.status, 0);

0 commit comments

Comments
 (0)