Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set parameters in EventInput in Dialogflow V2 API

I desperatly try to set parameters in a

dialogflow.types.EventInput

in python.

This doc says the parameters need to be of type Struct.

I read here that the parameters needs to be a google.protobuf.Struct. But it does not work for me.

Is there another Struct type equivalent in python?

If i send the EventInput without parameters, the intent is detected correctly.

I tried this so far:

import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()

session = session_client.session_path(project_id, session_id)
parameters = struct_pb2.Struct()
parameters['given-name'] = 'Jeff'
parameters['last-name'] = 'Bridges'

event_input = dialogflow.types.EventInput(         
    name='greetPerson',
    language_code='de',
    parameters=parameters)

query_input = dialogflow.types.QueryInput(event=event_input)

response = session_client.detect_intent(
    session=session, query_input=query_input)

Anybody having experience with this usecase?

Things i also tried:

  1. Pass a class named p yields:

    Parameter to MergeFrom() must be instance of same class: expected Struct got p. for field EventInput.parameters

  2. Pass a dict:

    parameters = {
        'given-name': 'Jeff',
        'last-name': 'Bridges'} 
    

    yields:

    Protocol message Struct has no "given-name" field.

  3. Generate Struct with constructor:

    from google.protobuf.struct_pb2 import Struct, Value
    parameters = Struct(fields={
        'given-name':Value(string_value='Jeff'),
        'last-name':Value(string_value='Bidges')
    })
    

    yields sometimes:

    Exception in thread ptvsd.stopping (most likely raised during interpreter shutdown):

This is the parameter section if my intent

/EventInput

like image 281
TVK Avatar asked Jan 15 '19 10:01

TVK


People also ask

What are parameters in Dialogflow?

When an intent is matched at runtime, Dialogflow provides the extracted values from the end-user expression as parameters. Each parameter has a type, called the entity type, which dictates exactly how the data is extracted.

What is slot filling in Dialogflow?

When an intent is matched at runtime, the Dialogflow agent continues collecting information from the end-user until the end-user has provided data for each of the required parameters. This process is called slot filling.

Is Dialogflow deprecated?

June 13, 2022. The Dialogflow ES Google Assistant integration will be removed on June 13, 2023. This is due to the Google Assistant Conversational Actions planned sunsetting.

How do events work in Dialogflow?

Dialogflow sends a webhook request to your server. Your server responds with a webhook response that includes a followup event. Instead of responding to the user for the Intent-1 match, Dialogflow triggers Intent-2, which is configured for the event.


1 Answers

This is how I did this:

import dialogflow
from google.protobuf import struct_pb2

session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)

parameters = struct_pb2.Struct()
parameters["given-name"] = 'Jeff'
parameters["last-name"] = 'Bridges'

query_input = {
    'event': {
        "name": "greetPerson",
        "parameters": parameters,
        "language_code": "de"
    }
}

response = session_client.detect_intent(
    session=session,
    query_input=query_input)

Note:
In dialogflow console, you must give default values of parameters as #even_name.parameter_name.
In this case for parameter given-name it would be #greetPerson.given-name and for last-name it would be #greetPerson.last-name.

Docs Reference:
We are using DetectIntent, in which we are using QueryInput, in which finally we are using EvenInput

Hope it helps.

like image 132
sid8491 Avatar answered Sep 22 '22 00:09

sid8491