简体   繁体   English

Dialogflow 检测意图实现

[英]Dialogflow Detect Intent Fulfillment

Hi i have created a dialogflow nodejs backend which detects intents using the client library for nodejs.嗨,我创建了一个对话流 nodejs 后端,它使用 nodejs 的客户端库检测意图。

 const sessionPath = this.sessionClient.sessionPath(this.configService.get('dialogFlowProjectId'), sessionId);

        const request = {
            session: sessionPath,
            queryInput: {
                text: {
                    text: query,
                    languageCode: "en-US"
                }
            }
        };
        // Send request and log result
        Logger.log(request);
        const responses = await this.sessionClient.detectIntent(request);

this works fine but I also want to trigger a fulfillment for certain intents.这很好用,但我也想触发某些意图的实现。

I have setup a webhook url - this works fine when you use the chat in the dialogflow console.我已经设置了一个 webhook url - 当您在 dialogflow 控制台中使用聊天时,这可以正常工作。 But when I use the method that I have created to send the request to dialogflow the webhook doesn't get called and goes to fallback intent.但是当我使用我创建的方法将请求发送到 dialogflow 时,webhook 不会被调用并转为回退意图。 I'm calling the same intent through the dialogflow console chat and through my own API.我通过对话流控制台聊天和我自己的 API 调用相同的意图。

How can I trigger the webhook call when I use the client library API?使用客户端库 API 时如何触发 webhook 调用?

First, remember that you don't "call an Intent", either through the test console or through the API.首先,请记住,无论是通过测试控制台还是通过 API,您都不会“调用 Intent”。 What you can do is send query text that should be matched by an Intent.可以做的是发送应与意图匹配的查询文本。

If you have set the Intent so that it should call the Fulfillment webhook, then this should happen no matter the source, as long as the Intent itself is triggered.如果您已设置 Intent 使其应调用 Fulfillment webhook,那么无论来源如何,只要 Intent 本身被触发,就会发生这种情况。

That the Fallback Intent is getting triggered instead suggests that something about the query text isn't matching the Intent you think it should be matching.回退 Intent 正在被触发,这表明查询文本的某些内容与您认为应该匹配的 Intent 不匹配。 I would check to make sure the text you're sending in query should match the training phrases for the Intent in question, that you have no Input Contexts, and that your agent is set for the "en-US" language code.我会检查以确保您在query发送的文本应与相关意图的训练短语匹配,您没有输入上下文,并且您的代理设置为“en-US”语言代码。

For routing multiple intents through a webhook you're going to want to have a handler.js file with an express router in it...要通过 webhook 路由多个意图,您将需要一个 handler.js 文件,其中包含一个快速路由器......

const def = require('./intents/default')
const compression = require('compression')

const serverless = require('serverless-http')
const bodyParser = require('body-parser')

const { WebhookClient } = require('dialogflow-fulfillment')

const express = require('express')
const app = express()

// register middleware
app.use(bodyParser.json({ strict: false }))
app.use(function (err, req, res, next) {
  res.status(500)
  res.send(err)
})
app.use(compression())
app.post('/', async function (req, res) {
  // Instantiate agent
  const agent = new WebhookClient({ request: req, response: res })
  const intentMap = new Map()

  intentMap.set('Default Welcome Intent', def.defaultWelcome)

  await agent.handleRequest(intentMap)
})

module.exports.server = serverless(app)

As you can see, this handler.js is using serverless-http and express.如您所见,此 handler.js 使用 serverless-http 和 express。

Your intent.js function could look something like this ...你的 intent.js 函数可能看起来像这样......

module.exports.defaultWelcome = async function DefaultWelcome (agent) {

  const responses = [
    'Hi! How are you doing?',
    'Hello! How can I help you?',
    'Good day! What can I do for you today?',
    'Hello, welcoming to the Dining Bot. Would you like to know what\'s being served? Example: \'What\'s for lunch at cronkhite?\'',
    'Greetings from Dining Bot, what can I do for you?(Hint, you can ask things like: \'What\'s for breakfast at Annenberg etc..\' or \'What time is breakfast at Anennberg?\')',
    'greetings',
    'hey',
    'long time no see',
    'hello',
    "lovely day isn't it"
  ]
  const index = Math.floor((Math.random() * responses.length) + 1)
  console.log(responses[index].text)
  agent.add(responses[index].text)
}

This gives you the bare bones for routing multiple request through your webhook.这为您提供了通过 webhook 路由多个请求的基础。 Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Dialogflow 以相同的意图完成两个请求 - Dialogflow fulfillment two requests in te same intent 如何通过代码在DialogFlow实现中创建意图? - How to create intent in DialogFlow Fulfillment by code? 如何在 Dialogflow 实现内联中多次使用 web 抓取? 以及如何在履行内联代码中检测错误? - How to use multiple time web scraping in Dialogflow fulfillment inline? and how to detect error at fulfillment inline code? 如何通过上下文检测Intent而不查询Dialogflow中的输入 - How to detect Intent by context and not query input in Dialogflow 实现中的DialogFlow-未定义DeepLink - DialogFlow in Fulfillment - DeepLink is not defined 使用 DialogFlow Messenger 实现中的“agent.setFollowupEvent(targetIntentEventName)”方法跳转到另一个意图 - Jumping over to another intent by using the 'agent.setFollowupEvent(targetIntentEventName)' method in the DialogFlow Messenger fulfillment 对话流意图 - Dialogflow Intent Dialogflow webhook 实现参数无法访问 - Dialogflow webhook fulfillment parameter not accessible 如何在对话流实现中使用 OR 运算符 - How to use OR operator in dialogflow fulfillment 在选项中选择Dialogflow实现 - Dialogflow fulfillment chose among options
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM