在Dialogflow中触发意图?(使用V2 api)

时间:2018-06-11 05:28:38

标签: dialogflow

如何在Dialogflow中触发意图?我需要在没有用户响应的情况下触发意图。我知道我们需要在这里召集一个活动,但是不知道如何在V2 api中做同样的活动?

2 个答案:

答案 0 :(得分:0)

您只需要深入了解一下API参考:QueryInput描述了hereEventInput您正在寻找here

答案 1 :(得分:-1)

您可以通过dialogflow触发事件,detectIntent

很容易
const dialogflow = require('dialogflow');
const config = require('../config');
// Import the JSON to gRPC struct converter

const credentials = {
    client_email: config.GOOGLE_CLIENT_EMAIL,
    private_key: config.GOOGLE_PRIVATE_KEY,
};

const sessionClient = new dialogflow.SessionsClient(
    {
        projectId: config.GOOGLE_PROJECT_ID,
        credentials
    }
);


module.exports = {

    async sendEventToDialogFlow(event, params = {}) {
        const sessionPath = sessionClient.sessionPath(config.GOOGLE_PROJECT_ID, sessionId);
        const request = {
            session: sessionPath,
            queryInput: {
                event: {
                    name: event,
                    languageCode: config.DF_LANGUAGE_CODE,
                },
            }
        };
        const responses = await sessionClient.detectIntent(request);
        return responses[0].queryResult;
    }

}