Skip to content

Commit

Permalink
Add support for multiple phone numbers comma separated (#5)
Browse files Browse the repository at this point in the history
* Add support for multiple phone number comma separated

* Update README.md

* Update README.md

* Update Change log
  • Loading branch information
mikhail-vl authored Apr 2, 2024
1 parent 6a4e7cd commit 2f0bc75
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.1.0 (2024-03-15)

### Features / Enhancements

- Add support for multiple phone number comma separated (#4)

## 1.0.0 (2024-01-15)

### Features / Enhancements
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ Run the command `npm install` and `npm run start` to start the server.
## REST API

```
fetch('http://localhost:3000/sendsms?number=1234567890', {
fetch('http://localhost:3000/sendsms?number=1234567890,12223334455', {
method: 'POST',
headers: {
authorization: '[apiKey]'
},
body: JSON.stringify({
message: 'Your message'
})
})
}).then((response) => response.text())
.then((body) => {
console.log(body);
})
.catch((error) => {
console.error('error in execution', error);
})
```

## Feedback
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"stop": "docker-compose down",
"typecheck": "tsc --emitDeclarationOnly false --noEmit"
},
"version": "1.0.0"
"version": "1.1.0"
}
25 changes: 20 additions & 5 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,30 @@ app.post(
});
}

/**
* Split to multiple numbers
*/
const numbers = phoneNumber.split(',');

/**
* Prepare messages
*/
const allPromise = Promise.all(
numbers.map(async (number) => {
await twilioClient.messages.create({
body: req.body.message || 'Test',
from: process.env.TWILIO_PHONE_NUMBER,
to: `+${number}`,
});
})
);

/**
* Send message
*/
try {
await twilioClient.messages.create({
body: req.body.message,
from: process.env.TWILIO_PHONE_NUMBER,
to: `+${phoneNumber}`,
});
await allPromise;

res.send({
message: 'success',
});
Expand Down

0 comments on commit 2f0bc75

Please sign in to comment.