Node.js 在dialogflow中执行POST请求
我试图使用DialogFlow的内联编辑器对GitHub的API进行HTTP post调用。这是我的密码:Node.js 在dialogflow中执行POST请求,node.js,firebase,dialogflow-es,Node.js,Firebase,Dialogflow Es,我试图使用DialogFlow的内联编辑器对GitHub的API进行HTTP post调用。这是我的密码: // See https://github.com/dialogflow/dialogflow-fulfillment-nodejs // for Dialogflow fulfillment library docs, samples, and to report issues 'use strict'; const functions = require('firebase-func
// 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');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
var github = require('request');
github.post({
headers: {'User-Agent' : 'dummy-gh-user', 'Authorization': 'token ****'},
url: 'https://api.github.com/repos/dummy-gh-user/dummy-gh-repo/issues',
json:
{
"title": "This is a bug",
"body": "I'm having a problem with this.",
"assignees": [
"dummy-gh-user"
],
"labels": [
"bug"
]
}
}, function(error, response, body){
console.log(body);
});
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?`);
}
// 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('your intent name here', yourFunctionHandler);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});
上面的代码得到部署和保存,我在firebase控制台中没有发现任何错误。虚拟gh用户
将替换为我的github用户名。我已将我的代码添加到现有的完整填充代码中
关于这段代码为什么不起作用有什么想法吗?github帖子的代码在我的本地环境中运行得非常好。不确定发生了什么变化。但同样的代码今天也在起作用。