लागू करने से जुड़ी सलाह (Dialogflow)

बातचीत डिज़ाइन के अच्छे तरीकों को लागू करने के लिए, नीचे दी गई सलाह देखें ऐक्शन में शामिल करें.

इसमें बदलाव हो सकते हैं

इसे "उपयोगकर्ता का कहना है" में मैनेज करना Dialogflow में इनपुट करें. साथ ही, एक से ज़्यादा रिपोर्ट का इस्तेमाल करें इंटेंट जो उसी कार्रवाई पर मैप कर सकता है, जहां हर इंटेंट इससे ट्रिगर हो सकता है "उपयोगकर्ता ने कहा" के अलग-अलग सेट वाक्यांश शामिल हैं.

मदद के लिए प्रॉम्प्ट सबमिट करें और ग्रेसफ़ुल तरीके से फ़ेल करें

कभी-कभी आपकी सेट की गई कार्रवाई को आगे नहीं बढ़ाया जा सकता, क्योंकि उसे कोई इनपुट नहीं मिला (जिसे नो-इनपुट कहा जाता है) या उपयोगकर्ता का इनपुट समझ नहीं आता था (जिसे नो-मैच कहा जाता है). ऐसा होने पर, Assistant सबसे पहले यह पता करने की कोशिश करती है कि उपयोगकर्ता की अनुमति चाहिए या नहीं का इस्तेमाल करें. अगर Assistant, उपयोगकर्ता के इनपुट से मेल नहीं खाती है दूसरी कार्रवाई से, उपयोगकर्ता आपकी कार्रवाई के संदर्भ में जारी रखता है. ऐसी स्थिति कभी भी आ सकती है, इसलिए सबसे सही तरीका यह है कि फ़ॉलबैक के साथ, बातचीत के हर चरण में, इनपुट नहीं मिलने और मैच न होने की स्थितियों की जानकारी देती है. फ़ॉलबैक का इस्तेमाल करके, उपयोगकर्ताओं को वापस ट्रैक पर लाने में मदद की जा सकती है.

ऐसा करने के लिए, अपने conv.data ऑब्जेक्ट में fallbackCount वैरिएबल शुरू करें, और 0 पर सेट करें. दो फ़ॉलबैक प्रॉम्प्ट का कलेक्शन तैयार करें (जो साफ़ तौर पर आगे बढ़ रहे हैं), और एक आखिरी फ़ॉलबैक प्रॉम्प्ट जिससे बातचीत खत्म हो जाती है.

इसके बाद, एक फ़ॉलबैक इंटेंट बनाएं (आम तौर पर, एजेंट). इंटेंट हैंडलर में, conv.data से फ़ॉलबैक काउंट पाएं ऑब्जेक्ट को बढ़ाने के लिए, उसे बढ़ाएं और अगर यह तीन से कम है, तो अरे से प्रॉम्प्ट तीन में से. अगर गिनती चार या उससे ज़्यादा है, तो आखिरी प्रॉम्प्ट. ऐसे सभी इंटेंट में जो फ़ॉलबैक नहीं हैं, फ़ॉलबैक की गिनती को 0 पर रीसेट करें. आम तौर पर, उन मकसद के हिसाब से फ़ॉलबैक का टेंप्लेट बनाएं जिन्हें उन मकसद के लिए बनाया गया है.

Node.js

const GENERAL_FALLBACK = [
   'Sorry, what was that?',
   'I didn\'t quite get that. I can help you find good local restaurants, what do you want to know about?',
];

const LIST_FALLBACK = [
   'Sorry, what was that?',
   'I didn\'t catch that. Could you tell me which one you prefer?',
];

const FINAL_FALLBACK = 'I\'m sorry I\'m having trouble here. Let\'s talk again later.';

