Created
September 14, 2018 22:49
-
-
Save kejadlen/f55f4e73cd95fc030517385959d3fd41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate serde_derive; | |
extern crate serde; | |
extern crate warp; | |
use warp::Filter; | |
fn main() { | |
// Match any request and return hello world! | |
let routes = warp::any().and(warp::body::json()).map(handle_callback); | |
warp::serve(routes).run(([127, 0, 0, 1], 3030)); | |
} | |
#[derive(Debug, Deserialize)] | |
#[serde(tag = "type", rename_all = "snake_case")] | |
enum Callback { | |
UrlVerification { token: String, challenge: String }, | |
EventCallback { token: String, event: Event }, | |
} | |
#[derive(Debug, Deserialize)] | |
struct Event { | |
channel: String, | |
ts: String, | |
#[serde(default)] | |
thread_ts: Option<String>, | |
} | |
#[derive(Serialize)] | |
struct Challenge { | |
challenge: String, | |
} | |
fn handle_callback(callback: Callback) -> impl warp::Reply { | |
match callback { | |
Callback::UrlVerification { challenge, .. } => return warp::reply::json(&Challenge { challenge }), | |
// Callback::EventCallback { event, .. } if event.thread_ts.is_none() => { | |
// return warp::reply | |
// }, | |
Callback::EventCallback {..} => return warp::reply(), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment