slack-rs / slack-rs-api

Rust interface for the Slack Web API
Apache License 2.0
110 stars 67 forks source link

change bot icons to serde::json value #67

Closed bunker-inspector closed 5 years ago

bunker-inspector commented 5 years ago

I tracked this down after the slackbot for a team I'm a part of stopped working. It appears that this field doesn't guarantee any real consistent format. For example, here are some of the results from my rtm.start command.


    {
      "id": "B070EUCG1",
      "deleted": true,
      "name": "screenhero",
      "updated": 1535500920,
      "app_id": "A0F7XDVHB",
      "icons": [

      ]
    },

    {
      "id": "B4491H4FP",
      "deleted": true,
      "name": "CatFacts",
      "updated": 1534347438,
      "app_id": "A09K56QTC",
      "icons": {
        "image_36": "https:\/\/avatars.slack-edge.com\/2015-12-15\/16744084547_0ce07b9b66de11dfc9c5_36.png",
        "image_48": "https:\/\/avatars.slack-edge.com\/2015-12-15\/16744084547_0ce07b9b66de11dfc9c5_48.png",
        "image_72": "https:\/\/avatars.slack-edge.com\/2015-12-15\/16744084547_0ce07b9b66de11dfc9c5_72.png"
      }
    },

    {
      "id": "B0V153UA0",
      "deleted": false,
      "name": "PinPon",
      "updated": 1458763112,
      "app_id": "A0F7VRG6Q",
      "icons": {
        "emoji": ":table_tennis_paddle_and_ball:",
        "image_64": "https:\/\/a.slack-edge.com\/37d58\/img\/emoji_2017_12_06\/apple\/1f3d3.png"
      }
    },
dten commented 5 years ago

Would rather not change it to a Value, looks to me like one of those classic, either empty list or object ones have you seen it give a non-empty list ever?

there is a function optional_struct_or_empty_array that handles this case specifically for UserProfile.fields and i suggest this is another case for it

bunker-inspector commented 5 years ago

That's a good point. I have only seen it as an empty list. The docs are unclear on what the bot field can look like so I figured it was possible. I'll try what you suggested when I have a chance

bunker-inspector commented 5 years ago

Updated. That function did the trick :+1:

dten commented 5 years ago

Sorry forgot to mention, that file you've changed is actually generated and shouldn't be changed manually unless you want your changes to be lost next time it's generated. The file you'll want to change is here, it captures the special cases (hacks) that are expressed nicely in the json schema.

https://github.com/slack-rs/slack-rs-api/blob/master/codegen/src/json_schema.rs#L158

then running code gen will update src/types.rs

could really do with the generator adding a massive comment at the top saying "oi this is generated"

dten commented 5 years ago

Accident or resubmitting?

dten commented 5 years ago

I have a pr that fixes this, if you would still like to submit one, as it is your contribution, you can if you wish https://github.com/slack-rs/slack-rs-api/pull/68