【发布时间】:2021-12-23 17:03:16
【问题描述】:
我已经测试了我的 nodemailer nodejs 代码并且它可以工作。我现在面临的问题是,当我将 Firebase db 的 Dialogflow Fulfillment 版本从 0.5.0 更改为 0.6.1 时,nodemailer 将崩溃。但是,当我将其切换回0.5.0 时,它可以工作。
我能知道如何解决这个问题吗?我是否需要为 ver 0.6.1 添加额外的代码或有什么区别?
我的代码如下:
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'EMAIL',
pass: 'APP PASSWORD'
}
});
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function sendEmail(agent){
const email = agent.parameters.email;
const name = agent.parameters.name;
const cls = agent.parameters.cls;
const message = agent.parameters.message;
const mailOptions = {
from: 'SENDER EMAIL',
to: 'EMAIL',
cc: email,
subject: "ABC",
text: "MESSAGE:" +
'\n\n Name: ' + name +
'\n\n Class: ' + cls +
'\n\n Email: ' + email +
'\n\n Message: ' + message
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
}
else {
console.log('Email sent: ' + info.response);
}
});
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('Email Enquiry', sendEmail);
agent.handleRequest(intentMap);
});
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "10"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.6.1",
"nodemailer": "^6.6.3"
}
}
错误:
Function execution took 150 ms, finished with status: 'crash'
Dialogflow fulfillment error : Webhook call failed. Error: UNAVAILABLE, State: URL_UNREACHABLE, Reason: UNREACHABLE_5xx, HTTP status code: 500.
【问题讨论】:
-
您好,您是使用内联编辑器运行这段代码吗?或者这个代码只是在外部运行,使用库dialogflow-fulfillment-nodejs 如果是这样,你的问题是由于库的过时造成的。正如您在链接中看到的,该库不再维护。您可以尝试在inline editor with cloud functions 中运行您的代码。
-
嗨@Betjens,是的,我正在使用内联编辑器来运行代码。但它似乎不适用于 0.6.1。可能是什么原因?
-
好的,我已经复制了我这边的问题,并为邮件意图获得了相同的输出,但其他意图很好。所以我认为它不是到达服务器端的问题,而是使用邮件功能。看起来像这样case。
标签: node.js email dialogflow-es nodemailer dialogflow-es-fulfillment