Skip to content
New issue

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

Bot #3

Open
Futurekheed opened this issue Jun 29, 2024 · 1 comment
Open

Bot #3

Futurekheed opened this issue Jun 29, 2024 · 1 comment

Comments

@Futurekheed
Copy link

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});
});

@Zoukov
Copy link

Zoukov commented Jul 1, 2024

Mkdir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants