I want to test my if else condition in the Twilio function.
The condition is if the user will text "Hi", Twilio will send him a quote.
The problem the condition always runs false even if I texted "Hi".
I'm not sure if the event.Body
is the right code to get the value of the message body.
exports.handler = function (context, event, callback) {
const got = require('got');
got('https://cyan-sparrow-7490.twil.io/assets/quote.json').then(response =>{
let messageBody = event.Body;
const qotd = JSON.parse(response.body);
let quote = qotd.contents.quotes[0];
const quoteEffect = messageBody === "Hi"? callback(null,quote): callback(null,null);
callback(null,quoteEffect);
});
};
Step 1,
Use the split Based Widget and input to the "Variable to Test" trigger.message.Body
Then add a condition in the Split Based Widget that could be found in the Transitions tab, if the incoming messages is equal to "Hi" then it will proceed to the next widget
Step 2,
Step 3
Step 4