Search code examples
chatbotfacebook-messengerdialogflow-es

How to deserialize custom payload response in Dialogflow v2?


I'm developing my own chatbot for messenger with Dialogflow v2 and the Node.js client SDK. But I've a problem with custom payloads. When I use the console provided by Dialogflow, I have a response which looks like this :

{ "payload": { "facebook": { "attachment": { "payload": { ...

But, when I get the response from my JS server, the custom payload has been serialized. Here is the object I receive :

{ facebook: { structValue: { fields: [Object] }, kind: 'structValue' } }

Is it possible to deserialize this object in order to get the same custom payload structure that I've provided in Dialogflow ?

Thank you in advance.


Solution

  • 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)