我是 Twilio 的新手。我正在尝试使用本教程将短信转发到电子邮件地址:
https://www.twilio.com/blog/2017/07/forward-incoming-sms-messages-to-email-with-node-js-sendgrid-and-twilio-functions.html https://www.twilio.com/blog/2017/07/forward-incoming-sms-messages-to-email-with-node-js-sendgrid-and-twilio-functions.html
我确信我已经完成了它所说的所有操作,但每次都会收到错误 11200 HTTP 检索失败,并包含以下详细信息:
{
"message": "找不到模块'got'",
"名称": "错误",
"stack": "错误:无法在 Function.Module._resolveFilename (module.js:547:15)\n 处找到模块 '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)" }
我已经尝试绝对确保我编写的函数与教程相同。我直接复制自github 页面 https://github.com/philnash/useful-twilio-functions/tree/master/forward-message-as-email为了确定。我不知道如何继续解决此问题,它似乎告诉我未找到“got”,但它应该在 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);
});
};