-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
232 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 43 additions & 43 deletions
86
notifico-web/assets/assets/index-BhrsKVmZ.js → notifico-web/assets/assets/index-Cj_sEHdQ.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "notifico-pushover" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
notifico-core = { path = "../../notifico-core" } | ||
reqwest = { workspace = true } | ||
async-trait = "0.1.83" | ||
serde = "1.0.215" | ||
serde_json = "1.0.133" | ||
serde_urlencoded = "0.7.1" | ||
thiserror = "2.0.3" | ||
url = "2.5.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
mod step; | ||
|
||
use crate::step::{Step, STEPS}; | ||
use async_trait::async_trait; | ||
use notifico_core::credentials::{CredentialStorage, TypedCredential}; | ||
use notifico_core::engine::{EnginePlugin, PipelineContext, StepOutput}; | ||
use notifico_core::error::EngineError; | ||
use notifico_core::recipient::TypedContact; | ||
use notifico_core::recorder::Recorder; | ||
use notifico_core::step::SerializedStep; | ||
use notifico_core::templater::RenderedTemplate; | ||
use serde::{Deserialize, Serialize}; | ||
use std::borrow::Cow; | ||
use std::sync::Arc; | ||
use url::Url; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct PushoverCredentials { | ||
token: String, | ||
} | ||
|
||
impl TypedCredential for PushoverCredentials { | ||
const CREDENTIAL_TYPE: &'static str = "pushover"; | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
struct PushoverMessageRequest { | ||
token: String, | ||
user: String, | ||
message: String, | ||
|
||
attachment_base64: Option<String>, | ||
attachment_type: Option<String>, | ||
|
||
device: Option<String>, | ||
html: Option<u8>, | ||
priority: Option<i8>, | ||
sound: Option<String>, | ||
timestamp: Option<u64>, | ||
title: Option<String>, | ||
ttl: Option<u64>, | ||
url: Option<Url>, | ||
url_title: Option<String>, | ||
} | ||
|
||
pub struct PushoverPlugin { | ||
client: reqwest::Client, | ||
credentials: Arc<dyn CredentialStorage>, | ||
recorder: Arc<dyn Recorder>, | ||
} | ||
|
||
impl PushoverPlugin { | ||
pub fn new(credentials: Arc<dyn CredentialStorage>, recorder: Arc<dyn Recorder>) -> Self { | ||
Self { | ||
client: reqwest::Client::new(), | ||
credentials, | ||
recorder, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl EnginePlugin for PushoverPlugin { | ||
async fn execute_step( | ||
&self, | ||
context: &mut PipelineContext, | ||
step: &SerializedStep, | ||
) -> Result<StepOutput, EngineError> { | ||
let step: Step = step.clone().convert_step()?; | ||
|
||
match step { | ||
Step::Send { credential } => { | ||
let credential: PushoverCredentials = self | ||
.credentials | ||
.get_typed_credential(context.project_id, &credential) | ||
.await?; | ||
|
||
let contact: PushoverContact = context.get_contact()?; | ||
|
||
for message in context.messages.iter().cloned() { | ||
let content: Message = message.content.try_into()?; | ||
let request = PushoverMessageRequest { | ||
token: credential.token.clone(), | ||
user: contact.user.clone(), | ||
message: content.text, | ||
attachment_base64: None, | ||
attachment_type: None, | ||
device: None, | ||
html: Some(1), | ||
priority: None, | ||
sound: None, | ||
timestamp: None, | ||
title: Some(content.title), | ||
ttl: None, | ||
url: None, | ||
url_title: None, | ||
}; | ||
|
||
let result = self | ||
.client | ||
.post("https://api.pushover.net/1/messages.json") | ||
.body(serde_urlencoded::to_string(request).unwrap_or_default()) | ||
.send() | ||
.await; | ||
|
||
match result { | ||
Ok(_) => self.recorder.record_message_sent( | ||
context.event_id, | ||
context.notification_id, | ||
message.id, | ||
), | ||
Err(e) => self.recorder.record_message_failed( | ||
context.event_id, | ||
context.notification_id, | ||
message.id, | ||
&e.to_string(), | ||
), | ||
} | ||
} | ||
Ok(StepOutput::Continue) | ||
} | ||
} | ||
} | ||
|
||
fn steps(&self) -> Vec<Cow<'static, str>> { | ||
STEPS.iter().map(|&s| s.into()).collect() | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone)] | ||
struct PushoverContact { | ||
user: String, | ||
} | ||
|
||
impl TypedContact for PushoverContact { | ||
const CONTACT_TYPE: &'static str = "pushover"; | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone)] | ||
pub struct Message { | ||
pub text: String, | ||
pub title: String, | ||
} | ||
|
||
impl TryFrom<RenderedTemplate> for Message { | ||
type Error = EngineError; | ||
|
||
fn try_from(value: RenderedTemplate) -> Result<Self, Self::Error> { | ||
Ok(Self { | ||
text: value.get("text")?.to_string(), | ||
title: value.get("title")?.to_string(), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
#[serde(tag = "step")] | ||
pub enum Step { | ||
#[serde(rename = "pushover.send")] | ||
Send { credential: String }, | ||
} | ||
|
||
pub(crate) const STEPS: &[&str] = &["pushover.send"]; |