I'm using Twilio Functions to look up a previous messages that was sent to from the incoming SMS.
exports.handler = function(context, event, callback) {
const fromNumber = event.From;
const client = context.getTwilioClient();
client.messages.list({
to: fromNumber,
limit: 1
})
.then((messages) => {
console.log(`Found message with SID ${messages[0].sid}`);
})
.catch(error => {
console.log(error);
});
};
But whatever I try, I can't get any results from the client.message.list(). Any thoughts? Thanks!
Went through twilio documentation. There weren't an exact example for this, but in a similar manner You could create new messages. No error from the console side also.
Turns out the problem was me. I had callback() call made outside the promise handling, which caused the function to exit before promise was done. More information from if anybody needs
https://www.twilio.com/docs/serverless/functions-assets/functions/invocation