Unable to send a autoresponse to my auto question using twilio API

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

hey @ss_chhaunkar

you are using the switch statement wrong, it should return a value after each case,
heres example.

switch (new Date().getDay()) {
  case 0:
    day = "Sunday";
    break;
  case 1:
    day = "Monday";
    break;
  case 2:
     day = "Tuesday";
    break;
  case 3:
    day = "Wednesday";
    break;
  case 4:
    day = "Thursday";
    break;
  case 5:
    day = "Friday";
    break;
  case 6:
    day = "Saturday";
}

You can have multiple case clauses for an expression:

You don’t need the curly braces (they are causing no harm but I don’t think most would use them there unless there was a specific reason to, such as shadowing a previously declared variable).

Instead of that switch expression it might be cleaner to just convert query to lowercase and compare it to hi and hello.

As for your question, I’m not familiar with WhatsApp and the twilio API so I can’t help you there.

Hi,

It looks ok, but I never work with twilio API.
What’s the console.log(query) output is?
And you don’t need curly braces after case:...