我正在研究我在node中编写的Google Action ,并正在部署到Firebase以通过API.AI上定义的意图进行交互。
我想实现一种功能,该功能可以在激活特定意图时将电子邮件发送到特定地址。我尝试使用nodemail和sendmail软件包,但是在与它们一起部署之后,当调用正确的意图时,它们似乎并没有发送电子邮件。我不确定问题出在我是否将其编码错误(由于我的经验不足,这很可能),或者在Firebase部署中指定这些软件包是否存在一些固有的问题。我已经能够通过简单地从其中返回对API.AI的响应来验证是否进入了执行sendmail
的代码;如果我能够访问firebase或API.AI日志,则不确定如何操作。据我所知,API.AI显示了一个JSON响应,仅此而已。
这是一些简化的代码(仅相关部分):
const sendmail = require('sendmail')();
const getSuggestion = app => {
const rawInput = app.getRawInput();
sendmail({
from: 'no-reply@yourdomain.com',
to: 'myemail@gmail.com',
subject: 'test sendmail',
html: rawInput,
}, function(err, reply) {
console.log(err && err.stack);
console.dir(reply);
return app.ask('You said ' + rawInput + '. Do you have any further input?');
});
};
最佳答案
以下是使用Cloud Functions for Firebase(又名Firebase功能),nodemailer和Gmail的示例:https://github.com/firebase/functions-samples/tree/master/quickstarts/email-users
当webhook调用失败时,API.AI会在API.AI的模拟器中指示206,因为即使webhook调用失败,某些内容也会被API.AI感知。如果在单击“显示JSON”后看到206,请检查您的Webhook(在本例中为Firebase)日志进行调试。以下是一些屏幕截图:
单击“SHOW JSON”将创建以下弹出窗口:
此206 partial_content Webhook call failed. Error: Webhook response was empty.
指示您的Webhook出现某种错误,或者是500错误,无法正确设置格式的成功响应或者您为Webhook输入了错误的HTTPS URL。
关于node.js - 通过Firebase项目上的Node发送电子邮件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46015997/