Here's what I'm trying to accomplish:
- Set a list of names and numbers (my "group")
- When a text message is sent to the Twilio number, forward it on to every member in the group
At a high-level, the idea seems straight forward enough. My programming / syntax skills are rusty, though, and I'd love some help.
I'm using Twilio Functions, and I've been able to send and receive messages successfully. Now I am stuck on how to carry this idea of iterating through a group.
Here's what I've written so far:
var groupmembers = {
    jonathan:{
        name: 'Jonathan',
        number: '+0000000000'
    },
    joshua:{
        name: 'Joshua',
        number: '+1110000000'
    }
}
exports.handler = function(context, event, callback) {
  // Set some values for later use
  this.fromNumber = event.From
  this.body = event.Body || ''
  let twiml = new Twilio.twiml.MessagingResponse();
  groupmembers.forEach(function(member) {
    // Skip sending if it's the same number
    if (member.number === this.fromNumber ) {
        return;
    }
    // Otherwise, let's send a mesage!
    twiml.message("Hello World").to( member.number );
    callback(null, twiml);
  });
};
The issues I believe I have:
- Not being sure how to properly set my array or "dictionary"
- Not knowing the proper syntax for passing the "to" variable to the message
- Not knowing the proper syntax for doing a loop in NodeJS (the Functions console is telling me that 'groupmembers.forEach is not a function')
Thank you for any and all feedback and for pointing me in the right direction!
 
     
    