MyPureCloud / knowledge-html-converter

This is a javascript library which can convert any html content to genesys cloud knowledge article content format which is a strict and genesys specific JSON structure.
MIT License
3 stars 1 forks source link

table fails to parse when missing "borderWidth" #5

Closed jm-nab closed 3 months ago

jm-nab commented 4 months ago

> HTTP response body: {"message":"Body should have a value.","code":"knowledge.variation.empty.request","status":400,"contextId":"8d282438-c708-4777-89c4-f49d1ac094ca","details":[],"errors":[]}

And:

HTTP response body: {"message":"Please provide a valid article title","code":"bad.request","status":400,"entityName":"DocumentV2","messageWithParams":"Please provide a valid article title","messageParams":{},"contextId":"bfb5484a-a809-4ebc-b3e2-5de93629c748","details":[],"errors":[]}

Example:

Ideally, the parser would fix, or coerce the title and body to be compliant.

Or actually it appears what might be happening is this:

 const borderWidth = tableProperties.borderWidth;
                                             ^

 TypeError: Cannot read properties of undefined (reading 'borderWidth')
     at generateTable (file:///home/jm/repos/export-elevio-kb-to-genesys/src/export_elevio_kb_to_genesys/node_modules/knowledge-html-converter/dist/converters/table.js:26:45)
     at generateTableBlock (file:///home/jm/repos/export-elevio-kb-to-genesys/src/export_elevio_kb_to_genesys/node_modules/knowledge-html-converter/dist/converters/table.js:11:19)
     at file:///home/jm/repos/export-elevio-kb-to-genesys/src/export_elevio_kb_to_genesys/node_modules/knowledge-html-converter/dist/converter.js:52:25
     at Array.forEach (<anonymous>)
     at convertParsedHtmlToBlocks (file:///home/jm/repos/export-elevio-kb-to-genesys/src/export_elevio_kb_to_genesys/node_modules/knowledge-html-converter/dist/converter.js:24:14)
     at convertHtmlToBlocks (file:///home/jm/repos/export-elevio-kb-to-genesys/src/export_elevio_kb_to_genesys/node_modules/knowledge-html-converter/dist/converter.js:20:12)
     at file:///home/jm/repos/export-elevio-kb-to-genesys/src/export_elevio_kb_to_genesys/parse.mjs:9:36
     at Object.readFileAfterClose (node:internal/fs/read/context:68:3)
     at tick (node:internal/fs/read/context:115:9)
     at process.processTicksAndRejections (node:internal/process/task_queues:81:21)

 Node.js v20.8.0
 "
tmelko-genesys commented 4 months ago

These should not happen, it would take us forever to update all of the articles. HTTP response body: {"message":"Body should have a value.","code":"knowledge.variation.empty.request","status":400,"contextId":"8d282438-c708-4777-89c4-f49d1ac094ca","details":[],"errors":[]}

The above error is returned if an empty body is sent in a document variation request. What is the html that you are trying to convert?

HTTP response body: {"message":"Please provide a valid article title","code":"bad.request","status":400,"entityName":"DocumentV2","messageWithParams":"Please provide a valid article title","messageParams":{},"contextId":"bfb5484a-a809-4ebc-b3e2-5de93629c748","details":[],"errors":[]} Example: How To Resolve Word Word/No *WORD Word/WORD File Not Found Error: word, word, word Ideally, the parser would fix, or coerce the title and body to be compliant.

This lib is for converting html to the json structure that can be used in the body property of document variation requests. It is not concerned about document titles. These characters are not allowed in title: ~`^*=|<> Can you just remove/replace them for the document request?

jm-nab commented 4 months ago

Yes I can write a title transform, however it makes it a bit inconvenient having to write an extra transform layer before going live, just to try the trial of the live agent.

I think it could be argued that the title conversion should be handled by the library, and that it shouldn't be incumbent on the support team, or your customers dev team to know the title is just json, the library which converts and imports it should have the context and know to do that.

I understand the empty body issue, however this actually appears to stem from a bug with the parser, it is failing to parse borderWidth I added a traceback.

To summarize, there's 2 issues:

1) Title coercion to whatever the api expects ( just json ) 2) borderWdith on tables doesn't work

tmelko-genesys commented 4 months ago

borderWidth bug: could you show an example html input?

jm-nab commented 4 months ago

Yes:

<!DOCTYPE html>
<html>

   <head>
      <title>Nested Elements Example</title>
   </head>

   <body>
      <h1>This is <i>italic</i> heading</h1>
      <p>This is <u>underlined</u> paragraph</p>
        <ul>
         <li>Beetroot</li>
         <li>Ginger</li>
         <li>Potato</li>
         <li>Radish</li>
      </ul>
      <img src="https://cdn.com/_/some image with spaces.png">
      <p><strong></p>
        <!-- righ here -->
        <table align="center" border="1" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th style="width: 18.711%; background-color: rgb(239, 239, 239);">Symbol</th>
                    <th style="width: 50.5198%; background-color: rgb(239, 239, 239);">Keystroke</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td style="width: 18.711%;" valign="bottom" width="98">
                        <p align="center">-</p>
                    </td>
                    <td style="width: 50.5198%;" valign="top" width="306">
                        <p>alpha left arrow key</p>
                    </td>
                </tr>
                <tr></tr>
            </tbody>
        </table>
   </body>
</html>
tmelko-genesys commented 4 months ago

Thanks for the html, we will fix this bug.

It's quite limited which properties the converter looks for in the html, it only looks for style attributes. This could be a workaround until the fix: write border="1" style="border: 1px solid" instead of border="1".

tmelko-genesys commented 3 months ago

This bug is fixed in version 0.3.4, change: https://github.com/MyPureCloud/knowledge-html-converter/commit/5ad2d11fe5a6ac78e787fb0ec6cf96861517c33f