daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #[macro_use]
  2. extern crate serde_derive;
  3.  
  4. extern crate serde;
  5. extern crate warp;
  6.  
  7. use warp::Filter;
  8.  
  9. fn main() {
  10.     // Match any request and return hello world!
  11.     let routes = warp::any().and(warp::body::json()).map(handle_callback);
  12.  
  13.     warp::serve(routes).run(([127, 0, 0, 1], 3030));
  14. }
  15.  
  16. #[derive(Debug, Deserialize)]
  17. #[serde(tag = "type", rename_all = "snake_case")]
  18. enum Callback {
  19.     UrlVerification { token: String, challenge: String },
  20.     EventCallback { token: String, event: Event },
  21. }
  22.  
  23. #[derive(Debug, Deserialize)]
  24. struct Event {
  25.     channel: String,
  26.     ts: String,
  27.     #[serde(default)]
  28.     thread_ts: Option<String>,
  29. }
  30.  
  31. #[derive(Serialize)]
  32. struct Challenge {
  33.     challenge: String,
  34. }
  35.  
  36. fn handle_callback(callback: Callback) -> impl warp::Reply {
  37.     match callback {
  38.         Callback::UrlVerification { challenge, .. } => return warp::reply::json(&Challenge { challenge }),
  39.         // Callback::EventCallback { event, .. } if event.thread_ts.is_none() => {
  40.         //     return warp::reply
  41.         // },
  42.         Callback::EventCallback {..} => return warp::reply(),
  43.     }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top