作者:手机用户2502885633 | 来源:互联网 | 2023-09-09 11:18
我正在尝试使用DialogFlow的Fulfillment内联编辑器对GitHub的API进行HTTP调用。这是我的代码:
// 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控制台中没有出现任何错误。 dummy-gh-user
替换为我的github用户名。我已将代码添加到现有的完整代码中。
关于此代码为何不起作用的任何想法?