const handleFallback = (conv, promptFetch, callback) => {
 conv.data.fallbackCount = parseInt(conv.data.fallbackCount, 10);
 conv.data.fallbackCount++;
 if (conv.data.fallbackCount > 2) {
   conv.close(promptFetch.getFinalFallbackPrompt());
 } else {
   callback();
 }
}
// Intent handlers below
const generalFallback = (conv) => {
  handleFallback = (conv, promptFetch, () => {
    conv.ask(GENERAL_FALLBACK[conv.data.fallbackCount],
      getGeneralNoInputPrompts());
 });
}

const listFallback = (conv) => {
  handleFallback = (conv, promptFetch, () => {
   conv.ask(LIST_FALLBACK[conv.data.fallbackCount],
       getGeneralNoInputPrompts());
 });
}

const nonFallback = (conv) => {
  conv.data.fallbackCount = 0;
  conv.ask('A non-fallback message here');
}

Java

private static final List<String> GENERAL_FALLBACK =
    Arrays.asList(
        "Sorry, what was that?",
        "I didn\'t quite get that. I can tell you all about IO, like date or location, or about the sessions. What do you want to know about?");
private static final List<String> LIST_FALLBACK =
    Arrays.asList(
        "Sorry, what was that?",
        "I didn\'t catch that. Could you tell me which one you liked?");
private static final List<String> FINAL_FALLBACK =
    Arrays.asList("I\'m sorry I\'m having trouble here. Maybe we should try this again later.");

@ForIntent("General Fallback")
public ActionResponse generalFallback(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  int fallbackCount = (Integer) request.getConversationData().get("fallbackCount");
  fallbackCount++;
  request.getConversationData().put("fallbackCount", fallbackCount);
  if (fallbackCount > 2) {
    responseBuilder.add(getRandomPromptFromList(FINAL_FALLBACK)).endConversation();
  } else {
    responseBuilder.add(getRandomPromptFromList(GENERAL_FALLBACK));
  }
  return responseBuilder.build();
}

private String getRandomPromptFromList(List<String> prompts) {
  Random rand = new Random();
  int i = rand.nextInt(prompts.size());
  return prompts.get(i);
}

@ForIntent("List Fallback")
public ActionResponse listFallback(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  int fallbackCount = (Integer) request.getConversationData().get("fallbackCount");
  fallbackCount++;
  request.getConversationData().put("fallbackCount", fallbackCount);
  if (fallbackCount > 2) {
    responseBuilder.add(getRandomPromptFromList(FINAL_FALLBACK)).endConversation();
  } else {
    responseBuilder.add(getRandomPromptFromList(LIST_FALLBACK));
  }
  return responseBuilder.build();
}

@ForIntent("Non Fallback")
public ActionResponse nonFallback(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  request.getConversationData().put("fallbackCount", 0);
  responseBuilder.add("Non Fallback message");
  return responseBuilder.build();
}

किसी भी समय मदद के लिए तैयार रहें

एक ऐसा इंटेंट बनाएं जो मददगार वाक्यांशों को सुनकर जवाब दे. जैसे, "मैं क्या करूं?", "तुम मुझे क्या बता सकती हो" या "मदद करो". इस इंटेंट में, कुछ ऑफ़र (घुमावदार) रिस्पॉन्स से यह खास जानकारी मिलती है कि एजेंट क्या कर सकता है. साथ ही, लोगों को कार्रवाई नहीं कर सकते. आम तौर पर, Dialogflow में फ़ॉलो-अप सहायता इंटेंट का इस्तेमाल इन कामों के लिए किया जा सकता है कार्रवाई करने के अलग-अलग इंटेंट के लिए, अलग-अलग सहायता हालात बनाएं.

Node.js

const HELP_PROMPTS = [
   'There\'s a lot you might want to know about the local restaurants, and I can tell you all about it, like where it is and what kind of food they have. What do you want to know?',
   'I\'m here to help, so let me know if you need any help figuring out where or what to eat. What do you want to know?',
];

