diff --git a/public/Rizzbot.html b/public/Rizzbot.html index 68bcf8a..a75fd86 100644 --- a/public/Rizzbot.html +++ b/public/Rizzbot.html @@ -55,7 +55,7 @@

RizzGPT - AI Wingman!

- +
@@ -118,16 +118,36 @@

RizzGPT - AI Wingman!

const { betterOptions } = await response.json(); betterOptionsResult.innerHTML = `Better Options: ${betterOptions}`; if (betterOptions) { - const copyBtn = document.createElement('button'); - copyBtn.className = 'btn btn-secondary'; - copyBtn.innerHTML = 'Copy to Clipboard'; - copyBtn.onclick = function() { - navigator.clipboard.writeText(betterOptions); - alert('Copied to clipboard!'); - }; - betterOptionsResult.appendChild(copyBtn); - } + const copyBtn = document.createElement('button'); + copyBtn.className = 'btn btn-secondary'; + copyBtn.innerHTML = 'Copy to Clipboard'; + copyBtn.onclick = function() { + navigator.clipboard.writeText(betterOptions); + alert('Copied to clipboard!'); + }; + + // Create a new button for sending to phone + const sendToPhoneBtn = document.createElement('button'); + sendToPhoneBtn.className = 'btn btn-secondary'; + sendToPhoneBtn.innerHTML = 'Send to Phone'; + sendToPhoneBtn.onclick = function() { + // Call the '/send-to-phone' route to send the message using Twilio + fetch('/send-to-phone', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ betterOptions }) + }) + .then(response => response.text()) + .then(message => alert(message)) + .catch(error => console.error(error)); + }; + + betterOptionsResult.appendChild(copyBtn); + betterOptionsResult.appendChild(sendToPhoneBtn); } +} diff --git a/server.js b/server.js index d4554bd..f9a44a7 100644 --- a/server.js +++ b/server.js @@ -10,6 +10,10 @@ const cors = require('cors'); app.use(cors()); app.use(express.json()); +const accountSid = process.env.TWILIO_ACCOUNT_SID; +const authToken = process.env.TWILIO_AUTH_TOKEN; +const client = require('twilio')(accountSid, authToken); + const configuration = new Configuration({ apiKey: process.env.OPENAI_KEY, }); @@ -68,7 +72,21 @@ function getFeedback(pickupLine) { }); } - + app.post('/send-to-phone', async (req, res) => { + const { betterOptions } = req.body; + try { + const message = await client.messages.create({ + body: betterOptions, + from: process.env.TWILIO_PHONE, + to: process.env.MY_PHONE + }); + console.log(`Message sent to ${message.to}`); + res.send('Message sent!'); + } catch (error) { + console.error(error); + res.status(500).send('Error sending message'); + } + });