Skip to content

SMS (Twilio)

  • Twilio account and a phone number with SMS capability.
  1. User sends SMS to your Twilio number.
  2. Twilio hits your webhook with From and Body.
  3. Your server posts to GeniStudio /api/v1/message.
  4. You reply via Twilio Messages API.
import express from 'express';
import fetch from 'node-fetch';
import twilio from 'twilio';
const app = express();
app.use(express.urlencoded({ extended: false }));
app.post('/twilio/sms', async (req, res) => {
const from = req.body.From;
const body = req.body.Body;
const r = await fetch('https://message.geneline-x.net/api/v1/message', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': process.env.GENISTUDIO_API_KEY!,
},
body: JSON.stringify({
chatbotId: process.env.GENISTUDIO_CHATBOT_ID!,
email: `${from}@sms`,
message: body,
}),
});
const aiText = await r.text();
const MessagingResponse = twilio.twiml.MessagingResponse;
const twiml = new MessagingResponse();
twiml.message(aiText.slice(0, 1600));
res.type('text/xml').send(twiml.toString());
});
app.listen(3000);

Configure your Twilio number’s Messaging webhook to POST https://yourdomain.com/twilio/sms.