I am sending an autoresponse to the message ‘Hi’ on WhatsApp through twilio API. Using switch statement as shown below.
app.post('/sms', (req, res) => {
const receievedMessage = req.body;
console.log(receievedMessage);
// console.log(receievedMessage.From);
const from = receievedMessage.From;
const query = receievedMessage.Body;
console.log(query);
const msgText = `${query}, Welcome to Ohphish.Fortifying Frontlines.Protect your workforce from Phishing attacks for FREE`;
const msgText2 = 'Kindly Enter Your Registered Mobile Number';
function sendWithDelay(){
setTimeout(() => {
sendMessage(msgText2,from);
},2000)
}
switch(query){
case 'Hi':
case 'hi':
case 'HI':
case 'Hello':
case 'hello':
case 'HELLO':
{
sendMessage(msgText,from);
sendWithDelay();
}
break;
default:
sendMessage('Sorry, Wrong Query', from)
}
I am sending two auto responses first is WelcomeMessage and second is a message to provide registered mobile number. When the mobile number is given the message I get is the default case of switch. My target is to send the same number with a message as Number entered by you is [number]
module.exports = sendMessage = (msgText,to) => {
client.messages
.create({
body: msgText,
from: 'whatsapp:+14155238886',
to: to
})
.then(message => {
console.log(message.sid);
})
.done();
}
Kindly help