Skip to content

Commit

Permalink
email: add subject to email notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Dec 23, 2024
1 parent cea403a commit 5f3e275
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 31 deletions.
54 changes: 36 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,43 @@ There's configuration options for the trampoline plugin that can to be passed
to core lightning on startup.

```
--trampoline-payment-timeout <arg> Maximum time in seconds to attempt to find a route to the destination. (default: 60)
--trampoline-policy-cltv-delta <arg> Cltv expiry delta for the trampoline routing policy. Any routes where the total cltv delta is lower than this
number will not be tried. (default: 1008)
--trampoline-policy-fee-base <arg> The base fee to charge for every trampoline payment which passes through. (default: 0)
--trampoline-email-cc <arg> 'CC' addresses for payment failure notification emails. Format [\"Satoshi Nakamoto
<[email protected]>\",\"Hal Finney <[email protected]>\"]
--trampoline-email-to <arg> 'To' addresses for payment failure notification emails. Format [\"Satoshi Nakamoto
<[email protected]>\",\"Hal Finney <[email protected]>\"]
--trampoline-cltv-delta <arg> The number of blocks between incoming payments and outgoing payments: this needs to be enough to make sure
that if we have to, we can close the outgoing payment before the incoming, or redeem the incoming once the
outgoing is redeemed. (default: 34)
--trampoline-policy-fee-per-satoshi <arg> This is the proportional fee to charge for every trampoline payment which passes through. As percentages are
too coarse, it's in millionths, so 10000 is 1%, 1000 is 0.1%. (default: 5000)
--trampoline-no-self-route-hints If this flag is set, invoices where the current node is in an invoice route hint are not supported. This can
be useful if there are other important plugins acting only on forwards. The trampoline plugin will 'receive'
and 'pay', so has different dynamics.
--trampoline-email-from <arg> 'From' address for payment failure notification emails. Format \"Satoshi Nakamoto <[email protected]>\"
--trampoline-mpp-timeout <arg> Timeout in seconds before multipart htlcs that don't add up to the payment amount are failed back to the
--trampoline-cltv-delta <arg> The number of blocks between incoming payments and
outgoing payments: this needs to be enough to make
sure that if we have to, we can close the outgoing
payment before the incoming, or redeem the incoming
once the outgoing is redeemed. (default: 34)
--trampoline-email-cc <arg> 'CC' addresses for payment failure notification
emails. Format [\"Satoshi Nakamoto
<[email protected]>\",\"Hal Finney
<[email protected]>\"]
--trampoline-email-from <arg> 'From' address for payment failure notification
emails. Format \"Satoshi Nakamoto
<[email protected]>\"
--trampoline-email-subject <arg> 'Subject' for payment failure notification emails.
(default: Trampoline payment failure)
--trampoline-policy-cltv-delta <arg> Cltv expiry delta for the trampoline routing policy.
Any routes where the total cltv delta is lower than
this number will not be tried. (default: 1008)
--trampoline-policy-fee-base <arg> The base fee to charge for every trampoline payment
which passes through. (default: 0)
--trampoline-policy-fee-per-satoshi <arg> This is the proportional fee to charge for every
trampoline payment which passes through. As
percentages are too coarse, it's in millionths, so
10000 is 1%, 1000 is 0.1%. (default: 5000)
--trampoline-payment-timeout <arg> Maximum time in seconds to attempt to find a route to
the destination. (default: 60)
--trampoline-mpp-timeout <arg> Timeout in seconds before multipart htlcs that don't
add up to the payment amount are failed back to the
sender. (default: 60)
--trampoline-no-self-route-hints If this flag is set, invoices where the current node
is in an invoice route hint are not supported. This
can be useful if there are other important plugins
acting only on forwards. The trampoline plugin will
'receive' and 'pay', so has different dynamics.
--trampoline-email-to <arg> 'To' addresses for payment failure notification
emails. Format [\"Satoshi Nakamoto
<[email protected]>\",\"Hal Finney
<[email protected]>\"]
```

## Testing
Expand Down
21 changes: 11 additions & 10 deletions src/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ pub struct EmailNotificationService {
#[derive(Debug, Clone)]
struct Config {
client: Client,
from: String,
destination: Destination,
params: EmailParams,
}

#[derive(Debug, Clone)]
pub struct EmailParams {
pub from: String,
pub destination: Destination,
pub subject: String,
}

impl EmailNotificationService {
Expand Down Expand Up @@ -96,11 +97,7 @@ impl EmailNotificationService {
let client = Client::new(&aws_config);

Self {
config: Some(Config {
client,
from: params.from,
destination: params.destination,
}),
config: Some(Config { client, params }),
}
}
}
Expand All @@ -127,15 +124,19 @@ async fn notify(
.charset("UTF-8")
.data(req.to_html())
.build()?;
let subject = Content::builder()
.charset("UTF-8")
.data(config.params.subject.clone())
.build()?;
let body = Body::builder().html(html_content).build();
let message = Message::builder().body(body).build();
let message = Message::builder().body(body).subject(subject).build();
let email_content = EmailContent::builder().simple(message).build();

config
.client
.send_email()
.destination(config.destination.clone())
.from_email_address(config.from.clone())
.destination(config.params.destination.clone())
.from_email_address(config.params.from.clone())
.content(email_content)
.send()
.await?;
Expand Down
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use anyhow::{anyhow, Error};
use aws_sdk_sesv2::types::Destination;
use block_watcher::BlockWatcher;
use cln_plugin::{
options::{ConfigOption, DefaultIntegerConfigOption, FlagConfigOption, StringConfigOption},
options::{
ConfigOption, DefaultIntegerConfigOption, DefaultStringConfigOption, FlagConfigOption,
StringConfigOption,
},
ConfiguredPlugin,
};
use email::{EmailNotificationService, EmailParams};
Expand Down Expand Up @@ -91,6 +94,11 @@ const OPTION_EMAIL_TO: StringConfigOption = ConfigOption::new_str_no_default(
"trampoline-email-to",
"'To' addresses for payment failure notification emails. Format [\"Satoshi Nakamoto <[email protected]>\",\"Hal Finney <[email protected]>\"]",
);
const OPTION_EMAIL_SUBJECT: DefaultStringConfigOption = ConfigOption::new_str_with_default(
"trampoline-email-subject",
"Trampoline payment failure",
"'Subject' for payment failure notification emails.",
);

#[tokio::main]
async fn main() -> Result<(), Error> {
Expand All @@ -104,7 +112,8 @@ async fn main() -> Result<(), Error> {
.option(OPTION_PAYMENT_TIMEOUT)
.option(OPTION_EMAIL_CC)
.option(OPTION_EMAIL_FROM)
.option(OPTION_EMAIL_TO);
.option(OPTION_EMAIL_TO)
.option(OPTION_EMAIL_SUBJECT);

let cp = match builder.configure().await? {
Some(cp) => cp,
Expand Down Expand Up @@ -181,6 +190,7 @@ where
let from: Option<String> = cp.option(&OPTION_EMAIL_FROM)?;
let to: Option<String> = cp.option(&OPTION_EMAIL_TO)?;
let cc: Option<String> = cp.option(&OPTION_EMAIL_CC)?;
let subject: String = cp.option(&OPTION_EMAIL_SUBJECT)?;

let from = match from {
Some(from) => from,
Expand Down Expand Up @@ -210,5 +220,9 @@ where
.set_cc_addresses(cc)
.build();

Ok(Some(EmailParams { destination, from }))
Ok(Some(EmailParams {
destination,
from,
subject,
}))
}

0 comments on commit 5f3e275

Please sign in to comment.