// Intent handler
const help = (conv) => {
 reply(conv, promptFetch.getHelpPrompt(), // fetches random entry from HELP_PROMPTS
     promptFetch.getGeneralNoInputPrompts());
}

Java

private static final List<String> HELP_PROMPTS =
    Arrays.asList(
        "There's a lot you might want to know about IO, and I can tell you all about it, like where it is and what the sessions are. What do you want to know?",
        "IO can be a little overwhelming, so I\'m here to help. Let me know if you need any help figuring out the event, like when it is, or what the sessions are. What do you want to know?");

@ForIntent("Help")
public ActionResponse help(ActionRequest request) {
  return getResponseBuilder(request).add(getRandomPromptFromList(HELP_PROMPTS)).build();
}

उपयोगकर्ताओं को जानकारी को फिर से चलाने की अनुमति दें

अपने सभी app.ask(output) तरीकों को किसी ऐसे प्रॉक्सी फ़ंक्शन से रैप करें जो आपके मौजूदा conv.data.lastPrompt के लिए आउटपुट. ध्यान से दोहराने के लिए एक इंटेंट बनाएं उपयोगकर्ता से दोहराने के लिए कहा जाता है, जैसे "क्या?" "एक बार फिर से कहो" या "क्या तुम फिर से कहो?". दोहराए जाने वाले प्रीफ़िक्स का कलेक्शन बनाएं, जिसका इस्तेमाल इन कामों के लिए किया जा सके यह स्वीकार करें कि उपयोगकर्ता ने कुछ दोहराने के लिए कहा है. बार-बार इंटेंट हैंडलर, दोहराए गए प्रीफ़िक्स की जुड़ी हुई स्ट्रिंग के साथ ask() को कॉल करें और conv.data.lastPrompt की वैल्यू डालें. यह ध्यान रखें कि आपको अगर आखिरी प्रॉम्प्ट में इस्तेमाल किया गया है, तो एसएसएमएल टैग खोलने का तरीका.

Node.js

const REPEAT_PREFIX = [
    'Sorry, I said ',
    'Let me repeat that. ',
];

const reply = (conv, inputPrompt, noInputPrompts) => {
  conv.data.lastPrompt = inputPrompt;
  conv.data.lastNoInputPrompts = noInputPrompts;
  conv.ask(inputPrompt, noInputPrompts);
}
// Intent handlers
const normalIntent = (conv) => {
  reply(conv, 'Hey this is a question', SOME_NO_INPUT_PROMPTS);
}

const repeat = (conv) => {
  let repeatPrefix = promptFetch.getRepeatPrefix(); // randomly chooses from REPEAT_PREFIX
  // Move SSML start tags over
  if (conv.data.lastPrompt.startsWith(promptFetch.getSSMLPrefix())) {
    conv.data.lastPrompt =
        conv.data.lastPrompt.slice(promptFetch.getSSMLPrefix().length);
    repeatPrefix = promptFetch.getSSMLPrefix() + repeatPrefix;
  }
  conv.ask(repeatPrefix + conv.data.lastPrompt,
      conv.data.lastNoInputPrompts);
}

Java

private final List<String> REPEAT_PREFIX = Arrays.asList("Sorry, I said ", "Let me repeat that.");

private final String SsmlPrefix = "<speak>";

@ForIntent("Normal Intent")
public ActionResponse normalIntent(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  responseBuilder.getConversationData().put("lastPrompt", "Hey this is a question");
  return responseBuilder.build();
}

@ForIntent("repeat")
public ActionResponse repeat(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  String repeatPrefix = getRandomPromptFromList(REPEAT_PREFIX);
  // Move SSML start tags over
  String lastPrompt = (String) responseBuilder.getConversationData().get("lastPrompt");
  if (lastPrompt.startsWith(SsmlPrefix)) {
    String newLastPrompt = lastPrompt.substring(SsmlPrefix.length());
    responseBuilder.getConversationData().put("lastPrompt", newLastPrompt);
    repeatPrefix = SsmlPrefix + repeatPrefix;
  }
  responseBuilder.add(repeatPrefix + lastPrompt);
  return responseBuilder.build();
}

