Learn how to integrate Lovable with Plivo using our step-by-step guide. Streamline your communications and boost your business efficiency effortlessly.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
package.json
file.
"dependencies"
section, add the Plivo dependency as shown below. This will instruct the platform to install the Plivo package.
{
"dependencies": {
"plivo": "^4.25.1"
// ... your other dependencies
}
}
package.json
file. Lovable will detect the changes and install the required dependency automatically.
src
directory (or the main directory of your TypeScript code).
integrations
if it doesn't exist already.
integrations
folder, create a new file named plivoIntegration.ts
.
plivoIntegration.ts
. This code initializes the Plivo client with your authentication credentials and defines a function to send SMS messages.
import * as plivo from 'plivo';
// Ensure your environment variables are set with your Plivo credentials.
// You can also manually assign the values for testing purposes:
// process.env.PLIVOAUTHID = 'YOURPLIVOAUTH_ID';
// process.env.PLIVOAUTHTOKEN = 'YOURPLIVOAUTH_TOKEN';
const client = new plivo.Client(
process.env.PLIVOAUTHID as string,
process.env.PLIVOAUTHTOKEN as string
);
/**
- sendSMS sends an SMS message using Plivo.
- @param to - The destination phone number.
- @param message - The text message content.
*/
export const sendSMS = async (to: string, message: string): Promise => {
try {
const response = await client.messages.create(
'YOURPLIVONUMBER', // Replace with your registered Plivo phone number.
to,
message
);
console.log('SMS sent successfully:', response);
return response;
} catch (error) {
console.error('Error sending SMS:', error);
throw error;
}
};
PLIVOAUTHID
and PLIVOAUTHTOKEN
in Lovable’s configuration settings if such an option exists.
// Only for testing purposes. Replace with your secure method for production.
process.env.PLIVOAUTHID = 'YOURPLIVOAUTH_ID';
process.env.PLIVOAUTHTOKEN = 'YOURPLIVOAUTH_TOKEN';
app.ts
or your main application file) and import the sendSMS
function:
import { sendSMS } from './integrations/plivoIntegration';
sendSMS
function wherever needed. Here is an example of sending a test SMS message:
const sendTestSMS = async () => {
try {
await sendSMS('DESTINATIONPHONENUMBER', 'Hello from Lovable integrated with Plivo!');
console.log('Test SMS sent successfully.');
} catch (error) {
console.error('Failed to send test SMS:', error);
}
};
// Trigger the test SMS function. Adjust when you want to send the SMS.
sendTestSMS();
DESTINATIONPHONENUMBER
with the target phone number and ensure that the phone numbers are in the proper format required by Plivo.
sendSMS
.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.