在Google智能助理webhook

时间:2018-05-18 10:19:32

标签: javascript actions-on-google

我是javascript的新手,我正在尝试使用Webhook从我的Google智能助理发出HTTP请求。但每次我收到错误:" Webhook错误(206)"。

RESPONSE:



{
  "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中有一行代码,它也会失败! :(

请让我知道我做错了什么或者我错过了什么?。

提前致谢!

0 个答案:

没有答案