बातचीत को उपयोगकर्ता की प्राथमिकताओं के हिसाब से बनाएं

आपकी सेट की गई कार्रवाई में, उपयोगकर्ताओं से उनकी प्राथमिकताएं पूछी जा सकती हैं. साथ ही, उन्हें याद रखा जा सकता है का इस्तेमाल किया जा सकता है. इससे आपको उस उपयोगकर्ता के साथ आने वाले समय में होने वाली बातचीत को आपके हिसाब से बनाने में मदद मिलती है.

यह उदाहरण, उपयोगकर्ताओं को पिन कोड के लिए मौसम की रिपोर्ट देता है. नीचे दिए गए उदाहरण के तौर पर दिया गया कोड उपयोगकर्ता से पूछता है कि क्या कार्रवाई में उसका पिन याद रखा जाए बाद की बातचीत के लिए कोड.

Node.js

app.intent('weather_report', (conv) => {
  let zip = conv.arguments.get('zipcode');
  conv.data.zip = zip;
  conv.ask(getWeatherReport(zip));
  conv.ask(new Confirmation(`Should I remember ${zip} for next time?`));
});

app.intent('remember_zip', (conv, params, confirmation) => {
  if (confirmation) {
    conv.user.storage.zip = conv.data.zip;
    conv.close('Great! See you next time.');
  } else conv.close('Ok, no problem.');
});

Java

@ForIntent("weather_report")
public ActionResponse weatherReport(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  String zip = (String) request.getArgument("location").getStructuredValue().get("zipCode");
  responseBuilder.getConversationData().put("zip", zip);
  responseBuilder.add(getWeatherReport(zip));
  responseBuilder.add(
      new Confirmation().setConfirmationText("Should I remember " + zip + " for next time?"));
  return responseBuilder.build();
}

@ForIntent("remember_zip")
public ActionResponse rememberZip(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  if (request.getUserConfirmation()) {
    responseBuilder.getUserStorage().put("zip", responseBuilder.getConversationData().get("zip"));
    responseBuilder.add("Great! See you next time.").endConversation();
  } else {
    responseBuilder.add("Ok, no problem.").endConversation();
  }
  return responseBuilder.build();
}

