Wednesday, 1 November 2017

Error: Can't set headers after they are sent.

As far as I understand this error means I can't send something back to the web browser a second time. After examining my code I don't believe I'm doing that, but I'm obviously wrong as the code isn't working.In simple terms I'm trying to grab an email address and then send an email to that address./** * ExternalreqestsController */ module.exports = { inboundSms: function(req, res) { // Receiver's phone number var to_number = req.body.To || req.query.To; // Sender's phone number var from_number = req.body.From || req.query.From; // The text which was received var text = req.body.Text || req.query.Text; // For testing purposes var email = req.body.Email || req.query.Email; var response = res.ok(req.body); response.send("Message received"); let emailNotification = { method: 'email', organizationId: '', subject: 'Text Message Received', body: ` Wondering Why `, addresses: ['${email}'], from: 'no-reply@company.com', identifier: 'inbound-sms' }; return Notifications.create(emailNotification) .then((notif) => { return true; }); } };

Submitted November 01, 2017 at 04:10PM by X-lem

No comments:

Post a Comment