├── .gitignore ├── LICENCE.md ├── README.md ├── javascript ├── orangeSMS.js ├── package-lock.json ├── package.json └── usageExample.js └── python ├── orangeSMS.py └── usageExample.py /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | node_modules/ 3 | __pycache__ -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2021 Honorable Con 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Orange SMS API 📬 2 | 3 | [![Made-In-Senegal](https://github.com/GalsenDev221/made.in.senegal/blob/master/assets/badge.svg)](https://github.com/GalsenDev221/made.in.senegal) 4 | 5 | > Orange SMS is a client library that allow you to send SMS with Javascript and Python using the [Orange SMS API](https://developer.orange.com/apis/sms-sn/overview) 6 | 7 | ## Disclaimer ⛔ 8 | 9 | This gem is not an official client of Orange, in order to use the client you need to create a [Orange SMS API](https://developer.orange.com/apis/sms-sn/overview) and to register an app in the developer dashboard that orange provide to you. 10 | After registering your app you can ask for SMS integration approval (this process can take time :) 11 | The registration process is detailed [here](https://developer.orange.com/apis/sms-sn/overview) 12 | 13 | Instead of reading and trying to understand once again how the Orange SMS API work this gem aims to let you quickly send SMS from JavaScript and Python using the [Orange SMS API](https://developer.orange.com/apis/sms-sn/overview). 14 | 15 | Check this [link](https://developer.orange.com/apis/sms-sn/overview) to find the steps of app creation. 16 | 17 | ## Install 📥 18 | ### Via NPM 19 | `npm i orange-sms-client` 20 | 21 | ## Usage ✅ 22 | 23 | 1. Copy your client id [here](https://developer.orange.com/myapps) 24 | (if you have already create an app) 25 | 2. generate token with `getToken` function 26 | 3. send sms with `sendSMS` function 27 | 28 | 29 | Exemple : [usageExample.py](/python/usageExample.py) | [usageExample.js](/javascript/usageExample.js) 30 | 31 | ### JavaScript 💛 32 | 33 | 34 | ```javascript 35 | 36 | const clientID = "your clientID" 37 | const token = await getToken(clientID) 38 | let senderAdress = "+2210000" 39 | let address = "+221{{receiver}}" 40 | sendSMS(senderAdress, address, 'message', token) 41 | ``` 42 | 43 | ### Python 🐍 44 | 45 | ```python 46 | 47 | clientID="your clientID" 48 | token = getToken(clientID) 49 | senderAdress = "+2210000" 50 | address = "+221{{receiver}}" 51 | sendSMS(senderAddress, receiverAddress, "message", token) 52 | ``` 53 | ### Modules 54 | 55 | 56 | - **sendSMS** : for sending SMS 57 | - params : 58 | - senderAddress 59 | - receiverAddress 60 | - message 61 | - token 62 | - return 63 | - response 64 | 65 | - **getToken** : to get token 66 | - params : 67 | - token 68 | - return : 69 | - token 70 | 71 | - **showBalanceSMS** : to show balance 72 | - params : 73 | - token 74 | - return : 75 | - balance 76 | 77 | - **getUsageStats** : to get usage stats 78 | - params : 79 | - token 80 | - return : 81 | - stats 82 | 83 | #### Contributing 🤝 84 | 85 | Bug reports and Pull Requests are welcome 👋🏽 86 | You can tell me **[HERE](https://github.com/honorableCon/OrangeSMS-API/issues)** 87 | 88 | #### License 🔖 89 | 90 | This project is under **[MIT License](https://opensource.org/licenses/MIT)**. 91 | -------------------------------------------------------------------------------- /javascript/orangeSMS.js: -------------------------------------------------------------------------------- 1 | import fetch from 'node-fetch'; 2 | 3 | async function getToken(clientID){ 4 | const data = await fetch('https://api.orange.com/oauth/v3/token', { 5 | method: 'POST', 6 | headers: { 7 | 'Authorization': `Basic ${clientID}`, 8 | 'Content-Type': 'application/x-www-form-urlencoded', 9 | 'Accept': 'application/json' 10 | }, 11 | body: 'grant_type=client_credentials' 12 | }).then( response => response.json()) 13 | 14 | return data['access_token']; 15 | } 16 | 17 | async function sendSMS(senderAdress, address, message, token){ 18 | const data = await fetch(`https://api.orange.com/smsmessaging/v1/outbound/tel:${senderAdress}/requests`, { 19 | method: 'POST', 20 | headers: { 21 | 'Authorization': `Bearer ${token}`, 22 | 'Content-Type': 'application/json' 23 | }, 24 | body: JSON.stringify({ 25 | "outboundSMSMessageRequest":{ 26 | "address":`tel:${address}`, 27 | "senderAddress" : `tel:${senderAdress}`, 28 | "outboundSMSTextMessage":{ 29 | "message": message 30 | } 31 | } 32 | }) 33 | }) 34 | .then( response => response.json()) 35 | 36 | return data 37 | } 38 | 39 | async function getUsageStats(token){ 40 | const stats = await fetch('https://api.orange.com/sms/admin/v1/statistics', { 41 | headers: { 42 | 'Authorization': `Bearer ${token}` 43 | } 44 | }) 45 | .then( response => response.json()) 46 | 47 | return stats 48 | } 49 | 50 | async function showBalanceSMS(token) { 51 | const balance = fetch('https://api.orange.com/sms/admin/v1/contracts', { 52 | headers: { 53 | 'Authorization': `Bearer ${token}` 54 | } 55 | }).then( response => response.json()); 56 | 57 | return balance 58 | } 59 | 60 | export { 61 | sendSMS, showBalanceSMS, getToken, getUsageStats 62 | } -------------------------------------------------------------------------------- /javascript/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "testapiorangesms", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "testapiorangesms", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "dotenv": "^10.0.0" 13 | } 14 | }, 15 | "node_modules/dotenv": { 16 | "version": "10.0.0", 17 | "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", 18 | "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", 19 | "engines": { 20 | "node": ">=10" 21 | } 22 | } 23 | }, 24 | "dependencies": { 25 | "dotenv": { 26 | "version": "10.0.0", 27 | "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", 28 | "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "testapiorangesms", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "type": "module", 10 | "keywords": ["Orange", "API"], 11 | "author": "Honorable Con", 12 | "license": "ISC" 13 | } 14 | -------------------------------------------------------------------------------- /javascript/usageExample.js: -------------------------------------------------------------------------------- 1 | import {getToken, sendSMS} from './orangeSMS.js'; 2 | 3 | const clientID = "aklGYUdsYjdhY...QVRBOVVkVTFqRHkxdg==" 4 | const token = await getToken(clientID) 5 | let senderAdress = "+2210000" 6 | let address = "+221781234567" 7 | 8 | sendSMS(senderAdress, address, "bonjour from node", token) 9 | .then(result => { 10 | console.log(result); 11 | }); -------------------------------------------------------------------------------- /python/orangeSMS.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | 4 | def getToken(clientID): 5 | response = requests.post('https://api.orange.com/oauth/v3/token', 6 | headers={ 7 | 'Authorization': f"Basic {clientID}", 8 | 'Content-Type': 'application/x-www-form-urlencoded', 9 | 'Accept': 'application/json' 10 | }, data={ 11 | 'grant_type': 'client_credentials' 12 | } 13 | ) 14 | response = response.json() 15 | return response['access_token'] 16 | 17 | 18 | def getUsageStats(token): 19 | response = requests.get('https://api.orange.com/sms/admin/v1/statistics', 20 | headers={ 21 | 'Authorization': f'Bearer {token}' 22 | } 23 | ) 24 | stats = response.json() 25 | 26 | return stats 27 | 28 | 29 | def showBalanceSMS(token): 30 | response = requests.get('https://api.orange.com/sms/admin/v1/contracts', 31 | headers={ 32 | 'Authorization': f"Bearer {token}" 33 | } 34 | ) 35 | balance = response.json() 36 | print(balance) 37 | 38 | return balance 39 | 40 | 41 | def sendSMS(senderAddress, receiverAddress, message, token): 42 | url = f'https://api.orange.com/smsmessaging/v1/outbound/tel:{senderAddress}/requests' 43 | headers = { 44 | 'Authorization': f'Bearer {token}', 45 | 'Content-Type': 'application/json', 46 | } 47 | 48 | data = { 49 | "outboundSMSMessageRequest":{ 50 | "address": f"tel:{receiverAddress}", 51 | "senderAddress":f"tel:{senderAddress}", 52 | "outboundSMSTextMessage":{ 53 | "message": message 54 | } 55 | }} 56 | response = requests.post(url, headers=headers, data=json.dumps(data)) 57 | 58 | return response.json() 59 | -------------------------------------------------------------------------------- /python/usageExample.py: -------------------------------------------------------------------------------- 1 | from orangeSMS import sendSMS, getToken 2 | 3 | 4 | clientID = "aklGYUdsYjdhY2VpM...Hkxdg==" 5 | token = getToken(clientID) 6 | senderAdress = "+2210000" 7 | address = "+221781234567" 8 | 9 | result = sendSMS(senderAdress, address, "Salam from python", token) 10 | print(result) --------------------------------------------------------------------------------