जब उपयोगकर्ता से पहली बार डायलॉग बॉक्स में उसके पिन कोड के बारे में पूछा जाता था, तब आपको अगली बार कॉल करने पर, प्रॉम्प्ट को छोड़कर आगे बढ़ सकते हैं और उसी पिन कोड का इस्तेमाल कर सकते हैं. आपको अब भी एक एस्केप रूट देना चाहिए (जैसे कि एक सुझाव चिप, जो उन्हें कोई दूसरा पिन कोड चुनने के लिए कहें. हालांकि, ऐसा करने के लिए आपको सामान्य मामले में, आपको एक बहुत ही सहज अनुभव मिलता है.

Node.js

app.intent('weather_report', (conv) => {
  let zip = conv.arguments.get('zipcode');
  if (zip) {
    conv.close(getWeatherReport(zip));
  } else if (conv.user.storage.zip) {
    conv.ask(new SimpleResponse(getWeatherReport(conv.user.storage.zip)));
    conv.ask(new Suggestions('Try another zipcode'));
  } else {
    conv.ask('What\'s your zip code?');
  }
});

app.intent('provide_zip_df', (conv) => {
  conv.user.storage.zip = conv.arguments.get('zipcode');
  conv.close(getWeatherReport(conv.user.storage.zip));
});

Java

public ActionResponse weatherReport2(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  String zip = (String) request.getArgument("location").getStructuredValue().get("zipCode");
  if (zip != null) {
    responseBuilder.add(getWeatherReport(zip)).endConversation();
  } else if ((zip = (String) responseBuilder.getUserStorage().get("zip")) != null) {
    responseBuilder.add(new SimpleResponse().setTextToSpeech(getWeatherReport(zip)));
    responseBuilder.add(new Suggestion().setTitle("Try another zipcode"));
  } else {
    responseBuilder.add("What's your zip code?");
  }
  return responseBuilder.build();
}

लौटने वाले उपयोगकर्ताओं के लिए पसंद के मुताबिक बनाएं

बातचीत के बीच सही स्थिति बनाए रखने से यह ज़्यादा स्वाभाविक होती है लौटने वाले उपयोगकर्ताओं के अनुभव को बेहतर बनाना. इस अनुभव को तैयार करने का पहला कदम यह है कि वापस लौटने वाले उपयोगकर्ताओं का अलग तरीक़े से स्वागत करें. उदाहरण के लिए, आप अभिवादन को टैप कर सकते हैं या पिछली बातचीत के आधार पर काम की जानकारी दिखाना. ऐसा करने के लिए, आने वाली AppRequest.User lastSeen प्रॉपर्टी, ताकि यह पता लगाया जा सके कि उपयोगकर्ता आपकी सेट की गई कार्रवाई के साथ पहले इंटरैक्ट किया हो. अगर lastSeen प्रॉपर्टी शामिल है अनुरोध पेलोड में, अभिवादन के लिए किसी दूसरे ग्रीटिंग मैसेज का इस्तेमाल किया जा सकता है.

नीचे दिया गया कोड कोड पाने के लिए, Node.js क्लाइंट लाइब्रेरी का इस्तेमाल करता है last.seen.

Node.js

// This function is used to handle the welcome intent
// In Dialogflow, the Default Welcome Intent ('input.welcome' action)
// In Actions SDK, the 'actions.intent.MAIN' intent
const welcome = (conv) => {
  if (conv.user.last.seen) {
    conv.ask(`Hey you're back...`);
  } else {
    conv.ask('Welcome to World Cities Trivia!...');
  }
}

Java

// This function is used to handle the welcome intent
// In Dialogflow, the Default Welcome Intent ('input.welcome' action)
// In Actions SDK, the 'actions.intent.MAIN' intent
public ActionResponse welcome(ActionRequest request) {
  ResponseBuilder responseBuilder = getResponseBuilder(request);
  if (request.getUser().getLastSeen() != null) {
    responseBuilder.add("Hey you're back...");
  } else {
    responseBuilder.add("Welcome to Number Genie!...");
  }
  return responseBuilder.build();
}

इस अभिवादन को और बेहतर बनाया जा सकता है. ऐसा करने के लिए, जवाब को असल मैसेज के हिसाब से तैयार किया जा सकता है lastSeen की वैल्यू. उदाहरण के लिए, जिन उपयोगकर्ताओं का अंतिम इंटरैक्शन कई बार हुआ था कई महीने पहले की बातचीत जिन्होंने एक दिन पहले कार्रवाई का इस्तेमाल किया.

बातचीत में आवाज़ को कंट्रोल करने की सुविधा

Assistant, उन डिवाइसों पर उपयोगकर्ताओं को डिवाइस का वॉल्यूम कंट्रोल करने की सुविधा देती है जिन पर यह सुविधा काम करती है. "आवाज़ बढ़ाओ" या " आवाज़ को 50 प्रतिशत पर सेट करो". अगर आपके पास ऐसे इंटेंट हैं जो मिलते-जुलते ट्रेनिंग वाक्यांशों को हैंडल करते हैं, आपके इंटेंट को प्राथमिकता दी जाती है. हमारा सुझाव है कि Assistant को ये काम करने दें उपयोगकर्ता अनुरोध कैसे करें, जब तक कि आपकी सेट की गई कार्रवाई की कोई खास वजह न हो.