I'm new to Twilio. I'm attempting to forward an SMS to an email address using this tutorial:
I feel certain I've done everything it says to do, but I get an error 11200 HTTP retrieval failure every time, with these details:
{ "message": "Cannot find module 'got'", "name": "Error", "stack": "Error: Cannot find module 'got'\n at Function.Module._resolveFilename (module.js:547:15)\n at Function.Module._load (module.js:474:25)\n at Module.require (module.js:596:17)\n at Module.twilioRequire [as require] (/var/task/node_modules/enigma-lambda/src/dependency.js:28:21)\n at require (internal/module.js:11:18)\n at Object. (/var/task/handlers/ZFa37cc3db9fd8db0501c2e5fc92137969.js:1:75)\n
at Module._compile (module.js:652:30)\n at Object.Module._extensions..js (module.js:663:10)\n at Module.load (module.js:565:32)\n at tryModuleLoad (module.js:505:12)" }
I've tried making absolutely sure I have the function written the same as the tutorial. I copied it directly from the github page to be sure. I'm not sure how to proceed in troubleshooting this, it seems it's telling me that 'got' isn't found but it's supposed to be available in Twilio functions. Any ideas? Thanks.
Edit: Here is the code:
const got = require('got');
exports.handler = function(context, event, callback) {
const requestBody = {
personalizations: [{ to: [{ email: context.TO_EMAIL_ADDRESS }] }],
from: { email: context.FROM_EMAIL_ADDRESS },
subject: `New SMS message from: ${event.From}`,
content: [
{
type: 'text/plain',
value: event.Body
}
]
};
got
.post('https://api.sendgrid.com/v3/mail/send', {
headers: {
Authorization: `Bearer ${context.SENDGRID_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
})
.then(response => {
let twiml = new Twilio.twiml.MessagingResponse();
callback(null, twiml);
})
.catch(err => {
callback(err);
});
};
const got = require('got');
beforeexports.handler = function(...
?? – Alex Baban