jolicode / qotd

MIT License
30 stars 4 forks source link

Links are not parsed / handled correctly #40

Open damienalexandre opened 1 year ago

damienalexandre commented 1 year ago

Slack links don't have a "markdown like" format:

image

lyrixx commented 1 year ago

FTR, I use a "MD => HTML" transformation. And slack messages are not in MD 😬 I don't know if a "slack format => HTML" transformer exist in PHP. I don't want to re-implement one!

damienalexandre commented 1 year ago

In theory you should have a "blocks" property on the message that's doing the actual parsing:

https://api.slack.com/changelog/2019-09-what-they-see-is-what-you-get-and-more-and-less#what__example-message-object

Then we need to translate this to HTML.

lyrixx commented 1 year ago

Thanks 👍🏼

Example of an API response:

array:12 [
  "iid" => "1df235db-374b-4871-911f-aeb0e9a499d9"
  "team" => "T0FLD8LEM"
  "score" => 0
  "channel" => array:12 [
    "id" => "C0FLD8LSV"
    "is_channel" => true
    "is_group" => false
    "is_im" => false
    "name" => "general"
    "is_shared" => false
    "is_org_shared" => false
    "is_ext_shared" => false
    "is_private" => false
    "is_mpim" => false
    "pending_shared" => []
    "is_pending_ext_shared" => false
  ]
  "type" => "message"
  "user" => "U0FLDV6UW"
  "username" => "lyrixx"
  "ts" => "1680169830.781739"
  "attachments" => array:1 [
    0 => array:12 [
      "image_url" => "https://github.githubassets.com/images/modules/open_graph/github-logo.png"
      "image_width" => 1200
      "image_height" => 1200
      "image_bytes" => 7038
      "from_url" => "https://github.com/notifications?query=is%3Aunread"
      "service_icon" => "https://a.slack-edge.com/80588/img/unfurl_icons/github.png"
      "id" => 1
      "original_url" => "https://github.com/notifications?query=is%3Aunread"
      "fallback" => "GitHub"
      "text" => "GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 330 million projects."
      "title" => "GitHub"
      "title_link" => "https://github.com/notifications?query=is%3Aunread"
    ]
  ]
  "blocks" => array:1 [
    0 => array:3 [
      "type" => "rich_text"
      "block_id" => "Ccn"
      "elements" => array:3 [
        0 => array:2 [
          "type" => "rich_text_section"
          "elements" => array:3 [
            0 => array:2 [
              "type" => "text"
              "text" => "Un message  "
            ]
            1 => array:3 [
              "type" => "link"
              "url" => "https://github.com/notifications?query=is%3Aunread"
              "text" => "un lien"
            ]
            2 => array:2 [
              "type" => "text"
              "text" => " un autre message\n"
            ]
          ]
        ]
        1 => array:3 [
          "type" => "rich_text_preformatted"
          "elements" => array:1 [
            0 => array:2 [
              "type" => "text"
              "text" => "du code"
            ]
          ]
          "border" => 0
        ]
        2 => array:2 [
          "type" => "rich_text_section"
          "elements" => array:2 [
            0 => array:2 [
              "type" => "text"
              "text" => "encore du text "
            ]
            1 => array:3 [
              "type" => "link"
              "url" => "https://example.com"
              "text" => "un autre lien"
            ]
          ]
        ]
      ]
    ]
  ]
  "text" => """
    Un message  <https://github.com/notifications?query=is%3Aunread|un lien> un autre message\n
    ```du code```\n
    encore du text <https://example.com|un autre lien>
    """
  "permalink" => "https://lyrixx.slack.com/archives/C0FLD8LSV/p1680169830781739"
]

Now, I need a lib that is able to transform all theses block in HTML 👍🏼 I'll be much cleaner than my hack 😂