Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[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(),
- }
- }
Add Comment
Please, Sign In to add comment