Closed ToddMorrill closed 6 years ago
this is built using Struct protocols
In order to convert that you would need to use google proto buffer i.e google.protobuf I used the below code to do this.
import google.protobuf as pf
pf.json_format.MessageToJson(response.query_result.fulfillment_messages[1].payload, including_default_value_fields=False)
Thanks!
I can revolve it, in this way:
Step 1: Import this lib
from google.protobuf.json_format import MessageToDict
Step 2: Send a request
agent = Agent( parent=parent, display_name=display_name, default_language_code="en", time_zone="America/Los_Angeles", )
request = SetAgentRequest( agent=agent, )
Step 3: Convert response to JSON [Look here, add ".pd"]
response = await agent_client.set_agent(request=request) new_response = MessageToDict(response._pb)
return IGetResponseBase(data=new_message)
I'm trying to convert a google.cloud.dialogflow_v2.types.QueryResult object to a simple python dictionary. I've got a fairly large custom payload coming through the
webhook_payload
attribute. Needless to say, when I simply calldict()
on this object, I'm getting a lot of nested objects. I'm trying to avoid 1) writing a function to extract all the data from these nested objects, and 2) using the REST API.Thanks for any help in advance.