Comments (4)
I found the following solution:
from google.protobuf.json_format import MessageToDict
result: DetectIntentResponse = detect_intent_texts([request_text], int(session_token, 16), agent_id)
messages = [MessageToDict(x) for x in result.query_result.fulfillment_messages]
This method seems works great it is just hard to find in the documentation.
@dysnomia Thanks for you assistance.
from python-dialogflow.
Yeah, this shared protobuf type only has very basic documentation at https://developers.google.com/protocol-buffers/docs/reference/python-generated#struct. There are some more usage examples https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/well_known_types_test.py#L683.
About converting to/from Python types:
- From dict: update seems to directly convert from a dict to a struct: https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/well_known_types_test.py#L818.
- To dict: As far as I can see, there is no direct support for that. But Struct implements (almost) the same interface as dict (https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/well_known_types_test.py#L727). Can you just use it in place of dict instead of converting? For serialization: Can you use the proto serialization (https://github.com/google/protobuf/blob/master/python/google/protobuf/internal/well_known_types_test.py#L715)?
I'll file a bug to improve our shared documentation.
from python-dialogflow.
So serialization works for instance for converting to string, but ToJsonString for instance is not implemented on all objects.
And for instance a Message object does not implement .items(), for that you need to use ListFields() which works slightly different.
I keep running into errors because different object types are used in unexpected places (and a seemingly inconsistent fashion), and I need to convert these elements before i can do something like sending the dialogflow payload to the frontend.
from python-dialogflow.
This appears to be answered, if not, please feel free to re-open.
Thanks! :)
from python-dialogflow.
Related Issues (20)
- Exporting Agent Bytes Then Fails to Import HOT 13
- Migrate to main branch
- samples.snippets.participant_management_test: test_analyze_content_text failed HOT 11
- samples.snippets.participant_management_test: test_analyze_content_text failed HOT 1
- Dependency Dashboard
- samples.snippets.create_document_test: test_create_document failed HOT 5
- samples.snippets.create_knowledge_base_test: test_create_knowledge_base failed HOT 5
- participant_management.py test failed.
- Segmentation fault with multiprocessing HOT 2
- Increase code coverage from 99% to 100% HOT 1
- No DesignTimeAgent found for project `python-docs-samples-*` HOT 2
- AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key' HOT 9
- Resolve sphinx docs warnings and enable warnings as errors HOT 1
- seminar HOT 1
- Warning: a recent release failed
- AttributeError: module 'google.cloud.dialogflow_v2' has no attribute 'Entity' HOT 1
- Add sample code for StreamingAnalyzeContent with audio live transcription HOT 1
- Add Code Snippet for Pulling Session ID from WebhookRequests HOT 1
- AttributeError: 'dict' object has no attribute 'index' HOT 2
- unable to import name "common_pb2" from "google.cloud.dialogflow_v2.types" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-dialogflow.