javascript - 在 Google Assistant webhook 中创建一个 HttpRequest
问题描述
我是 javascript 新手,我正在尝试使用 Webhook 从我的 Google 助理发出 HTTP 请求。但每次我收到错误:“Webhook 错误(206)”。
回复:
{
"conversationToken": "[]",
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Name is Vasanth and its a Customer assigned to 100100"
}
}
]
}
},
"possibleIntents": [
{
"intent": "assistant.intent.action.TEXT"
}
],
"speechBiasingHints": [
"$alphaname",
"$addrnum",
"$type"
]
}
],
"responseMetadata": {
"status": {
"code": 14,
"message": "Webhook error (206)"
},
"queryMatchInfo": {
"queryMatched": true,
"intent": "fd11e73a-5eda-42db-bb03-27bcf732746a",
"parameterNames": [
"number"
]
}
}
}
调试信息:
{
"response": "Name is Vasanth and its a Customer assigned to 100100",
"expectUserResponse": 1,
"conversationToken": "CiZDIzViMG...",
"audioResponse": "//NExAASoo...",
"debugInfo": {
"assistantToAgentDebug": {
"curlCommand": "curl -v 'https://api.api.ai/api/integrations/google?token=7f1f8a0dddf4439aad4b64c8ffa66b9a' -H 'Content-Type: application/json;charset=UTF-8' -H 'Google-Actions-API-Version: 2' -H 'Authorization: eyJhbGciOiJSUzI1NiIsImtpZCI6IjAyOWYyNjlmM2YwNmFmMWU5M2RhYzY3MDYzOTc3ZjcxM2E3N2YxOWUifQ.eyJhdWQiOiJ0ZXN0Z2EtNjYyNjAiLCJleHAiOjE1MjY1NzEyODMsImlzcyI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbSIsImp0aSI6ImE4ODYwODNlMjliZTJjZGQwYjE1MjRlZWQ1ZDcyYTFjNzc2NDEwY2EiLCJpYXQiOjE1MjY1NzExNjMsIm5iZiI6MTUyNjU3MDg2M30.K7dmTzf63SflHOJjkIwYgRJcsW28yiSTGA_xpBiZZI9mpG4fnswyASO9A4rrFCMvo0jBEr2N02jcqJOxuna5Jix3fu0QiEhGxGCheVhBa1XeCknPDebVbROLLU8gcXDYNVKEii_qFUHI6cbaN4yXtmRPI5pvlQQX3EM0LaR00c-EQSeC5Zw9h52pAZoXibQjapStreML1wnJlZZX67MFHC0J7zryfC1zBscNXVncyFgdyB5-XvT4FttqNKW7sPvyLyXzDqs7-lDU2ePakhetlBEwUpvs4lUUJsxyXepUUKeA3xm8kt9hqgEc2BFhGzuVYmK1wPZGFQj6hd5GO9s4tQ' -A 'Mozilla/5.0 (compatible; Google-Cloud-Functions/2.1; +http://www.google.com/bot.html)' -X POST -d '{\"user\":{\"userId\":\"ABwppHHuDuSoyWPtn6lFGMcKFft017GnKtv7OALV2q7JcqM5YcUOUsOXguR-PInp8At0ceb0kLXcczVZ\",\"locale\":\"en-US\",\"lastSeen\":\"2018-05-17T15:32:02Z\"},\"conversation\":{\"conversationId\":\"1526571142079\",\"type\":\"ACTIVE\",\"conversationToken\":\"[\\\"actions_capability_audio_output\\\",\\\"actions_capability_media_response_audio\\\",\\\"actions_capability_screen_output\\\",\\\"actions_capability_web_browser\\\",\\\"address_book_dialog_context\\\",\\\"address_book_dialog_params_number\\\",\\\"fd11e73a-5eda-42db-bb03-27bcf732746a_id_dialog_context\\\",\\\"google_assistant_input_type_keyboard\\\"]\"},\"inputs\":[{\"intent\":\"actions.intent.TEXT\",\"rawInputs\":[{\"inputType\":\"KEYBOARD\",\"query\":\"100100\"}],\"arguments\":[{\"name\":\"text\",\"rawText\":\"100100\",\"textValue\":\"100100\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}'",
"assistantToAgentJson": "{\"user\":{\"userId\":\"ABwppHHuDuSoyWPtn6lFGMcKFft017GnKtv7OALV2q7JcqM5YcUOUsOXguR-PInp8At0ceb0kLXcczVZ\",\"locale\":\"en-US\",\"lastSeen\":\"2018-05-17T15:32:02Z\"},\"conversation\":{\"conversationId\":\"1526571142079\",\"type\":\"ACTIVE\",\"conversationToken\":\"[\\\"actions_capability_audio_output\\\",\\\"actions_capability_media_response_audio\\\",\\\"actions_capability_screen_output\\\",\\\"actions_capability_web_browser\\\",\\\"address_book_dialog_context\\\",\\\"address_book_dialog_params_number\\\",\\\"fd11e73a-5eda-42db-bb03-27bcf732746a_id_dialog_context\\\",\\\"google_assistant_input_type_keyboard\\\"]\"},\"inputs\":[{\"intent\":\"actions.intent.TEXT\",\"rawInputs\":[{\"inputType\":\"KEYBOARD\",\"query\":\"100100\"}],\"arguments\":[{\"name\":\"text\",\"rawText\":\"100100\",\"textValue\":\"100100\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.SCREEN_OUTPUT\"},{\"name\":\"actions.capability.AUDIO_OUTPUT\"}]}]}"
},
"agentToAssistantDebug": {
"agentToAssistantJson": "{\"conversationToken\":\"[]\",\"expectUserResponse\":true,\"expectedInputs\":[{\"inputPrompt\":{\"richInitialPrompt\":{\"items\":[{\"simpleResponse\":{\"textToSpeech\":\"Name is Vasanth and its a Customer assigned to 100100\"}}]}},\"possibleIntents\":[{\"intent\":\"assistant.intent.action.TEXT\"}],\"speechBiasingHints\":[\"$alphaname\",\"$addrnum\",\"$type\"]}],\"responseMetadata\":{\"status\":{\"code\":14,\"message\":\"Webhook error (206)\"},\"queryMatchInfo\":{\"queryMatched\":true,\"intent\":\"fd11e73a-5eda-42db-bb03-27bcf732746a\",\"parameterNames\":[\"number\"]}}}"
},
"sharedDebugInfoList": []
},
"visualResponse": {
"visualElementsList": [
{
"displayText": {
"content": "Name is Vasanth and its a Customer assigned to 100100"
}
}
],
"suggestionsList": [],
"agentLogoUrl": "https://www.gstatic.com/voice/opa/partner_icons/generic_3p_avatar.png",
"agentStyle": {
"primaryColor": "",
"fontFamily": "",
"borderRadius": 0,
"backgroundColor": "",
"backgroundImageUrl": ""
}
},
"clientError": 0,
"is3pResponse": 1
}
有时我也会遇到错误,例如:“必须设置最终响应”,即使我的对话流中有默认响应。
以下是我的代码:
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const Suggestion = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
const url='MY URL';
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 JDE ASSISTANT');
agent.add('Lets create an address book entry in JD Edwards');
agent.add('Should we create a Customer or a Supplier?');
agent.add(new Suggestion('Customer'));
agent.add(new Suggestion('Supplier'));
}
function createCustomerSupplier(agent){
//Get the input parameters from the user via DialogFlow
const type = agent.parameters.type;
const name = agent.parameters.name;
const addrnum = agent.parameters.number;
var json_req;
if(type== 'C' || type == 'Customer')
{
json_req ={
"inputs":[
{
'name':'Address Number',
'value':addrnum
},
{
'name':'ALPH',
'value':name
},
{
'name':'ADD1',
'value':'ADD1'
},
{
'name':'ADD2',
'value':'ADD2'
} ,
{
'name':'City',
'value':'NJ'
} ,
{
'name':'Country',
'value':'IN'
} ,
{
'name':'AT1',
'value':'C'
}
]
}}
else if(type == 'S' || type == 'Supplier')
{
json_req ={
"inputs":[
{
'name':'Address Number',
'value':addrnum
},
{
'name':'ALPH',
'value':name
},
{
'name':'ADD1',
'value':'ADD1'
},
{
'name':'ADD2',
'value':'ADD2'
} ,
{
'name':'City',
'value':'NJ'
} ,
{
'name':'Country',
'value':'IN'
} ,
{
'name':'AT1',
'value':'V'
}
]
};
}
var strJSON = JSON.stringify(json_req);
var request = new XMLHttpRequest();
request.open("POST",url,true,'user','pwd');
request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
request.send(strJSON);
agent.add("This is the Webhook.Operation successful!!");
}
});
即使我在 webhook 中有一行代码,它也会失败!:(
请让我知道我做错了什么或者我错过了什么?
提前致谢!
解决方案
推荐阅读
- sql-server - 是否可以在从 Power BI 中的 SQL 数据库直接查询之前过滤数据
- javascript - 池连接上的nodejs mysql错误:连接丢失:服务器关闭了连接
- go - 在自动收报机内使用睡眠
- javascript - 在支持负数的同时,以非破坏性方式按属性对对象进行数字排序
- unity3d - Unity 的 .h 库在哪里?
- scala - scala play-json 中动态 json 的读取器和写入器
- hpc - 使用 condor 时如何从环境变量中获取交互式作业的作业 ID?
- javascript - 在定义函数时访问实例的属性
- swift - 数组的内部过滤不会快速过滤
- database-restore - 恢复外部硬盘驱动器上的数据库