1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use anyhow::Result;

use crate::Client;

pub struct Search {
    pub client: Client,
}

impl Search {
    #[doc(hidden)]
    pub fn new(client: Client) -> Self {
        Search { client }
    }

    /**
     * This function performs a `GET` to the `/search.messages` endpoint.
     *
     * Searches for messages matching a query.
     *
     * FROM: <https://api.slack.com/methods/search.messages>
     *
     * **Parameters:**
     *
     * * `token: &str` -- Authentication token. Requires scope: `search:read`.
     * * `count: i64` -- Pass the number of results you want per "page". Maximum of `100`.
     * * `highlight: bool` -- Pass a value of `true` to enable query highlight markers (see below).
     * * `page: i64`
     * * `query: &str` -- Search query.
     * * `sort: &str` -- Return matches sorted by either `score` or `timestamp`.
     * * `sort_dir: &str` -- Change sort direction to ascending (`asc`) or descending (`desc`).
     */
    pub async fn message(
        &self,
        count: i64,
        highlight: bool,
        page: i64,
        query: &str,
        sort: &str,
        sort_dir: &str,
    ) -> Result<crate::types::DndEndSchema> {
        let mut query_args: Vec<(String, String)> = Default::default();
        if count > 0 {
            query_args.push(("count".to_string(), count.to_string()));
        }
        if highlight {
            query_args.push(("highlight".to_string(), highlight.to_string()));
        }
        if page > 0 {
            query_args.push(("page".to_string(), page.to_string()));
        }
        if !query.is_empty() {
            query_args.push(("query".to_string(), query.to_string()));
        }
        if !sort.is_empty() {
            query_args.push(("sort".to_string(), sort.to_string()));
        }
        if !sort_dir.is_empty() {
            query_args.push(("sort_dir".to_string(), sort_dir.to_string()));
        }
        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
        let url = format!("/search.messages?{}", query_);

        self.client.get(&url, None).await
    }
}