我正在开发一个谷歌行动,我已经在节点中编写并部署到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?');
});
};
答案 0 :(得分:1)
以下是使用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)日志以进行调试。以下是一些截图:点击"显示JSON"创建以下弹出窗口:
此206 partial_content Webhook call failed. Error: Webhook response was empty.
表示您的webhook存在某种错误,可能是500错误,无法正确格式化的成功回复,或者您错误地输入了您的webhook的HTTPS网址。