Learn how to seamlessly integrate Bolt.new AI with Nexmo (Vonage API). Follow our step-by-step guide to streamline messaging automation and boost communications.
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 in your Bolt.new AI project.nexmo
dependency manually by inserting it into the "dependencies" section. Since Bolt.new AI doesn’t provide a terminal, you must edit this file directly. For example, update your package.json
like this:
{
"name": "my-bolt-project",
"version": "1.0.0",
"dependencies": {
"nexmo": "^2.9.2"
},
"scripts": {
"start": "node dist/index.js"
}
}
src
), create a new file called nexmoIntegration.ts
.nexmoIntegration.ts
. This code initializes the Nexmo client using API credentials from environment variables and provides a function to send an SMS:
import Nexmo from 'nexmo';
const nexmo = new Nexmo({
apiKey: process.env.NEXMOAPIKEY as string,
apiSecret: process.env.NEXMOAPISECRET as string,
});
export function sendSMS(from: string, to: string, text: string): void {
nexmo.message.sendSms(from, to, text, (error, responseData) => {
if (error) {
console.error("Error occurred:", error);
} else {
const message = responseData.messages[0];
if (message.status === "0") {
console.log("Message sent successfully.");
} else {
console.error(Message failed with error: ${message['error-text']});
}
}
});
}
NEXMOAPIKEY
and NEXMOAPISECRET
.
index.ts
or app.ts
) in the src
folder.sendSMS
function from nexmoIntegration.ts
at the top of your file, and call it in the context of your application logic. For instance, you might add an endpoint that triggers an SMS send:
import express from 'express';
import { sendSMS } from './nexmoIntegration';
const app = express();
// Example endpoint to send an SMS
app.get('/send-sms', (req, res) => {
const from = 'YourApp';
const to = 'RecipientPhoneNumber'; // Replace with a valid phone number
const text = 'Hello from Bolt.new AI integrated with Nexmo!';
sendSMS(from, to, text);
res.send('SMS send initiated. Check your console for the response.');
});
// Start the server on the designated port
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(Server is running on port ${PORT});
});
/send-sms
that uses the Nexmo integration to send an SMS message.
NEXMOAPIKEY
: Your Nexmo API keyNEXMOAPISECRET
: Your Nexmo API secretindex.ts
) and the Nexmo integration file are saved. Bolt.new AI will automatically compile your TypeScript files and deploy the application.
By following these steps, you have manually added the nexmo
dependency, created a dedicated integration file, and incorporated the SMS sending functionality into your Bolt.new AI project without using a terminal.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.