Skip to content

Commit

Permalink
added twilio
Browse files Browse the repository at this point in the history
  • Loading branch information
arncv committed Apr 2, 2023
1 parent b3dea49 commit 600167e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
40 changes: 30 additions & 10 deletions public/Rizzbot.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<h1>RizzGPT - AI Wingman!</h1>

<form id="pickupLineForm">
<label class="user-label">Enter Pickup Line</label>

<div class="inputGroup">
<input type="text" class="input" id="pickupLine" name="pickupLine">

Expand Down Expand Up @@ -118,16 +118,36 @@ <h1>RizzGPT - AI Wingman!</h1>
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);
}
}
</script>
</body>
</html>
20 changes: 19 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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');
}
});



Expand Down

0 comments on commit 600167e

Please sign in to comment.