Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6fe905c
refactor!: simplifies and extends typings for Event types
JadedEvan Apr 5, 2023
e40c9a3
test: adds tests for "app requested" event
JadedEvan Apr 9, 2023
6ac5a55
test: adds additional tests to Events API
JadedEvan Apr 9, 2023
f0bff62
fix: correct field definition for `app_requested` event
JadedEvan Apr 10, 2023
ee62688
test: adds tests for Events API for `call_rejected` and others
JadedEvan Apr 10, 2023
57b378b
test: adds additional tests for Event API events
JadedEvan Apr 13, 2023
ab82b23
feat: adds missing Event API types (dnd_updated, dnd_updated_user)
JadedEvan Apr 13, 2023
9ded706
refactor: update `emoji_changed` event to support subtypes
JadedEvan Apr 13, 2023
cbe7b57
feat: adds various Event API for file operations (shared, created, etc)
JadedEvan Apr 14, 2023
8aac7de
chore: formatting and documentation for group events in Events API
JadedEvan Apr 14, 2023
4cc97fd
feat: implement `link_shared` from Event API
JadedEvan Apr 15, 2023
344f23c
refactor: clean up member_joined_channel in Events API
JadedEvan Apr 15, 2023
c1a2bf5
feat: implement `message_metadata_posted` in Events API types
JadedEvan Apr 16, 2023
a8a33af
feat: implement `message_metadata_deleted`, `message_metadata_updated…
JadedEvan Apr 17, 2023
3a10be8
feat: implements several new Event API events
JadedEvan Apr 17, 2023
15e02c5
feat: adds Event API types for shared channel actions
JadedEvan Apr 18, 2023
64c708c
feat: implement the `subteam_created` Event type
JadedEvan Apr 23, 2023
0aa076f
feat: implement "subteam_members_changed" event
JadedEvan Apr 24, 2023
942bf43
feat: implements additional "team_xxx" from Events API
JadedEvan Apr 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ features = ["client"]
[dev-dependencies]
env_logger = "0.9.0"
mockall = "0.11.0"
assert-json-diff = "^2.0.2"

[dev-dependencies.async-tls]
version = "0.11.0"
default-features = false
features = ["server"]
features = ["server"]

[build]
incremental = true
6 changes: 3 additions & 3 deletions examples/events_app_mention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;

use async_trait::async_trait;
use slack::chat::post_message::{post_message, PostMessageRequest};
use slack::event_api::event::{Event, EventCallbackType};
use slack::event_api::event::{Event, EventType};
use slack::http_client::{default_client, SlackWebAPIClient};
use slack::socket::event::{EventsAPI, HelloEvent};
use slack::socket::socket_mode::{ack, EventHandler, SocketMode, Stream};
Expand Down Expand Up @@ -51,8 +51,8 @@ where
.expect("socket mode ack error.");

match e.payload {
Event::EventCallback(event_callback) => match event_callback.event {
EventCallbackType::AppMention {
Event{event, ..} => match event {
EventType::AppMention {
text,
channel,
ts,
Expand Down
89 changes: 84 additions & 5 deletions src/event_api/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@ use crate::users::user::User;

use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use serde_json::Value;

#[skip_serializing_none]
#[derive(Deserialize, Serialize, Debug, PartialEq)]
/// See more at <https://api.slack.com/events/app_requested>
///
/// Note that the `enterprise` field is a bit ambiguous. Slack's official
/// documentation says this value may be null or not null (but does not provide
/// an example). Therefore we use the `serde_json::Value::Null` variant to
/// represent this possibility
pub struct AppRequest {
pub id: Option<String>,
pub app: Option<App>,
pub enterprise: Value,
pub id: Option<String>,
pub message: Option<String>,
pub previous_resolution: Option<PreviousResolution>,
pub scopes: Option<Vec<Scope>>,
pub team: Option<Team>,
pub user: Option<User>,
}

#[skip_serializing_none]
Expand All @@ -25,10 +37,6 @@ pub struct App {
pub is_app_directory_approved: Option<bool>,
pub is_internal: Option<bool>,
pub additional_info: Option<String>,
pub user: Option<User>,
pub team: Option<Team>,
pub scopes: Option<Vec<Scope>>,
pub message: Option<String>,
}

#[skip_serializing_none]
Expand All @@ -46,3 +54,74 @@ pub struct Scope {
pub is_sensitive: Option<bool>,
pub token_type: Option<String>,
}

#[cfg(test)]
mod tests {
use crate::event_api::event::EventType;
use assert_json_diff::*;
use serde_json::Value;

#[test]
fn deserialized_app_requested_event() {
let json = r##"
{
"type": "app_requested",
"app_request":{
"id": "1234",
"app": {
"id": "A5678",
"name": "Brent's app",
"description": "They're good apps, Bront.",
"help_url": "brontsapp.com",
"privacy_policy_url": "brontsapp.com",
"app_homepage_url": "brontsapp.com",
"app_directory_url": "https://slack.slack.com/apps/A102ARD7Y",
"is_app_directory_approved": true,
"is_internal": false,
"additional_info": "none"
},
"previous_resolution": {
"status": "approved",
"scopes": [
{
"name": "app_requested",
"description": "allows this app to listen for app install requests",
"is_sensitive": false,
"token_type": "user"
}]
},
"user":{
"id": "U1234",
"name": "Bront",
"email": "bront@brent.com"
},
"team": {
"id": "T1234",
"name": "Brant App Team",
"domain": "brantappteam"
},
"enterprise": null,
"scopes": [
{
"name": "app_requested",
"description": "allows this app to listen for app install requests",
"is_sensitive": false,
"token_type": "user"
}
],
"message": "none"
}
}
"##;
let deserialized = serde_json::from_str::<EventType>(&json).unwrap();
// Make comparison between our deserialized struct and generic serde_json Value to ensure
// that all expected keys exist
let expected: Value = serde_json::from_str(&json).unwrap();
assert_json_eq!(deserialized, expected);

match deserialized {
EventType::AppRequested{..} => assert!(true),
_ => panic!("unrecognized variant"),
}
}
}
Loading