admin管理员组

文章数量:1355694

DialogFlow sends to webhook a request for a file using CPFCN.

Webhook returns the PDF File on JSON Format but it is not working. What is wrong with my JSON response?

{
  "fulfillmentText": "PDF File generated",
  "fulfillmentMessages": [
    {
      "payload": {
        "richContent": [
          [
            {
              "type": "file",
              "file": {
                "name": "generated_document.pdf",
                "url": "data:application/pdf;base64,255044462d312e330a25938c8b9e205265706f72744c61622047656e6572617465642050444620646f63756d656e7420687474703a2f2f7777772e7265706f72746c61622e636f6d0a312030206f626a0a3c3c0a2f46312032203020520a3e3e0a656e646f626a0a322030206f626a0a3c3c0a2f42617365466f6e74202f48656c766574696361202f456e636f64696e67202f57696e416e7369456e636f64696e67202f4e616d65202f4631202f53756274797065202f5479706531202f54797065202f466f6e740a3e3e0a656e646f626a0a332030206f626a0a3c3c0a2f436f6e74656e7473203720302052202f4d65646961426f78205b20302030203539352e32373536203834312e38383938205d202f506172656e74203620302052202f5265736f7572636573203c3c0a2f466f6e74203120302052202f50726f63536574205b202f504446202f54657874202f496d61676542202f496d61676543202f496d61676549205d0a3e3e202f526f746174652030202f5472616e73203c3c0a0a3e3e200a20202f54797065202f506167650a3e3e0a656e646f626a0a342030206f626a0a3c3c0a2f506167654d6f6465202f5573654e6f6e65202f5061676573203620302052202f54797065202f436174616c6f670a3e3e0a656e646f626a0a352030206f626a0a3c3c0a2f417574686f722028616e6f6e796d6f757329202f4372656174696f6e446174652028443a32303235303332393135343535382d30332730302729202f43726561746f7220285265706f72744c616220504446204c696272617279202d207777772e7265706f72746c61622e636f6d29202f4b6579776f726473202829202f4d6f64446174652028443a32303235303332393135343535382d30332730302729202f50726f647563657220285265706f72744c616220504446204c696272617279202d207777772e7265706f72746c61622e636f6d29200a20202f5375626a6563742028756e73706563696669656429202f5469746c652028756e7469746c656429202f54726170706564202f46616c73650a3e3e0a656e646f626a0a362030206f626a0a3c3c0a2f436f756e742031202f4b696473205b203320302052205d202f54797065202f50616765730a3e3e0a656e646f626a0a372030206f626a0a3c3c0a2f46696c746572205b202f415343494938354465636f6465202f466c6174654465636f6465205d202f4c656e677468203236340a3e3e0a73747265616d0a47617332415f2b716d2526344821634d45286124273c623d5e2b5c2c4b6b454271422a2644514d233c465d2a52244047234c6950354b40383f3a2d516840295d515539456c7069352928382c2a37425f5452463527482c635734586167322d502a47313b4b554868243846414e5b3e5d41634648214a7548556c3c324a54246f4561652c28604024304c5a624d49726f366a5c687269234c6d3d2b56377544405943352e3367424b3c3742376c6a372f737124225d6343744167592f4c366e4165476c496a5835376e4d3936486b28526b42422369403e7172262658385b5346635c50246f334559406e273e4c213e2c57293f35663a2227424d4a2b322a3d215d3a36604e727e3e656e6473747265616d0a656e646f626a0a787265660a3020380a303030303030303030302036353533352066200a30303030303030303733203030303030206e200a30303030303030313034203030303030206e200a30303030303030323131203030303030206e200a30303030303030343134203030303030206e200a30303030303030343832203030303030206e200a30303030303030373738203030303030206e200a30303030303030383337203030303030206e200a747261696c65720a3c3c0a2f4944200a5b3c61393332353464653861373730363236343563366438623966343531303038643e3c61393332353464653861373730363236343563366438623966343531303038643e5d0a25205265706f72744c61622067656e6572617465642050444620646f63756d656e74202d2d206469676573742028687474703a2f2f7777772e7265706f72746c61622e636f6d290a0a2f496e666f2035203020520a2f526f6f742034203020520a2f53697a6520380a3e3e0a7374617274787265660a313139310a2525454f460a"
              }
            }
          ]
        ]
      }
    }
  ]
}

I tried to return PDF File to the user.

The PDF File is not being sent. What´s wrong with the JSON Response?

DialogFlow sends to webhook a request for a file using CPFCN.

Webhook returns the PDF File on JSON Format but it is not working. What is wrong with my JSON response?

