Last active
July 27, 2024 04:17
-
-
Save ranjithkumar8352/56681a9bd5f2603bec7444ef71604ed2 to your computer and use it in GitHub Desktop.
Send TextLocal SMS using Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This code was posted for an article at https://codingislove.com/send-sms-developers/ | |
const axios = require("axios"); | |
const tlClient = axios.create({ | |
baseURL: "https://api.textlocal.in/", | |
params: { | |
apiKey: "YOUR API KEY", //Text local api key | |
sender: "6 CHARACTER SENDER ID" | |
} | |
}); | |
const smsClient = { | |
sendPartnerWelcomeMessage: user => { | |
if (user && user.phone && user.name) { | |
const params = new URLSearchParams(); | |
params.append("numbers", [parseInt("91" + user.phone)]); | |
params.append( | |
"message", | |
`Hi ${user.name}, | |
Welcome to iWheels, Download our app to get bookings from our customers with better pricing. | |
https://iwheels.co` | |
); | |
tlClient.post("/send", params); | |
} | |
}, | |
sendVerificationMessage: user => { | |
if (user && user.phone) { | |
const params = new URLSearchParams(); | |
params.append("numbers", [parseInt("91" + user.phone)]); | |
params.append( | |
"message", | |
`Your iWheels verification code is ${user.verifyCode}` | |
); | |
tlClient.post("/send", params); | |
} | |
} | |
}; | |
module.exports = smsClient; | |
// Now import the client in any other file or wherever required and run these functions | |
// const smsClient = require("./smsClient"); | |
// smsClient.sendVerificationMessage(user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you champ