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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
use crate::{LineApiResponse, LineClient};
use serde_derive::{Deserialize, Serialize};
use serde_json::{json, Value};

impl LineClient {
    /// https://developers.line.biz/ja/reference/messaging-api/#create-rich-menu
    pub async fn rich_menu_create(
        &self,
        value: Value,
    ) -> LineApiResponse<LineApiRichMenuCreateResponse> {
        self.http_post("https://api.line.me/v2/bot/richmenu", &value)
            .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#create-rich-menu
    pub async fn rich_menu_validate_object(
        &self,
        value: Value,
    ) -> LineApiResponse<LineApiRichMenuValidateObjectResponse> {
        self.http_post("https://api.line.me/v2/bot/richmenu/validate", &value)
            .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#delete-rich-menu
    pub async fn rich_menu_content_upload(
        &self,
        rich_menu_id: &str,
        file: Vec<u8>,
    ) -> LineApiResponse<Value> {
        self.http_post_data(
            format!(
                "https://api-data.line.me/v2/bot/richmenu/{}/content",
                rich_menu_id
            )
            .as_str(),
            file,
        )
        .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#download-rich-menu-image
    pub async fn rich_menu_content_download(&self, rich_menu_id: &str) -> LineApiResponse<Vec<u8>> {
        self.http_get_stream(
            format!(
                "https://api-data.line.me/v2/bot/richmenu/{}/content",
                rich_menu_id
            )
            .as_str(),
            &json!({}),
        )
        .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-rich-menu-list
    pub async fn rich_menu_list(&self) -> LineApiResponse<LineApiRichMenuListResponse> {
        self.http_get("https://api.line.me/v2/bot/richmenu/list", &json!({}))
            .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#delete-rich-menu
    pub async fn rich_menu_delete(
        &self,
        rich_menu_id: &str,
    ) -> LineApiResponse<LineApiRichMenuDeleteResponse> {
        self.http_delete(
            format!("https://api.line.me/v2/bot/richmenu/{}", rich_menu_id).as_str(),
            &json!({}),
        )
        .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#delete-rich-menu
    pub async fn rich_menu_get(
        &self,
        rich_menu_id: &str,
    ) -> LineApiResponse<LineApiRichMenuGetResponse> {
        self.http_get(
            format!("https://api.line.me/v2/bot/richmenu/{}", rich_menu_id).as_str(),
            &json!({}),
        )
        .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#get-default-rich-menu-id
    pub async fn rich_menu_set_default_menu(
        &self,
        rich_menu_id: &str,
    ) -> LineApiResponse<LineApiRichMenuSetDefaultResponse> {
        self.http_post(
            format!(
                "https://api.line.me/v2/bot/user/all/richmenu/{}",
                rich_menu_id
            )
            .as_str(),
            &json!({}),
        )
        .await
    }

    /// https://developers.line.biz/ja/reference/messaging-api/#get-default-rich-menu-id
    pub async fn rich_menu_get_default_menu_id(
        &self,
    ) -> LineApiResponse<LineApiRichMenuGetDefaultResponse> {
        self.http_get("https://api.line.me/v2/bot/user/all/richmenu", &json!({}))
            .await
    }
    /// https://developers.line.biz/ja/reference/messaging-api/#cancel-default-rich-menu
    pub async fn rich_menu_delete_default_menu(
        &self,
    ) -> LineApiResponse<LineApiRichMenuDeleteDefaultResponse> {
        self.http_delete("https://api.line.me/v2/bot/user/all/richmenu", &json!({}))
            .await
    }
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiRichMenuCreateResponse {
    #[serde(rename = "richMenuId")]
    pub rich_menu_id: String,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiRichMenuValidateObjectResponse {}

#[derive(Debug, Default, Clone, Deserialize, Serialize)]
pub struct SlackApiFilesUploadRequest {
    pub file: Option<String>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiRichMenuListResponse {
    #[serde(rename = "richmenus")]
    pub rich_menus: Vec<RichMenu>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct RichMenu {
    #[serde(rename = "richMenuId")]
    pub rich_menu_id: String,
    #[serde(rename = "name")]
    pub name: String,
    #[serde(rename = "size")]
    pub size: RichMenuSize,
    #[serde(rename = "chatBarText")]
    pub chat_bar_text: String,
    #[serde(rename = "selected")]
    pub selected: bool,
    #[serde(rename = "areas")]
    pub areas: Vec<RichMenuArea>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct RichMenuSize {
    pub width: u32,
    pub height: u32,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct RichMenuArea {
    pub bounds: RichMenuAreaBounds,
    pub action: RichMenuAction,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct RichMenuAreaBounds {
    pub x: u32,
    pub y: u32,
    pub width: u32,
    pub height: u32,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct RichMenuAction {
    #[serde(rename = "type")]
    pub action_type: String,
    pub data: Option<String>,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiRichMenuGetResponse {
    #[serde(flatten)]
    pub rich_menu: RichMenu,
}
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiRichMenuDeleteResponse {}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiRichMenuSetDefaultResponse {}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiRichMenuGetDefaultResponse {
    #[serde(rename = "richMenuId")]
    pub rich_menu_id: String,
}

#[derive(Debug, Default, Deserialize, Serialize, Clone)]
pub struct LineApiRichMenuDeleteDefaultResponse {}