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
use lazy_static::lazy_static;
use rsb_derive::Builder;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use url::Url;
use crate::ratectl::*;
use crate::SlackClient;
use crate::{ClientResult, SlackClientHttpConnector};
use rvstruct::ValueStruct;
use slack_morphism_models::*;
impl<SCHC> SlackClient<SCHC>
where
SCHC: SlackClientHttpConnector + Send,
{
pub async fn post_webhook_message(
&self,
incoming_webhook_url: &Url,
req: &SlackApiPostWebhookMessageRequest,
) -> ClientResult<SlackApiPostWebhookMessageResponse> {
self.http_api
.connector
.http_post_uri(
incoming_webhook_url.clone(),
req,
None,
Some(&POST_WEBHOOK_SPECIAL_LIMIT_RATE_CTL),
)
.await
}
pub async fn respond_to_event(
&self,
response_url: &SlackResponseUrl,
req: &SlackApiPostWebhookMessageRequest,
) -> ClientResult<SlackApiPostWebhookMessageResponse> {
self.post_webhook_message(response_url.value(), req).await
}
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackApiPostWebhookMessageRequest {
#[serde(flatten)]
pub content: SlackMessageContent,
pub thread_ts: Option<SlackTs>,
}
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)]
pub struct SlackApiPostWebhookMessageResponse {}
lazy_static! {
pub static ref POST_WEBHOOK_SPECIAL_LIMIT_RATE_CTL: SlackApiMethodRateControlConfig =
SlackApiMethodRateControlConfig::new().with_special_rate_limit(
SlackApiRateControlSpecialLimit::new(
"post_webhook_message".into(),
SlackApiRateControlLimit::new(1, std::time::Duration::from_secs(1))
)
);
}