Skip to content

Commit

Permalink
Merge pull request #24 from DataLayerHost/update/docker-24
Browse files Browse the repository at this point in the history
Added .txms.txt extension
  • Loading branch information
rastislavcore authored Aug 22, 2024
2 parents ebe50fb + 995c6e7 commit d2bcdb7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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.

Expand Down Expand Up @@ -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 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.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "txms-server",
"version": "1.2.5",
"version": "1.2.6",
"description": "TxMS server",
"main": "stream.js",
"engines": {
Expand Down
26 changes: 12 additions & 14 deletions stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,21 +118,19 @@ async function processSMS(messageBody) {

async function processMMSMessages(mediaUrls) {
for (const url of mediaUrls) {
if (url.endsWith('.txms')) {
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;
Expand Down

0 comments on commit d2bcdb7

Please sign in to comment.