I have the following function
export function incoming_message(event, context, callback) {
var qs = require('qs');
var util = require('util');
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const response = new MessagingResponse();
const message = response.message({to:"+15621112222"});
var queryString = event.body;
if(queryString != "" && queryString != null && queryString !== undefined){
var obj = qs.parse(queryString);
message.body(obj.Body);
if(obj.NumMedia > 0){
message.media([obj.MediaUrl0,obj.MediaUrl0]);
}
sendemail("myemail@gmail.com","Incoming Message - Twilio",util.inspect(obj));
}else{
message.body("error");
sendemail("myemail@gmail.com","Incoming Text Message with Twilio, No DATA Present","No Data");
}
callback(null, successXml(response.toString()));
}
If I send media like this instead it works, message.media(obj.MediaUrl0);
but I need to send the same image back twice in this example. I'm trying to relay MMS messages the user texted to another number. The limit is 10 MMS per message. My attempt to use an array failed to work, and Twilio returned this as the XML it generated.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message to="+14079470503">
<Body>Teeeeeee</Body>
<Media 0="https://api.twilio.com/2010-04-01/Accounts/ACb07efd8168f1be2d5e109f66002ed172/Messages/MM29c53d31a3aa1f6cf70bcd92b6d0031d/Media/MEc9c082a5266668b61b0bb6fa13272bf8" 1="https://api.twilio.com/2010-04-01/Accounts/ACb07efd8168f1be2d5e109f66002ed172/Messages/MM29c53d31a3aa1f6cf70bcd92b6d0031d/Media/MEc9c082a5266668b61b0bb6fa13272bf8"/>
</Message>
</Response>
It gave a warning, Element type "Media" must be followed by either attribute specifications, ">" or "/>".
I am not sure what to do to get this to work. The image is never successfully delivered. Any ideas anyone?
Attempts:
I've tried this also, message.media({"1":obj.MediaUrl0,"2":obj.MediaUrl0});
same error