We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mkdir whatsapp-bot cd whatsapp-bot npm init -y npm install express twilio body-parser const express = require('express'); const bodyParser = require('body-parser'); const twilio = require('twilio');
const app = express(); const port = process.env.PORT || 3000;
const accountSid = 'your_twilio_account_sid'; const authToken = 'your_twilio_auth_token'; const client = twilio(accountSid, authToken);
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/whatsapp', (req, res) => { const incomingMessage = req.body.Body; const from = req.body.From;
let responseMessage = 'Hello!';
if (incomingMessage.toLowerCase() === 'hi') { responseMessage = 'Hi there! How can I help you today?'; }
client.messages .create({ body: responseMessage, from: 'whatsapp:+14155238886', // Twilio sandbox number to: from }) .then(message => console.log(message.sid)) .catch(err => console.error(err));
res.sendStatus(200); });
app.listen(port, () => { console.log(Server running on port ${port}); });
Server running on port ${port}
The text was updated successfully, but these errors were encountered:
Mkdir
Sorry, something went wrong.
No branches or pull requests
mkdir whatsapp-bot
cd whatsapp-bot
npm init -y
npm install express twilio body-parser
const express = require('express');
const bodyParser = require('body-parser');
const twilio = require('twilio');
const app = express();
const port = process.env.PORT || 3000;
const accountSid = 'your_twilio_account_sid';
const authToken = 'your_twilio_auth_token';
const client = twilio(accountSid, authToken);
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/whatsapp', (req, res) => {
const incomingMessage = req.body.Body;
const from = req.body.From;
let responseMessage = 'Hello!';
if (incomingMessage.toLowerCase() === 'hi') {
responseMessage = 'Hi there! How can I help you today?';
}
client.messages
.create({
body: responseMessage,
from: 'whatsapp:+14155238886', // Twilio sandbox number
to: from
})
.then(message => console.log(message.sid))
.catch(err => console.error(err));
res.sendStatus(200);
});
app.listen(port, () => {
console.log(
Server running on port ${port}
);});
The text was updated successfully, but these errors were encountered: