Google Assistant Webhook发送HTTP请求时遭遇206错误求助
Hey there, let's break down what's causing that "Webhook error (206)" and fix it step by step.
First, let's look at the root of the issue: Google Assistant expects your Webhook to return a strictly formatted JSON response that follows its Actions on Google v2 spec. When it doesn't get that, it throws errors like this one. Let's dig into your debug data to spot the issues:
Key Problems in Your Response
Looking at the agentToAssistantJson from your debug info, two critical issues jump out:
- Missing
possibleIntentsfield: When you setexpectUserResponse: true, Google requires you to specify which intents the user can trigger next. Your response doesn't include this array, which breaks the spec. - Empty
conversationToken: You're resetting the conversation token to an empty array, which wipes out all session context. This can confuse the Assistant about the state of the conversation.
Fixes to Apply
Let's adjust your Webhook response to fix these issues. Here's what a valid response should look like, tailored to your use case:
{ "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\"]", "expectUserResponse": true, "expectedInputs": [ { "inputPrompt": { "richInitialPrompt": { "items": [ { "simpleResponse": { "textToSpeech": "Name is Vasanth and its a Customer assigned to 100100" } } ] } }, "possibleIntents": [ { "intent": "assistant.intent.action.TEXT" } ] } ] }
Step-by-Step Implementation Tips
If you're using Node.js/Express for your Webhook, here's how to code this correctly:
const express = require('express'); const app = express(); app.use(express.json()); app.post('/webhook', (req, res) => { // Keep the original conversation token from the incoming request const conversationToken = req.body.conversation.conversationToken; const response = { conversationToken: conversationToken, expectUserResponse: true, expectedInputs: [ { inputPrompt: { richInitialPrompt: { items: [ { simpleResponse: { textToSpeech: "Name is Vasanth and its a Customer assigned to 100100" } } ] } }, // Add the required possibleIntents array possibleIntents: [ { intent: "assistant.intent.action.TEXT" } ] } ] }; // Make sure to send a 200 OK status code (not 206!) res.status(200).json(response); }); app.listen(3000, () => console.log('Webhook server running on port 3000'));
Final Checks
- Verify HTTP Status Code: Your Webhook must return a
200 OKstatus code. If your server is returning206 Partial Contentfor any reason, that's a direct cause of the error. - Validate JSON Structure: Use a tool like JSONLint to check for syntax errors (missing commas, unescaped quotes, etc.).
- Preserve Session Context: Never reset the
conversationTokenunless you intentionally want to start a new conversation.
These changes should resolve the Webhook error and get your Google Assistant integration working as expected.
内容的提问来源于stack exchange,提问作者Vasanth Kumar

