This project is a simple API built using Node.js written in typescript and Express that allows sending SMS messages via the AfricasTalking SMS service.
Before you begin, ensure you have the following installed on your system:
- Node.js (v18.x or higher)
- npm or yarn
- TypeScript (v5 or higher)
-
Clone this repository:
git clone https://github.com/Anthony11-hub/sms-sending-api.git cd sms-sending-api
-
Install the required dependencies:
npm install
or
yarn install
-
Compile the TypeScript code:
npm run build
sms-sending-api/
│ ├── src/
| │ ├── routes/
│ │ └── ├── smsRoutes.ts # SMS routes using AfricasTalking
│ └── index.ts # Server entry point
├── dist/ # Compiled JavaScript files
├── tsconfig.json # TypeScript configuration
├── package.json
└── README.md
Send an SMS message to a recipient.
-
POST /sms
-
Request body should contain:
{ "to": "+254712345678", "message": "Your message content" }
200 OK
: If the SMS was sent successfully.500 Internal Server Error
: If there was an issue sending the SMS.
curl -X POST http://localhost:4000/sms \
-H "Content-Type: application/json" \
-d '{"to": "+254712345678", "message": "Hello, this is a test message!"}'
To start the development server, run:
npm run dev
This will start the server at http://localhost:4000
- Sign up for an AfricasTalking account at https://africastalking.com/.
- Generate an API key from the dashboard under Settings.
- For testing, use the default
sandbox
username and configure your sandbox environment to send SMS.
- Once you're ready to go live, switch from
sandbox
to your live AfricasTalking username. - Set up your sender ID in the AfricasTalking dashboard to use a custom sender name.
Make sure to also include a tsconfig.json
file in your project to configure TypeScript options.