如何在Dialogflow V2beta1中区分文本/音频来源及不同终端机器人
Got it, I've run into this exact issue before when migrating from Dialogflow V1 to V2beta1. The good news is there's a reliable way to distinguish between audio-based (Alexa/Google Home) and text-based bots, even though the old numeric message enum from V1 is gone.
How to Distinguish Bot Types in Dialogflow V2beta1
Check the
originalDetectIntentRequest.sourcefield
This string field directly identifies the originating platform. For example:"google"for Google Assistant devices (including audio-only ones like Google Home)"alexa"for Alexa-enabled voice devices"dialogflowMessenger","slack","telegram"(text mode) for text-based bots that support Rich Responses
Dig into
originalDetectIntentRequest.payloadfor granular device details
For audio platforms, the payload adds context to confirm device capabilities:- For Google Assistant, look for
payload.surface.capabilities— if it includesactions.capabilities.AUDIO_OUTPUT, you can be sure it's an audio-only device that can't render Rich Responses. - Alexa's payload follows the Alexa Skills Kit request format, with fields like
request.type(e.g.,"LaunchRequest") that clearly signal voice-first interactions.
- For Google Assistant, look for
Build response logic with source mapping
Add a simple check in your webhook code to categorize platforms and serve appropriate responses:const isAudioOnlyBot = (source) => { return ["google", "alexa"].includes(source); }; const supportsRichResponses = (source) => { return ["dialogflowMessenger", "slack", "telegram"].includes(source); };Use these functions to skip Rich Responses for audio bots, and include them for text-based platforms.
Key Note
V2beta1 replaces V1's numeric message enum with platform-specific string sources and payloads. It's more verbose, but it gives you finer control over different device types beyond just audio vs text.
内容的提问来源于stack exchange,提问作者Jefftopia

