1

I can't split up a string using Functions. This is an SMS app in Studio:
User texts his full name to Twilio, I call a function and add the Liquid variable with their full name and send it to a Function where I want to return only the first name.

exports.handler = function(context, event, callback) {
    var firstName = event.fullName.split(' ');
    callback(null, firstName[0]);
};

error message:Cannot read property 'split' of undefined

Alex Baban
  • 11,312
  • 4
  • 30
  • 44

1 Answers1

1

First, your code for the function is fine, except that event.fullName is undefined because is not being passed from the Studio.

In Studio, add a fullName parameter to the function call. The value for the parameter is {{trigger.message.Body}} (to pass the incoming message text body to the function), then you will be able to access it in your function.

Note: In the "Function Parameters" section of the "RUN FUNCTION" widget there are two "Save" buttons, you will need to click them both, first the one for the parameters, then the (red) one for the widget.

Here is a screen capture which might help you

enter image description here

Alex Baban
  • 11,312
  • 4
  • 30
  • 44
  • Thank you Alex! That is exactly how I had the Function widget and parameters configured, but I must have neglected to properly save the function. I think my next question is "When do I stop feeling stupid?" :) All good, Brent – Brent Thompson May 21 '19 at 12:17
  • @BrentThompson I missed the first "Save" button many times, the reason I've added to the answer. Cheers. – Alex Baban May 21 '19 at 13:42