Skip to content

Commit

Permalink
refactor: slack bot switched to using webhook instead of bot token
Browse files Browse the repository at this point in the history
  • Loading branch information
neriumrevolta committed Dec 12, 2023
1 parent 74db359 commit 1f707a3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 45 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions subgraph-radio/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ impl Config {
) -> Result<GraphcastAgentConfig, GraphcastAgentError> {
let wallet_key = self.wallet_input().unwrap().to_string();
let topics = self.radio_setup().topics.clone();
let mut discv5_enrs = self.waku().discv5_enrs.clone().unwrap_or_default();
// Discovery network
discv5_enrs.push("enr:-P-4QJI8tS1WTdIQxq_yIrD05oIIW1Xg-tm_qfP0CHfJGnp9dfr6ttQJmHwTNxGEl4Le8Q7YHcmi-kXTtphxFysS11oBgmlkgnY0gmlwhLymh5GKbXVsdGlhZGRyc7hgAC02KG5vZGUtMDEuZG8tYW1zMy53YWt1djIucHJvZC5zdGF0dXNpbS5uZXQGdl8ALzYobm9kZS0wMS5kby1hbXMzLndha3V2Mi5wcm9kLnN0YXR1c2ltLm5ldAYfQN4DiXNlY3AyNTZrMaEDbl1X_zJIw3EAJGtmHMVn4Z2xhpSoUaP5ElsHKCv7hlWDdGNwgnZfg3VkcIIjKIV3YWt1Mg8".to_string());

GraphcastAgentConfig::new(
wallet_key,
Expand All @@ -166,7 +163,7 @@ impl Config {
self.waku().waku_port.clone(),
self.waku().waku_addr.clone(),
self.waku().filter_protocol,
Some(discv5_enrs),
self.waku().discv5_enrs.clone(),
self.waku().discv5_port,
)
.await
Expand Down Expand Up @@ -387,18 +384,11 @@ pub struct RadioSetup {
pub collect_message_duration: u64,
#[clap(
long,
value_name = "SLACK_TOKEN",
help = "Slack bot API token",
env = "SLACK_TOKEN"
value_name = "SLACK_WEBHOOK",
help = "Slack webhook URL to send messags to",
env = "SLACK_WEBHOOK"
)]
pub slack_token: Option<String>,
#[clap(
long,
value_name = "SLACK_CHANNEL",
help = "Name of Slack channel to send messages to (has to be a public channel)",
env = "SLACK_CHANNEL"
)]
pub slack_channel: Option<String>,
pub slack_webhook: Option<String>,
#[clap(
long,
value_name = "DISCORD_WEBHOOK",
Expand Down
21 changes: 7 additions & 14 deletions subgraph-radio/src/operator/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use crate::config::Config;
#[derive(Clone, Debug, Getters, Serialize, Deserialize, PartialEq)]
pub struct Notifier {
radio_name: String,
slack_token: Option<String>,
slack_channel: Option<String>,
slack_webhook: Option<String>,
discord_webhook: Option<String>,
telegram_token: Option<String>,
telegram_chat_id: Option<i64>,
Expand All @@ -31,8 +30,7 @@ impl Notifier {
#[allow(clippy::too_many_arguments)]
pub fn new(
radio_name: String,
slack_token: Option<String>,
slack_channel: Option<String>,
slack_webhook: Option<String>,
discord_webhook: Option<String>,
telegram_token: Option<String>,
telegram_chat_id: Option<i64>,
Expand All @@ -41,8 +39,7 @@ impl Notifier {
) -> Notifier {
Notifier {
radio_name,
slack_token,
slack_channel,
slack_webhook,
discord_webhook,
telegram_token,
telegram_chat_id,
Expand All @@ -53,8 +50,7 @@ impl Notifier {

pub fn from_config(config: &Config) -> Self {
let radio_name = config.radio_setup().radio_name.clone();
let slack_token = config.radio_setup().slack_token.clone();
let slack_channel = config.radio_setup().slack_channel.clone();
let slack_webhook = config.radio_setup().slack_webhook.clone();
let discord_webhook = config.radio_setup().discord_webhook.clone();
let telegram_token = config.radio_setup().telegram_token.clone();
let telegram_chat_id = config.radio_setup().telegram_chat_id;
Expand All @@ -63,8 +59,7 @@ impl Notifier {

Notifier::new(
radio_name,
slack_token,
slack_channel,
slack_webhook,
discord_webhook,
telegram_token,
telegram_chat_id,
Expand All @@ -74,10 +69,8 @@ impl Notifier {
}

pub async fn notify(&self, content: String) {
if let (Some(token), Some(channel)) = (&self.slack_token, &self.slack_channel) {
if let Err(e) =
SlackBot::send_webhook(token.to_string(), channel, &self.radio_name, &content).await
{
if let Some(webhook_url) = &self.slack_webhook {
if let Err(e) = SlackBot::send_webhook(webhook_url, &self.radio_name, &content).await {
warn!(
err = tracing::field::debug(e),
"Failed to send notification to Slack"
Expand Down
1 change: 0 additions & 1 deletion template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ topics = ['QmacQnSgia4iDPWHpeY6aWxesRFdb8o5DKZUx96zZqEWrB']
gossip_topic_coverage = 'Comprehensive'
auto_upgrade_coverage = 'Comprehensive'
collect_message_duration = 10
slack_token = 'xoxb-1231231231231-2312312312312-3abcabcabcabacabcabcabca'
metrics_host = '0.0.0.0'
server_host = '0.0.0.0'
server_port = 7700
Expand Down
3 changes: 1 addition & 2 deletions test-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ pub fn test_config() -> Config {
log_level:
"off,hyper=off,graphcast_sdk=trace,subgraph_radio=trace,test_runner=trace"
.to_string(),
slack_token: None,
slack_channel: None,
slack_webhook: None,
discord_webhook: None,
metrics_host: String::new(),
metrics_port: None,
Expand Down
12 changes: 2 additions & 10 deletions test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,11 @@ pub fn start_radio(config: &Config) -> Child {
.arg(config.waku().waku_port.as_deref().unwrap_or("None"))
.arg("--log-level")
.arg(&config.radio_setup().log_level)
.arg("--slack-token")
.arg("--slack-webhook")
.arg(
config
.radio_setup()
.slack_token
.as_deref()
.unwrap_or("None"),
)
.arg("--slack-channel")
.arg(
config
.radio_setup()
.slack_channel
.slack_webhook
.as_deref()
.unwrap_or("None"),
)
Expand Down

0 comments on commit 1f707a3

Please sign in to comment.