{
  "fulfillmentText": "PDF File generated",
  "fulfillmentMessages": [
    {
      "payload": {
        "richContent": [
          [
            {
              "type": "file",
              "file": {
                "name": "generated_document.pdf",
                "url": "data:application/pdf;base64,255044462d312e330a25938c8b9e205265706f72744c61622047656e6572617465642050444620646f63756d656e7420687474703a2f2f7777772e7265706f72746c61622e636f6d0a312030206f626a0a3c3c0a2f46312032203020520a3e3e0a656e646f626a0a322030206f626a0a3c3c0a2f42617365466f6e74202f48656c766574696361202f456e636f64696e67202f57696e416e7369456e636f64696e67202f4e616d65202f4631202f53756274797065202f5479706531202f54797065202f466f6e740a3e3e0a656e646f626a0a332030206f626a0a3c3c0a2f436f6e74656e7473203720302052202f4d65646961426f78205b20302030203539352e32373536203834312e38383938205d202f506172656e74203620302052202f5265736f7572636573203c3c0a2f466f6e74203120302052202f50726f63536574205b202f504446202f54657874202f496d61676542202f496d61676543202f496d61676549205d0a3e3e202f526f746174652030202f5472616e73203c3c0a0a3e3e200a20202f54797065202f506167650a3e3e0a656e646f626a0a342030206f626a0a3c3c0a2f506167654d6f6465202f5573654e6f6e65202f5061676573203620302052202f54797065202f436174616c6f670a3e3e0a656e646f626a0a352030206f626a0a3c3c0a2f417574686f722028616e6f6e796d6f757329202f4372656174696f6e446174652028443a32303235303332393135343535382d30332730302729202f43726561746f7220285265706f72744c616220504446204c696272617279202d207777772e7265706f72746c61622e636f6d29202f4b6579776f726473202829202f4d6f64446174652028443a32303235303332393135343535382d30332730302729202f50726f647563657220285265706f72744c616220504446204c696272617279202d207777772e7265706f72746c61622e636f6d29200a20202f5375626a6563742028756e73706563696669656429202f5469746c652028756e7469746c656429202f54726170706564202f46616c73650a3e3e0a656e646f626a0a362030206f626a0a3c3c0a2f436f756e742031202f4b696473205b203320302052205d202f54797065202f50616765730a3e3e0a656e646f626a0a372030206f626a0a3c3c0a2f46696c746572205b202f415343494938354465636f6465202f466c6174654465636f6465205d202f4c656e677468203236340a3e3e0a73747265616d0a47617332415f2b716d2526344821634d45286124273c623d5e2b5c2c4b6b454271422a2644514d233c465d2a52244047234c6950354b40383f3a2d516840295d515539456c7069352928382c2a37425f5452463527482c635734586167322d502a47313b4b554868243846414e5b3e5d41634648214a7548556c3c324a54246f4561652c28604024304c5a624d49726f366a5c687269234c6d3d2b56377544405943352e3367424b3c3742376c6a372f737124225d6343744167592f4c366e4165476c496a5835376e4d3936486b28526b42422369403e7172262658385b5346635c50246f334559406e273e4c213e2c57293f35663a2227424d4a2b322a3d215d3a36604e727e3e656e6473747265616d0a656e646f626a0a787265660a3020380a303030303030303030302036353533352066200a30303030303030303733203030303030206e200a30303030303030313034203030303030206e200a30303030303030323131203030303030206e200a30303030303030343134203030303030206e200a30303030303030343832203030303030206e200a30303030303030373738203030303030206e200a30303030303030383337203030303030206e200a747261696c65720a3c3c0a2f4944200a5b3c61393332353464653861373730363236343563366438623966343531303038643e3c61393332353464653861373730363236343563366438623966343531303038643e5d0a25205265706f72744c61622067656e6572617465642050444620646f63756d656e74202d2d206469676573742028687474703a2f2f7777772e7265706f72746c61622e636f6d290a0a2f496e666f2035203020520a2f526f6f742034203020520a2f53697a6520380a3e3e0a7374617274787265660a313139310a2525454f460a"
              }
            }
          ]
        ]
      }
    }
  ]
}

I tried to return PDF File to the user.

The PDF File is not being sent. What´s wrong with the JSON Response?

Share Improve this question edited Mar 29 at 19:10 Mr Papiro asked Mar 29 at 19:06 Mr PapiroMr Papiro 74 bronze badges 2
  • Please take a look at this answer and this answer on how to encode a file in base64 format. – Chris Commented Mar 30 at 10:18
  • That is NOT a PDF it is a coded string that needs decoding into a PDF then encoding into a base64 as you have attempted then decoding by client into a pdf then decoding into text on screen. So what it actually contains as screen pixels could be shown simpler on HTML screen and printed HERE Document generated for Dialogflow Session: /sessions/98585d67-b6fd-6cbf-1730-e1df6dbab78b/contexts/ Parameters received: cpfcnpj-number: 111.222.333-55 – K J Commented Apr 3 at 21:13
Add a comment  | 

1 Answer 1

Reset to default -1

The URL field contains data:application/pdf;base64,..., which might not be handled appropriately by some clients.

Try sending the base64 content separately in a downloadable format instead of embedding it directly in a URL.

本文标签: pythonHow can I correct my JSON Response It is not working on DialogFlowStack Overflow