Discover a simple guide to integrate Bolt.new AI with Smooch (Zendesk Sunshine Conversations) for seamless messaging and automated customer engagement.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
smoochClient.ts
(e.g. inside a folder named integrations
).
import SmoochCore from 'smooch-core';
const smoochClient = new SmoochCore({
keyId: process.env.SMOOCHKEYID || 'yourkeyid',
secret: process.env.SMOOCHSECRET || 'yoursecret'
});
export default smoochClient;
'yourkeyid'
and 'your_secret'
with your actual Sunshine Conversations API credentials or set them via environment variables.
smoochWebhook.ts
(for example, inside a folder named webhooks
).
import { Request, Response } from 'express';
// This function handles incoming webhook events from Smooch/Sunshine Conversations.
export const handleSmoochWebhook = async (req: Request, res: Response) => {
try {
// Log the incoming webhook data for debugging
console.log('Received Smooch webhook:', req.body);
// Process the webhook event.
// For example, if it is a message event, you might extract details:
const event = req.body;
if (event && event.trigger === 'message:appUser') {
// Extract relevant data
const appUserId = event.appUser && event.appUser._id;
const message = event.message && event.message.text;
console.log(Message from app user ${appUserId}: ${message});
// Add your custom logic here (e.g. send this message to Bolt.new AI for further processing)
}
// Respond with 200 OK to acknowledge receipt
res.status(200).send('Webhook received');
} catch (error) {
console.error('Error processing Smooch webhook:', error);
res.status(500).send('Internal Server Error');
}
};
index.ts
or app.ts
).
import express from 'express';
import bodyParser from 'body-parser';
import { handleSmoochWebhook } from './webhooks/smoochWebhook';
const app = express();
// Middleware to parse JSON bodies
app.use(bodyParser.json());
// Define your webhook endpoint
app.post('/webhook', handleSmoochWebhook);
// Other routes and middleware may already exist here
// Start your server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(Server is running on port ${PORT});
});
/webhook
that will receive JSON data from Sunshine Conversations.
sendMessage.ts
(you may put it in a services
folder).
import smoochClient from './smoochClient';
export const sendMessage = async (appUserId: string, messageText: string) => {
try {
const response = await smoochClient.appUsers.sendMessage(appUserId, {
type: 'text',
text: messageText
});
console.log('Message sent successfully:', response);
return response;
} catch (error) {
console.error('Error sending message:', error);
throw error;
}
};
sendMessage
from anywhere in your project. For example, integrate it in your conversational logic to respond to users.
// Example of how you might set defaults in your code
process.env.SMOOCHKEYID = 'yourkeyid';
process.env.SMOOCHSECRET = 'yoursecret';
/webhook
) is publicly accessible by Sunshine Conversations. You might need to set up an HTTPS endpoint or use a tunnel service during development.sendMessage
function sends a message as expected.
By following these steps, you integrate Zendesk Sunshine Conversations (formerly Smooch) into your Bolt.new AI project. Each change is contained in specific files to keep your project modular and easy to manage.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.