slack_chat_api/
search.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Search {
5    pub client: Client,
6}
7
8impl Search {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Search { client }
12    }
13
14    /**
15     * This function performs a `GET` to the `/search.messages` endpoint.
16     *
17     * Searches for messages matching a query.
18     *
19     * FROM: <https://api.slack.com/methods/search.messages>
20     *
21     * **Parameters:**
22     *
23     * * `token: &str` -- Authentication token. Requires scope: `search:read`.
24     * * `count: i64` -- Pass the number of results you want per "page". Maximum of `100`.
25     * * `highlight: bool` -- Pass a value of `true` to enable query highlight markers (see below).
26     * * `page: i64`
27     * * `query: &str` -- Search query.
28     * * `sort: &str` -- Return matches sorted by either `score` or `timestamp`.
29     * * `sort_dir: &str` -- Change sort direction to ascending (`asc`) or descending (`desc`).
30     */
31    pub async fn message(
32        &self,
33        count: i64,
34        highlight: bool,
35        page: i64,
36        query: &str,
37        sort: &str,
38        sort_dir: &str,
39    ) -> ClientResult<crate::Response<crate::types::DndEndSchema>> {
40        let mut query_args: Vec<(String, String)> = Default::default();
41        if count > 0 {
42            query_args.push(("count".to_string(), count.to_string()));
43        }
44        if highlight {
45            query_args.push(("highlight".to_string(), highlight.to_string()));
46        }
47        if page > 0 {
48            query_args.push(("page".to_string(), page.to_string()));
49        }
50        if !query.is_empty() {
51            query_args.push(("query".to_string(), query.to_string()));
52        }
53        if !sort.is_empty() {
54            query_args.push(("sort".to_string(), sort.to_string()));
55        }
56        if !sort_dir.is_empty() {
57            query_args.push(("sort_dir".to_string(), sort_dir.to_string()));
58        }
59        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
60        let url = self
61            .client
62            .url(&format!("/search.messages?{}", query_), None);
63        self.client
64            .get(
65                &url,
66                crate::Message {
67                    body: None,
68                    content_type: None,
69                },
70            )
71            .await
72    }
73}