जब Actions on Google, Dialogflow v2 की मदद से आपके फ़ुलफ़िलमेंट को शुरू करता है, तो यह सेक्शन JSON पेलोड के फ़ॉर्मैट के बारे में बताता है.
अगर आप कार्रवाइयां बनाने के लिए Dialogflow का इस्तेमाल कर रहे हैं, तो आपका फ़ुलफ़िलमेंट, Actions on Google के बातचीत वाले वेबहुक फ़ॉर्मैट के बजाय, अपने ही स्टैंडर्ड वेबहुक फ़ॉर्मैट की मदद से Dialogflow के साथ काम करता है. Dialogflow वेबहुक फ़ॉर्मैट में, बातचीत के वेबहुक फ़ॉर्मैट की सारी जानकारी होती है. साथ ही, Dialogflow के बारे में ज़्यादा जानकारी देने वाला डेटा भी होता है, जैसे कि कॉन्टेक्स्ट और पैरामीटर के बारे में जानकारी.
Dialogflow वेबहुक के लिए JSON मैसेज के और उदाहरण देखने के लिए, यह GitHub प्रोजेक्ट देखें.
अनुरोध का मुख्य भाग
Dialogflow के request मैसेज में, Dialogflow वेबहुक फ़ॉर्मैट में डेटा होता है. इस ऑब्जेक्ट में, Google की खास जानकारी पर कार्रवाइयां शामिल हैं, जिनकी खास जानकारी यहां दी गई है:
originalDetectIntentRequest.source
की वैल्यू "google" है.originalDetectIntentRequest.version
, अनुरोध के लिए Actions on Google वर्शन के बारे में बताता है.originalDetectIntentRequest.payload
में, खास कार्रवाइयों के बारे में Google से जुड़ी खास जानकारी होती है. इसमें Assistant से बातचीत का अनुरोध JSON भी शामिल होता है.Conversation.conversationToken
फ़ील्ड, Dialogflow वेबहुक के अनुरोधों के साथ काम नहीं करता. इसके बजाय, आपके फ़ुलफ़िलमेंट में बातचीत के पूरे समय में डेटा को बनाए रखने के लिए, Dialogflow context का इस्तेमाल किया जा सकता है.
बातचीत शुरू करने के अनुरोध का आसान उदाहरण
नीचे दिया गया स्निपेट, Dialogflow वेबहुक फ़ॉर्मैट में शुरू करने के अनुरोध का उदाहरण दिखाता है.
{
"responseId": "c4b863dd-aafe-41ad-a115-91736b665cb9",
"queryResult": {
"queryText": "GOOGLE_ASSISTANT_WELCOME",
"action": "input.welcome",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "",
"fulfillmentMessages": [],
"outputContexts": [
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/google_assistant_welcome"
},
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_capability_screen_output"
},
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/google_assistant_input_type_voice"
},
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_capability_audio_output"
},
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_capability_web_browser"
},
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_capability_media_response_audio"
}
],
"intent": {
"name": "projects/${PROJECTID}/agent/intents/8b006880-0af7-4ec9-a4c3-1cc503ea8260",
"displayName": "Default Welcome Intent"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {},
"languageCode": "en-us"
},
"originalDetectIntentRequest": {
"source": "google",
"version": "2",
"payload": {
"isInSandbox": true,
"surface": {
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.WEB_BROWSER"
},
{
"name": "actions.capability.MEDIA_RESPONSE_AUDIO"
}
]
},
"inputs": [
{
"rawInputs": [
{
"query": "Talk to my test app",
"inputType": "VOICE"
}
],
"intent": "actions.intent.MAIN"
}
],
"user": {
"lastSeen": "2018-03-16T22:08:48Z",
"permissions": [
"UPDATE"
],
"locale": "en-US",
"userId": "ABwppHEvwoXs18xBNzumk18p5h02bhRDp_riW0kTZKYdxB6-LfP3BJRjgPjHf1xqy1lxqS2uL8Z36gT6JLXSrSCZ"
},
"conversation": {
"conversationId": "${SESSIONID}",
"type": "NEW"
},
"availableSurfaces": [
{
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
}
]
}
]
}
},
"session": "projects/${PROJECTID}/agent/sessions/${SESSIONID}"
}
बातचीत के अनुरोध का उदाहरण
नीचे दिया गया स्निपेट, Dialogflow वेबहुक फ़ॉर्मैट में बातचीत के अनुरोध का एक उदाहरण दिखाता है, जिसमें उपयोगकर्ता का इनपुट एक टेक्स्ट स्ट्रिंग होती है.
{
"responseId": "68efa569-4ba1-4b7f-9b1b-ac2865deb539",
"queryResult": {
"queryText": "query from the user",
"action": "action.name.of.matched.dialogflow.intent",
"parameters": {},
"allRequiredParamsPresent": true,
"outputContexts": [
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_capability_screen_output"
},
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_capability_audio_output"
},
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/google_assistant_input_type_keyboard"
},
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_capability_media_response_audio"
},
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_capability_web_browser"
}
],
"intent": {
"name": "projects/${PROJECTID}/agent/intents/1f4e5bd9-a670-4161-a22e-2c97b077f29f",
"displayName": "Name of Dialogflow Intent"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {},
"languageCode": "en-us"
},
"originalDetectIntentRequest": {
"source": "google",
"version": "2",
"payload": {
"isInSandbox": true,
"surface": {
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.WEB_BROWSER"
},
{
"name": "actions.capability.MEDIA_RESPONSE_AUDIO"
}
]
},
"inputs": [
{
"rawInputs": [
{
"query": "query from the user",
"inputType": "KEYBOARD"
}
],
"arguments": [
{
"rawText": "query from the user",
"textValue": "query from the user",
"name": "text"
}
],
"intent": "actions.intent.TEXT"
}
],
"user": {
"lastSeen": "2017-10-06T01:06:56Z",
"locale": "en-US",
"userId": "AI_yXq-AtrRh3mJX5D-G0MsVhqun"
},
"conversation": {
"conversationId": "1522951193000",
"type": "ACTIVE",
"conversationToken": "[]"
},
"availableSurfaces": [
{
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
}
]
}
]
}
},
"session": "projects/${PROJECTID}/agent/sessions/${SESSIONID}"
}
हेल्पर नतीजे का उदाहरण
नीचे दिया गया स्निपेट, Dialogflow वेबहुक फ़ॉर्मैट में एक हेल्पर नतीजे का उदाहरण दिखाता है. इस उदाहरण में, उपयोगकर्ता का जवाब तब दिखाया जाता है, जब वेबहुक, Assistant को बताता है कि उसे उपयोगकर्ता से सहमति लेना है.
{
"responseId": "cb6f5ec2-c26e-4349-b561-a9ddd6a0e495",
"queryResult": {
"queryText": "actions_intent_CONFIRMATION",
"action": "Dialogflow action name of matched intent",
"parameters": {},
"allRequiredParamsPresent": true,
"outputContexts": [
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_intent_confirmation",
"parameters": {
"CONFIRMATION": true
}
}
],
"intent": {
"name": "projects/${PROJECTID}/agent/intents/1777d616-a5f7-4838-a9a9-870f2956bd14",
"displayName": "Dialogflow action name of matched intent"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {},
"languageCode": "en-us"
},
"originalDetectIntentRequest": {
"source": "google",
"version": "2",
"payload": {
"isInSandbox": true,
"surface": {},
"inputs": [
{
"rawInputs": [
{
"query": "yes",
"inputType": "VOICE"
}
],
"arguments": [
{
"name": "CONFIRMATION",
"boolValue": true
}
],
"intent": "actions.intent.CONFIRMATION"
}
],
"user": {},
"conversation": {},
"availableSurfaces": []
}
},
"session": "projects/${PROJECTID}/agent/sessions/${SESSIONID}"
}
जवाब का मुख्य भाग
Assistant के लिए आपके फ़ुलफ़िलमेंट एंडपॉइंट से
एचटीटीपी पोस्ट के हेडर में मौजूद Content-Type
, application/json
होना चाहिए.
Dialogflow को भेजा जाने वाला रिस्पॉन्स मैसेज, Dialogflow वेबहुक फ़ॉर्मैट में होना चाहिए.
Assistant से बातचीत करते समय, आम तौर पर आपके जवाब में payload
ऑब्जेक्ट मौजूद होता है, जिसमें "google
" ऑब्जेक्ट शामिल होता है. "google
" पेलोड ऑब्जेक्ट में,
Google की खास जानकारी पर कार्रवाइयां शामिल हैं. इसमें कम से कम एक expectUserResponse
फ़ील्ड होना चाहिए. इसके अलावा, richResponse
या systemIntent
फ़ील्ड भी होना चाहिए.
"google
" पेलोड ऑब्जेक्ट के लिए मुख्य फ़ील्ड की खास जानकारी यहां दी गई है:
फ़ील्ड | ब्यौरा |
---|---|
expectUserResponse |
इससे पता चलता है कि ग्राहक को आइटम भेजने के लिए, उपयोगकर्ता से जवाब मिलने की उम्मीद है या नहीं. इसके लिए, वैल्यू को
true पर और बातचीत को
खत्म करने के लिए false पर सेट करें. |
userStorage |
किसी खास उपयोगकर्ता से जुड़ा स्थायी डेटा सेव करता है. कुल स्टोरेज 10,000 बाइट है. |
richResponse |
इस फ़ील्ड में ऑडियो, टेक्स्ट, कार्ड, सुझाव या स्ट्रक्चर्ड डेटा मौजूद होता है, ताकि Assistant उसे रेंडर कर सके. Actions on Google के लिए रिच रिस्पॉन्स का इस्तेमाल करने के बारे में ज़्यादा जानने के लिए, ज़्यादा बेहतर जवाब देखें. |
systemIntent |
इस फ़ील्ड का स्ट्रक्चर ExpectedInput.possibleIntents जैसा है. अगर फ़ुलफ़िलमेंट के लिए हेल्पर इंटेंट का इस्तेमाल किया गया है, तो आम तौर पर आपके जवाब में systemIntent शामिल होता है. systemIntent के
possibleIntents
फ़ील्ड को
ExpectedIntent
ऑब्जेक्ट पर सेट किया जाना चाहिए. साथ ही, inputValueData फ़ील्ड का नाम बदलकर data किया जाना चाहिए.
|
ExpectedIntent
ऑब्जेक्ट में, आपको ये वैल्यू डालने होती हैं:
- intent: हेल्पर के लिए इंटेंट का नाम, जो यह बताता हो कि उपयोगकर्ता से किस तरह की जानकारी चाहिए.
- data: वैल्यू स्पेसिफ़िकेशन एक स्ट्रिंग होती है जो उस डेटा के बारे में बताती है जो Assistant को हेल्पर का इस्तेमाल करने के लिए ज़रूरी होता है.
उदाहरण के लिए, अगर आपने उपयोगकर्ता की अनुमति मांगी है, तो intent
को
actions.intent.PERMISSSION
पर और data
को
"@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec"
पर सेट करें. साथ ही, उस टाइप के लिए
फ़ील्ड भी सेट करें.
नीचे दी गई सूची, हेल्पर के लिए वैल्यू स्पेसिफ़िकेशन वाली स्ट्रिंग की खास जानकारी देती है. इन्हें
Dialogflow वेबहुक रिस्पॉन्स के लिए, systemIntent
में सेट किया जा सकता है. बातचीत को कंट्रोल करने के लिए, Actions on Google इंटेंट की पूरी सूची देखने के लिए, इंटेंट का रेफ़रंस देखें.
इंटेंट का नाम | Dialogflow इवेंट का नाम | वैल्यू की खास बातें | ब्यौरा |
---|---|---|---|
actions.intent.CONFIRMATION
|
actions_intent_CONFIRMATION |
"@type": "type.googleapis.com/google.actions.v2.ConfirmationValueSpec"
|
उपयोगकर्ता से पुष्टि लेता है (उदाहरण के लिए, हां या नहीं वाले सवाल का जवाब). |
actions.intent.DATETIME
|
actions_intent_DATETIME |
"@type": "type.googleapis.com/google.actions.v2.DateTimeValueSpec"
|
उपयोगकर्ता से तारीख और समय का इनपुट लेता है. |
actions.intent.DELIVERY_ADDRESS
|
actions_intent_DELIVERY_ADDRESS |
"@type": "type.googleapis.com/google.actions.v2.DeliveryAddressValueSpec"
|
उपयोगकर्ता से डिलीवरी के पते का इनपुट लेता है. |
actions.intent.LINK
|
actions_intent_LINK |
"@type": "type.googleapis.com/google.actions.v2.LinkValueSpec"
|
यह किसी Android ऐप्लिकेशन में डीप लिंक फ़्लो का अनुरोध करता है. |
actions.intent.OPTION
|
actions_intent_OPTION |
"@type": "type.googleapis.com/google.actions.v2.OptionValueSpec"
|
किसी सूची या कैरसेल यूज़र इंटरफ़ेस (यूआई) से चुना गया आइटम लेता है. |
actions.intent.PERMISSION
|
actions_intent_PERMISSION |
"@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec"
|
उपयोगकर्ता की जानकारी इकट्ठा करता है. इसमें पूरा नाम, अनुमानित जगह या जगह की सटीक जानकारी शामिल है. |
actions.intent.SIGN_IN
|
actions_intent_SIGN_IN |
"@type": "type.googleapis.com/google.actions.v2.SignInValueSpec"
|
किसी उपयोगकर्ता के खाता लिंक करने के लिए खाता लिंक करने के फ़्लो का अनुरोध करता है. |
जवाब के सामान्य उदाहरण
नीचे दिया गया स्निपेट, Dialogflow वेबहुक फ़ॉर्मैट में एक आसान जवाब का उदाहरण दिखाता है.
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "this is a simple response"
}
}
]
}
}
}
}
हेल्पर उदाहरण
नीचे दिया गया स्निपेट, Dialogflow वेबहुक फ़ॉर्मैट में हेल्पर इंटेंट को इस्तेमाल करने का एक उदाहरण दिखाता है. इस उदाहरण में, Assistant को दो विकल्पों में से कोई उपयोगकर्ता चुनने का निर्देश देने के लिए, आपका वेबहुक actions.intent.OPTIONS
हेल्पर इंटेंट का इस्तेमाल कर रहा है.
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Choose a item"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.OPTION",
"data": {
"@type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
"listSelect": {
"title": "Hello",
"items": [
{
"optionInfo": {
"key": "first title key"
},
"description": "first description",
"image": {
"url": "/assistant/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"accessibilityText": "first alt"
},
"title": "first title"
},
{
"optionInfo": {
"key": "second"
},
"description": "second description",
"image": {
"url": "https://lh3.googleusercontent.com/Nu3a6F80WfixUqf_ec_vgXy_c0-0r4VLJRXjVFF_X_CIilEu8B9fT35qyTEj_PEsKw",
"accessibilityText": "second alt"
},
"title": "second title"
}
]
}
}
}
}
}
}
पिछले उदाहरण में मैसेज मिलने पर, Assistant कुछ समय के लिए बातचीत को अपने हाथ में लेती है और उपयोगकर्ता को दिए गए विकल्पों के आधार पर विकल्प चुनने का निर्देश देती है. उपयोगकर्ता से सभी ज़रूरी इनपुट इकट्ठा करने के बाद, Assistant इस हेल्पर नतीजे को Dialogflow के वेबहुक अनुरोध में आपके फ़ुलफ़िलमेंट के लिए भेजती है.
नीचे दिए गए स्निपेट में, उपयोगकर्ता की पसंद को चुनने वाले हेल्पर नतीजे का उदाहरण दिया गया है.
{
"responseId": "ea166558-615a-48f3-ae5b-7f55d895784b",
"queryResult": {
"queryText": "actions_intent_OPTION",
"action": "",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "",
"fulfillmentMessages": [],
"outputContexts": [
{
"name": "projects/${PROJECTID}/agent/sessions/${SESSIONID}/contexts/actions_intent_option",
"parameters": {
"OPTION": "key of selected item"
}
}
],
"intent": {
"name": "projects/${PROJECTID}/agent/intents/1777d616-a5f7-4838-a9a9-870f2956bd14",
"displayName": "Dialogflow intent name of matched intent"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {},
"languageCode": "en-us"
},
"originalDetectIntentRequest": {
"source": "google",
"version": "2",
"payload": {
"isInSandbox": true,
"surface": {
"capabilities": []
},
"inputs": [
{
"rawInputs": [
{
"query": "Title of selected item",
"inputType": "TOUCH"
}
],
"arguments": [
{
"textValue": "Key of selected item",
"name": "OPTION"
}
],
"intent": "actions.intent.OPTION"
}
],
"user": {},
"conversation": {},
"availableSurfaces": []
}
},
"session": "projects/${PROJECTID}/agent/sessions/${SESSIONID}"
}
बातचीत खत्म करने का उदाहरण
नीचे दिया गया स्निपेट, बातचीत के सेशन को Dialogflow वेबहुक फ़ॉर्मैट में खत्म करने के लिए आसान रिस्पॉन्स का एक उदाहरण दिखाता है. जवाब के तौर पर दिए गए मैसेज में मौजूद, false
की
expectUserResponse
वैल्यू से Assistant को यह पता चलता है कि आगे और उपयोगकर्ता के इनपुट की ज़रूरत नहीं है. साथ ही, इससे मौजूदा बातचीत खत्म हो जानी चाहिए.
{
"payload": {
"google": {
"expectUserResponse": false,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Goodbye!"
}
}
]
}
}
}
}
Assistant के साथ बातचीत खत्म करने के लिए, जब उपयोगकर्ता किसी स्टैंडर्ड वाक्यांश का इस्तेमाल करते हैं, तब डिफ़ॉल्ट व्यवहार को बदलने का तरीक़ा जानने के लिए बातचीत से बाहर निकलने की गाइड देखें.