sid8491
sid8491

Reputation: 6800

How to send extra data in DialogFlow v2?

How to send extra data to DialogFlow while calling it using some SDK?
I understand that in v1, originalRequest.data was used for this purpose.

Basically I want to send username, mobile number etc from website session and pass it to DialogFlow so that I can get it in webhook and perform some operation.

I am using below code to call DialogFlow:

import dialogflow

def detect_intent_texts(text, session_id):

    session_client = dialogflow.SessionsClient()

    session = session_client.session_path(project_id, session_id)

    text_input = dialogflow.types.TextInput(
        text=text, language_code=language_code)

    query_input = dialogflow.types.QueryInput(text=text_input)

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

    return response.query_result.fulfillment_text


detect_intent_texts('hello how are you', 'some_session_id')

Upvotes: 0

Views: 911

Answers (1)

Abhinav Tyagi
Abhinav Tyagi

Reputation: 5256

You need to set parameters in the context.

  • create a context
  • add parameter
  • extract the context and parameter in the next interaction.

In JSON, it will look like this

{  
  "fulfillmentText":"This is a text response",
  "fulfillmentMessages":[  ],
  "source":"example.com",
  "payload":{  
    "google":{  },
    "facebook":{  },
    "slack":{  }
  },
  "outputContexts":[  
    {  
      "name":"context name",
      "lifespanCount":5,
      "parameters":{  
        "param":"param value"
      }
    }
  ],
  "followupEventInput":{  }
}

You can take a look how it can be done in python using create_context in dialogflow-python-client

Upvotes: 1

Related Questions