googleapis / googleapis/google-cloud-python

response_result.response_messages.payloads is in protobuf; serialize to json?

Đang mở
#16,444 2 bình luận 0 reaction 1 người được giao Được giao cho @balajismaniam Xem trên GitHub
api: dialogflow type: feature request
Ngôn ngữ chính
Python
Star
5.4k
Fork
1.8k
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
122

Mô tả

Thanks for stopping by to let us know something could be better!

per support Case: 29062259 (Serialize a (json) protobuf object)

**your feature request related to a problem**
When session_client.detect_intent(request=request) returns response_result, from which you can get custom "payloads" that you defined in a DialogFlow Page. However, while what your input is in json, what you get in response_result.response_messages.payloads is in protobuf. It is inconvenient to access the parameters you defined in payloads (json) with protobuf.

** solution **
It will be very beneficial to have a seriallizer to convert the protobuf back to the original json format.

I wrote a serialize function that could convert protobuf to json:

```
def parse_protomap(value):

if isinstance(value, RepeatedComposite):
obj = []
for v in value:
o = {}
for k in v:
o[k] = parse_protomap(v[k])
obj.append(o)
elif isinstance(value, MapComposite):
obj = {}
for v in value:
obj[v] = parse_protomap(value[v])
else:
obj = value
return obj
```

to call it:

for r in response_result.response_messages:
if r.payload != None:
payloads = parse_protomap(r.payload)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.