GoogleCloudPlatform / dialogflow-integrations

Dialogflow integrations with multiple platforms including KIK, Skype, Spark, Twlio, Twitter and Viber
https://cloud.google.com/dialogflow/
Apache License 2.0
256 stars 503 forks source link

JsonToProto returns empty payload #9

Open christ0089 opened 4 years ago

christ0089 commented 4 years ago

jsonToProto functions seems to return proto object but when sent as request object to the fullfilment it returns empty payload.

const payload = { data: { SmsSid: "SM1eb889baa86d1887d14c6007a6c5684a", Body: "Hola", SmsStatus: "received", MessageSid: "SM1eb889baa86d1887d14c6007a6c5684a", ApiVersion: "2010-04-01", From: "whatsapp:+5218717953912", AccountSid: "ACf71ea17bda8928547c7f0fa3f13d384b", NumMedia: "0", To: "whatsapp:+14155238886", SmsMessageSid: "SM1eb889baa86d1887d14c6007a6c5684a", NumSegments: "1" } };

const request = {
  session: sessionPath,
  queryInput: {
    text: {
      text: "Hola",
      languageCode: LANGUAGE_CODE
    }
  },
  queryParams: {
    payload: this.jsonValueToProto(payload)
  }
};
mekpavit commented 4 years ago

I'm not sure what this refers to. But if it refers to the exported module from /botlib/json_to_proto.js, try changing this.jsonValueToProto(payload) to this.jsonToStructProto(payload) should fix the problem.

FYI, jsonValueToProto only converts the value in a JSON object into StructProto value. But the payload variable in your code holds the whole JSON object (including key and value) which should be convert using jsonToStructProto method.

Feel free to reply if this approach does not work!