2

What do i want?

  • Directly insert data from dialogflows fulfillment into firebase database (requires userId)

  • i only want to know: Use parameters within triggered intents (e.g. the name of the user). Example: User writes "Hello" (in the app) and chatbot answers "Hello John" like in Googles description

What i've so far:

I've a kind of chat app where the user could chat with other users and/or a chatbot (using dialogflow).

Within firebase cloud functions the app sends a request to dialogflow incl. context with parameter:

function sendToDialogflow(uid) {
    const sessionId = '<SESSION_ID>';
    const sessionClient = new dialogflow.SessionsClient();
    const projectId = '<PROJECT_ID>';
    const sessionPath = sessionClient.sessionPath(projectId, sessionId);

    const request = {
        session: sessionPath,
        queryParams: {
            contexts: [{
                name: `projects/${projectId}/agent/sessions/${sessionId}/contexts/userId`,
                lifespanCount: 2,
                parameters: {
                    uid: uid,
                }
            }]
        },
        queryInput: {
            text: {
                text: text,
                languageCode: 'en-US',
            },
        },
    };
    sessionClient.detectIntent(request).then((response) => {
        const result = response[0].queryResult.fulfillmentText;
    });
}

The given context does work.

My current solution to insert data into firebase by using promise (in firebase cloud functions) but it seems to be very slow (waiting up to 20 sec for response):

sessionClient.detectIntent(request).then((response) => {
    const result = response[0].queryResult.fulfillmentText;
    return admin.database().ref('message').push({
        fromUid: '<bots id>',
        toUid: uid,
        text: result
    }).catch((error) => {
        console.log(error);
    });
});
andre_hold
  • 562
  • 8
  • 20
  • Trying to understand your problem. Why do you want to set the Intent parameter to some value from the context parameter? Have you tried changing the Intent parameter name to something besides "uid" (or at least something besides the same parameter name as in the Context)? Have you tried setting a Context lifespan greater than 1? – Prisoner Feb 07 '19 at 02:03
  • @Prisoner thx for your questions/hinds. I've edit the text above due to some of your question. 1st: I want to send e.g. the username (as parameter) and want to use the name in the (intent) response. 2nd: I've test with some other parameter names besides "uid" and another name for intent parameter than the context parameter. 3rd: I've test with lifespan 2 and 5. the result ist the same. In my question above headline "what i want" i've added a snippet from "telegram bot" (connected with my agent). there's a chatId within the outputContext parameter. – andre_hold Feb 07 '19 at 09:30
  • I'm very confused about what you're doing and seeing. In one place you're talking about using the Detect Intent API, which suggests you're building a client. In another, you're talking about using Telegram as the client. In another you're talking about using fulfillment to do something. In some cases you're talking about using responses, in others doing something in fulfillment (which typically builds its own responses). Having a clear flow and example of what you're trying to do and what isn't working or what you're seeing will help a great deal. – Prisoner Feb 07 '19 at 10:12
  • @Prisoner sorry for the confusion. i try to clearify: telegram was only for testing purposes. I've an app client. I'll only use fulfillment. I want to send some parameter to the agent and use this parameter in fulfillment (prio 1) and i'm ready to throw away all my ideas and thoughts, for a solution :) – andre_hold Feb 07 '19 at 10:34
  • Ok, but you mentioned a telegram ID. My suggestion would be to update your question to clarify. Add a section showing exactly what you expect things to do - what the user does and then how you want to reply. And then show what you've tried and what it is doing instead of working. Right now, all of that may be in your question, but it is hard to sort out and put together. – Prisoner Feb 07 '19 at 10:39
  • @Prisoner i hope i clearify my question. – andre_hold Feb 07 '19 at 13:17

1 Answers1

1

After spending some hours on that problem, i still found out, that the mistake was at the payload (with parameter) from my firebase cloud function that triggers dialogflow. Thanks to @matthewayne answer here, i've to use jsonToStructProto (file) to convert the parameter in another format (proto struct).

the new request looks like

const request = {
    session: sessionPath,
    queryParams: {
        contexts: [{
                name: `projects/${projectId}/agent/sessions/${sessionId}/contexts/testId`,
                lifespanCount: 2,
                parameters: structjson.jsonToStructProto({foo: 'bar'}),
            }
        ]
    },
    queryInput: {
        text: {
            text: text,
            // The language used by the client (en-US)
            languageCode: 'de-DE',
        },
    },
};

Now it is possible to get the parameter at the dialogflow console:

#testId.foo

or at fulfillment:

agent.contexts['testId'].parameters

andre_hold
  • 562
  • 8
  • 20