作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Dialogflow API V2beta1 构建一个 Messenger + Google Assistant 机器人。
根据他们的文档,我可以分派(dispatch)一个事件来触发一个意图。我能够成功触发事件,并且 (200) 响应记录在 Firebase Functions 中,但消息永远不会推送到聊天本身。
如何确保将响应推送到当前 session ?
// requries...
const app = express();
const sessionClient = new dialogflow.SessionsClient();
app.post('/detect', (req, res) => {
console.log('handler');
res.header('Content-Type', 'application/json');
res.header('Access-Control-Allow-Headers', 'Content-Type');
res.header('Access-Control-Allow-Origin', 'my-domain');
const bdy = JSON.parse(req.body);
const sessionPath = sessionClient.sessionPath(projectId, bdy.session);
const request = {
session: sessionPath,
queryParams: {
session: sessionPath,
contexts: [{
name: `${sessionPath}/contexts/mycontext`,
lifespan: 5,
parameters: structjson.jsonToStructProto({ 'Model': bdy.model })
}],
},
queryInput: {
event: {
name: 'my_event',
parameters: structjson.jsonToStructProto(
{
Model: bdy.model,
}),
languageCode: languageCode,
},
}
};
// Send request and log result
console.log('md request: ', request);
// here is where the intent is detected, and my handler for that successfully invoked
sessionClient
.detectIntent(request)
.then(responses => {
console.log('event response ', JSON.stringify(responses));
const result = responses[0].queryResult;
if (result.intent) {
res.send(responses);
} else {
console.log(` No intent matched.`);
res.send({ text: 'not match' })
}
})
.catch(err => {
console.error('ERROR:', err);
res.send(err);
});
});
exports.myHandler = functions.https.onRequest(app);
这是我的回复,其中一些参数被混淆了:
[{
"responseId": "c87b3c74-5c74-478b-8a5a-a0b90f059787",
"queryResult": {
"fulfillmentMessages": [{
"platform": "PLATFORM_UNSPECIFIED",
"text": {
"text": ["You you have a BMW X1.\n Next, I just need to know what computer you have"]
},
"message": "text"
}],
"outputContexts": [{
"name": "projects/<my-project>/agent/sessions/<my-session>/contexts/<my-context>",
"lifespanCount": 5,
"parameters": {
"fields": {
"Model.original": {
"stringValue": "",
"kind": "stringValue"
},
"Model": {
"stringValue": "BMW X1",
"kind": "stringValue"
}
}
}
}],
"queryText": "my_event",
"speechRecognitionConfidence": 0,
"action": "",
"parameters": {
"fields": {
"Model": {
"stringValue": "",
"kind": "stringValue"
}
}
},
"allRequiredParamsPresent": true,
"fulfillmentText": "You you have a BMW X1.\n Next, I just need to know what computer you have",
"webhookSource": "",
"webhookPayload": null,
"intent": {
"inputContextNames": [],
"events": [],
"trainingPhrases": [],
"outputContexts": [],
"parameters": [],
"messages": [],
"defaultResponsePlatforms": [],
"followupIntentInfo": [],
"name": "projects/<my-project>/agent/intents/<intent-id>",
"displayName": "my_event",
"priority": 0,
"isFallback": false,
"webhookState": "WEBHOOK_STATE_UNSPECIFIED",
"action": "",
"resetContexts": false,
"rootFollowupIntentName": "",
"parentFollowupIntentName": "",
"mlDisabled": false
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"fields": {
"webhook_latency_ms": {
"numberValue": 6065,
"kind": "numberValue"
}
}
},
"languageCode": "en-us"
},
"webhookStatus": {
"details": [],
"code": 0,
"message": "Webhook execution successful"
}
}]
最佳答案
感谢 Nick Felker 在评论中的评论。
回答:您不能将消息推送到 Google 助理对话中。相反,使用推送通知和类似“我回来了”的回复引导用户回到对话中。
关于actions-on-google - 如何将消息推送到 Dialogflow session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50137291/
我是一名优秀的程序员,十分优秀!