【发布时间】:2018-11-16 09:05:39
【问题描述】:
我是 Twilio 的新手。我正在尝试使用本教程将 SMS 转发到电子邮件地址:
我确信我已经完成了它所说的一切,但我每次都收到错误 11200 HTTP 检索失败,并提供以下详细信息:
{ "message": "找不到模块 'got'", “名称”:“错误”, "stack": "错误:在 Function.Module._resolveFilename (module.js:547:15) 处找不到模块 'got'\n Function.Module._load (module.js:474:25)\n 在 Module.require (module.js:596:17)\n 在 Module.twilioRequire [按要求] (/var/task/node_modules/enigma-lambda/src/dependency.js:28:21)\n 在 需要 (internal/module.js:11:18)\n 在对象。 (/var/task/handlers/ZFa37cc3db9fd8db0501c2e5fc92137969.js:1:75)\n
在 Module._compile (module.js:652:30)\n 在 Object.Module._extensions..js (module.js:663:10)\n 在 Module.load (module.js:565:32)\n 在 tryModuleLoad (module.js:505:12)" }
我已经尝试过确保我编写的函数与教程中的相同。可以肯定的是,我直接从the github page 复制了它。我不确定如何继续进行故障排除,它似乎告诉我没有找到“得到”,但它应该在 Twilio 功能中可用。有任何想法吗?谢谢。
编辑:这里是代码:
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);
});
};
【问题讨论】:
-
在
exports.handler = function(...之前有const got = require('got');吗?? -
@AlexBaban 是的,谢谢。我已经编辑了我的问题以包含我正在使用的代码。