From 4e59bd71b3ba698aabe214645ec5472e23943374 Mon Sep 17 00:00:00 2001 From: Rastislav Date: Thu, 22 Aug 2024 20:05:23 +0200 Subject: [PATCH 1/2] Added .txms.txt extension --- README.md | 4 ++-- package.json | 2 +- stream.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 97d75dd..15caa07 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Utilize this server to develop your unique TxMS webhook, securely deployed with This server provides the following services: - Catch the SMS and forward it to the blockchain provider. -- Catch the MMS attachments `.txms`, fetch them and forward it to the blockchain provider. +- Catch the MMS attachments `.txms.txt`, fetch them and forward it to the blockchain provider. - Accepting TxMS Binary-to-text transcription and pure hexadecimal data. - `0x` prefix is optional for hexadecimal data. @@ -167,7 +167,7 @@ To do so, you can modify the code and create database of numbers, which paid for The server can handle both SMS and MMS messages. To enable MMS, set the `MMS` environment variable to `true`. -MMS messages can contain `.txms` attachments, which are fetched and forwarded to the blockchain provider. +MMS messages can contain `.txms.txt` attachments, which are fetched and forwarded to the blockchain provider. Pricing for SMS and MMS services may vary depending on the provider. Please check with your provider for more information. diff --git a/package.json b/package.json index 86ce7f6..629815b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "txms-server", - "version": "1.2.5", + "version": "1.2.6", "description": "TxMS server", "main": "stream.js", "engines": { diff --git a/stream.js b/stream.js index 08fce1b..39514d0 100644 --- a/stream.js +++ b/stream.js @@ -118,7 +118,7 @@ async function processSMS(messageBody) { async function processMMSMessages(mediaUrls) { for (const url of mediaUrls) { - if (url.endsWith('.txms')) { + if (url.endsWith('.txms.txt')) { try { const response = await fetch(url); if (!response.ok) throw new Error(`Failed to fetch file from ${url}`); From 995c6e7efa21ef4851a6d484ef651fd2e0ff2147 Mon Sep 17 00:00:00 2001 From: Rastislav Date: Thu, 22 Aug 2024 20:30:11 +0200 Subject: [PATCH 2/2] Excluded extension --- README.md | 4 ++-- stream.js | 26 ++++++++++++-------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 15caa07..f00db4d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Utilize this server to develop your unique TxMS webhook, securely deployed with This server provides the following services: - Catch the SMS and forward it to the blockchain provider. -- Catch the MMS attachments `.txms.txt`, fetch them and forward it to the blockchain provider. +- Catch the MMS attachments, fetch them and forward it to the blockchain provider. - Accepting TxMS Binary-to-text transcription and pure hexadecimal data. - `0x` prefix is optional for hexadecimal data. @@ -167,7 +167,7 @@ To do so, you can modify the code and create database of numbers, which paid for The server can handle both SMS and MMS messages. To enable MMS, set the `MMS` environment variable to `true`. -MMS messages can contain `.txms.txt` attachments, which are fetched and forwarded to the blockchain provider. +MMS messages can contain attachments, which are fetched and forwarded to the blockchain provider. Pricing for SMS and MMS services may vary depending on the provider. Please check with your provider for more information. diff --git a/stream.js b/stream.js index 39514d0..e8228b8 100644 --- a/stream.js +++ b/stream.js @@ -67,7 +67,7 @@ app.post('/', async (c) => { } // Process MMS if enabled and attachments are present - if (processMMS && mediaUrls && Array.isArray(mediaUrls)) { + if (processMMS && mediaUrls && Array.isArray(mediaUrls) && mediaUrls.length > 0) { log('debug', `MMS URLs: "${mediaUrls}"`); const mmsResult = await processMMSMessages(mediaUrls); if (mmsResult) return mmsResult; @@ -118,21 +118,19 @@ async function processSMS(messageBody) { async function processMMSMessages(mediaUrls) { for (const url of mediaUrls) { - if (url.endsWith('.txms.txt')) { - try { - const response = await fetch(url); - if (!response.ok) throw new Error(`Failed to fetch file from ${url}`); - const fileContent = await response.text(); + try { + const response = await fetch(url); + if (!response.ok) throw new Error(`Failed to fetch file from ${url}`); + const fileContent = await response.text(); - const parts = validateMessage(fileContent.trim()); - for (const msg of parts) { - const hextx = getHexTransaction(msg); - const result = await sendTransaction(hextx); - if (result) return result; - } - } catch (err) { - log('debug', `Error processing MMS URL ${url}:`, err.message); + const parts = validateMessage(fileContent.trim()); + for (const msg of parts) { + const hextx = getHexTransaction(msg); + const result = await sendTransaction(hextx); + if (result) return result; } + } catch (err) { + log('debug', `Error processing MMS URL ${url}:`, err.message); } } return null;