0

I can't get the value of my gather input widget in Twilio function, I always get an error enter image description here

This is the name of the gather input widget in Twilio studio enter image description here

This variable is not working. let val = event.widgets.Mortgage_info.Digits.value;

exports.handler = function (context, event, callback) {
     const got = require('got');
    
     
     
     
     got('https://cyan-sparrow-7490.twil.io/assets/mortgage.json').then (response =>{
         
         
         const mort = JSON.parse(response.body);
         let mortgageData = mort.feed.entry;
         let mortgageIdTest = mort.feed.entry[900].gsx$mortgage.$t;
         
         //Begin filter code
         let val = event.widgets.Mortgage_info.Digits.value;
         let index = mortgageData.findIndex(function(item, i){
            return item.gsx$mortgage.$t === val
         });
         
         //End filter code
         
         let mortgageSpecificData = mort.feed.entry[index];
         let mortgageId = mort.feed.entry[index].gsx$mortgage.$t;
         let borrowerName = mort.feed.entry[index].gsx$name.$t;
         let lenderName = mort.feed.entry[index].gsx$lender.$t;
         let recordDate = mort.feed.entry[index].gsx$recorddate.$t;
         let lendAmount = mort.feed.entry[index].gsx$amount.$t;
         let neededData = `Borrower ${borrowerName}\nYou loan with ${lenderName}\nClosed on ${recordDate}`
         
         
         
         console.log(val);
         console.log(index);
         console.log(neededData);
         callback(null,neededData);
         
     });
     
     
    };
nomar09
  • 59
  • 8

1 Answers1

1

You need to pass the value of `{{widgets.Mortgage_info.Digits}}`` into the Twilio Function via the Run Function Widget Function Parameters.

You can see how this may work by looking at this code example.

Using Run Function widget in Studio

Alan
  • 10,465
  • 2
  • 8
  • 9
  • Hi Alan, after I console.log the return is null. How to get the value of the mortgage info? I define it like this let mortgageInfo = event.mortgage_info; is that correct? I already put the key= mortgage_info and value= {{widgets.Mortgage_info.Digits}} in widget function. – nomar09 Apr 28 '21 at 13:25
  • Can you put this code at the top of your function, to console log out the event object and see what is coming in? Also, look at the Studio Execution logs (left side of the screen) and then click on an execution. See what the Digits value is to make sure you are using the correct liquid syntax to access it. Object.keys(event).forEach( thisKey => console.log(`${thisKey}: ${event[thisKey]}`)); – Alan Apr 28 '21 at 15:28
  • After I put the code it logs for an error http://prntscr.com/127h8wb – nomar09 Apr 28 '21 at 15:42
  • 1
    Alan, the key and value are now working in Twilio function. – nomar09 Apr 28 '21 at 18:40