slack-rs / slack-api-schemas

Schemas for the Slack API
1 stars 11 forks source link

Download and generate schema 2018-03-25 [don't merge!] #9

Closed Mange closed 3 months ago

Mange commented 6 years ago

[Don't merge! See rest of description.]

After #8 I decided to download a new version of the schema. Some of the things got corrected, but it also meant that all the manual changes in 5de8de0cfbae8ef572f24fe89dc9a742c3887c8f got lost.

Should we try to add them to the scraper script somehow? Should I rebase the commit to not include any deletions except for the ones that we want? (I'm not sure how to tell them apart right now)

Anyway, it needs to be handled before this can be merged.


Main change is that reply_broadcast is removed and a new thread_broadcast is added in its place, replacing it (but looking slightly different).

Mange commented 6 years ago

Friendly ping. :)

dten commented 6 years ago

sorry didn't see this the scraper doesn't seem like an accurate source of info, worries me a little

dten commented 6 years ago

for example bot_message doesn't even mention channel! https://api.slack.com/events/message/bot_message

Mange commented 6 years ago

Yeah, I know. Their documentation is terrible. Slack has a repo for specifications for their messages, but they don't include the RTM messages.

I've been thinking about creating my own version of the Slack crate that only provides the raw JSON values, and then add optional decorators on top of it that tries to understand them. But if Slack adds another field in there you still have access to it, only without nice types and documentation. But at least you could start dumping the message to guess how the field works and then open a PR. Maybe start with an extension and test it live first.

trait MessageWithShoeSize {
  fn shoe_size(&self) -> Option<ShoeSize>;
}

impl MessageWithShoeSize for slack::Rtm::StandardMessage {
  fn shoe_size(&self) -> Option<ShoeSize> {
    self.get_json("shoeSize").flat_map { |value| ShoeSize::parse_from_json(value).ok() }
  }
}

impl MessageWithShoeSize for slack::Rtm::UnknownMessage {
  fn shoe_size(&self) -> Option<ShoeSize> {
    self.get_json("shoeSize").flat_map { |value| ShoeSize::parse_from_json(value).ok() }
  }
}

# …

# Use extension like it was built-in
println!("Message with shoe size: {:?}", message.shoe_size());
println!("{}", message.body()); # Some methods are already provided of course.

It would be interesting to see where you could go with it. One could tell so much by just allowing a program to dump the entire RTM stream and then perform actions in Slack and record the events.