Skip to content

Commit

Permalink
Merge pull request #180 from breez/savage-fix-link
Browse files Browse the repository at this point in the history
Fix using webhooks link
  • Loading branch information
dangeross authored Oct 22, 2024
2 parents 4c7a87d + fa32494 commit 205c1a2
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 39 deletions.
6 changes: 4 additions & 2 deletions snippets/csharp/Webhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public void RegisterWebhook(BlockingBreezServices sdk)
// ANCHOR: register-webook
try
{
sdk.RegisterWebhook("https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>");
var url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>";
sdk.RegisterWebhook(url);
}
catch (Exception)
{
Expand All @@ -21,7 +22,8 @@ public void UnregisterWebhook(BlockingBreezServices sdk)
// ANCHOR: unregister-webook
try
{
sdk.UnregisterWebhook("https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>");
var url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>";
sdk.UnregisterWebhook(url);
}
catch (Exception)
{
Expand Down
6 changes: 4 additions & 2 deletions snippets/dart_snippets/lib/webhook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import 'package:dart_snippets/sdk_instance.dart';

Future<void> registerWebhook() async {
// ANCHOR: register-webook
await breezSDK.registerWebhook(webhookUrl: "https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>");
String url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>";
await breezSDK.registerWebhook(webhookUrl: url);
// ANCHOR_END: register-webook
}

Future<void> unregisterWebhook() async {
// ANCHOR: unregister-webook
await breezSDK.unregisterWebhook(webhookUrl: "https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>");
String url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>";
await breezSDK.unregisterWebhook(webhookUrl: url);
// ANCHOR_END: unregister-webook
}
6 changes: 4 additions & 2 deletions snippets/go/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import (

func RegisterWebhook() {
// ANCHOR: register-webook
if err := sdk.RegisterWebhook("https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>"); err != nil {
url := "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>"
if err := sdk.RegisterWebhook(url); err != nil {
log.Printf("Webhook register failed: %v", err)
}
// ANCHOR_END: register-webook
}

func UnregisterWebhook() {
// ANCHOR: unregister-webook
if err := sdk.UnregisterWebhook("https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>"); err != nil {
url := "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>"
if err := sdk.UnregisterWebhook(url); err != nil {
log.Printf("Webhook unregister failed: %v", err)
}
// ANCHOR_END: unregister-webook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class Webhooks {
fun registerWebhook(sdk: BlockingBreezServices) {
// ANCHOR: register-webook
try {
sdk.registerWebhook("https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>")
val url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>"
sdk.registerWebhook(url)
} catch (e: Exception) {
// Handle error
}
Expand All @@ -15,7 +16,8 @@ class Webhooks {
fun unregisterWebhook(sdk: BlockingBreezServices) {
// ANCHOR: unregister-webook
try {
sdk.unregisterWebhook("https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>")
val url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>"
sdk.unregisterWebhook(url)
} catch (e: Exception) {
// Handle error
}
Expand Down
6 changes: 4 additions & 2 deletions snippets/python/src/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
def register_webhook(sdk_services):
try:
# ANCHOR: register-webook
sdk_services.register_webhook("https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>")
url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>"
sdk_services.register_webhook(url)
# ANCHOR_END: register-webook
except Exception as error:
print(error)
Expand All @@ -12,7 +13,8 @@ def register_webhook(sdk_services):
def unregister_webhook(sdk_services):
try:
# ANCHOR: unregister-webook
sdk_services.unregister_webhook("https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>")
url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>"
sdk_services.unregister_webhook(url)
# ANCHOR_END: unregister-webook
except Exception as error:
print(error)
Expand Down
6 changes: 4 additions & 2 deletions snippets/react-native/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { registerWebhook, unregisterWebhook } from '@breeztech/react-native-bree
const _registerWebhook = async () => {
// ANCHOR: register-webook
try {
await registerWebhook('https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>')
const url = 'https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>'
await registerWebhook(url)
} catch (err) {
console.error(err)
}
Expand All @@ -13,7 +14,8 @@ const _registerWebhook = async () => {
const _unregisterWebhook = async () => {
// ANCHOR: unregister-webook
try {
await unregisterWebhook('https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>')
const url = 'https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>'
await unregisterWebhook(url)
} catch (err) {
console.error(err)
}
Expand Down
12 changes: 4 additions & 8 deletions snippets/rust/src/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ use std::sync::Arc;

async fn register_webhook(sdk: Arc<BreezServices>) -> Result<()> {
// ANCHOR: register-webook
sdk.register_webhook(
"https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>".to_string(),
)
.await?;
let url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>".to_string();
sdk.register_webhook(url).await?;
// ANCHOR_END: register-webook

Ok(())
}

async fn unregister_webhook(sdk: Arc<BreezServices>) -> Result<()> {
// ANCHOR: unregister-webook
sdk.unregister_webhook(
"https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>".to_string(),
)
.await?;
let url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>".to_string();
sdk.unregister_webhook(url).await?;
// ANCHOR_END: unregister-webook

Ok(())
Expand Down
6 changes: 4 additions & 2 deletions snippets/swift/BreezSDKExamples/Sources/Webhook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import BreezSDK

func registerWebhook(sdk: BlockingBreezServices) throws {
// ANCHOR: register-webook
try sdk.registerWebhook(webhookUrl: "https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>")
let url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>"
try sdk.registerWebhook(webhookUrl: url)
// ANCHOR_END: register-webook
}

func unregisterWebhook(sdk: BlockingBreezServices) throws {
// ANCHOR: unregister-webook
try sdk.unregisterWebhook(webhookUrl: "https://your-nds-service.com/notify?platform=ios&token=<PUSH_TOKEN>")
let url = "https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>"
try sdk.unregisterWebhook(webhookUrl: url)
// ANCHOR_END: unregister-webook
}
12 changes: 6 additions & 6 deletions src/guide/payment_notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ By default the Notification Plugin should receive the push notification data in
{
"notification_type": "payment_received",
"notification_payload": "{ \"payment_hash\": \"\" }",
"app_data": ""
"app_data": "..."
}
```
The structure and fields of this data can be changed by [customising the push messages](/notifications/custom_messages.md) handling in the Notification Plugin to reflect how your NDS sends this data over push notifications.
Expand All @@ -36,7 +36,7 @@ The `payment_received` notification type will be received by the webhook in the
{
"template": "payment_received",
"data": {
"payment_hash": "" // The payment hash that is in progress
"payment_hash": "..." // The payment hash that is in progress
}
}
```
Expand All @@ -50,7 +50,7 @@ The `address_txs_confirmed` notification type will be received by the webhook in
{
"template": "address_txs_confirmed",
"data": {
"address": "" // The address of the swap with confirmed funds
"address": "..." // The address of the swap with confirmed funds
}
}
```
Expand All @@ -66,8 +66,8 @@ The `lnurlpay_info` notification type will be received by the webhook in the fol
{
"template": "lnurlpay_info",
"data": {
"callback_url": "", // The URL of the LNURL service
"reply_url": "" // The URL to reply to this request
"callback_url": "...", // The URL of the LNURL service
"reply_url": "..." // The URL to reply to this request
}
}
```
Expand All @@ -79,7 +79,7 @@ The `lnurlpay_invoice` notification type will be received by the webhook in the
"template": "lnurlpay_invoice",
"data": {
"amount": 0, // The amount in millisatoshis within the min/max sendable range
"reply_url": "" // The URL to reply to this request
"reply_url": "..." // The URL to reply to this request
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/notifications/custom_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The Notification Plugin by default handles a specific format of push notificatio
{
"notification_type": "payment_received",
"notification_payload": "{ \"payment_hash\": \"\" }",
"app_data": ""
"app_data": "..."
}
```

Expand Down
12 changes: 6 additions & 6 deletions src/notifications/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ By default the Notification Plugin should receive the push notification data in
{
"notification_type": "payment_received",
"notification_payload": "{ \"payment_hash\": \"\" }",
"app_data": ""
"app_data": "..."
}
```
The structure and fields of this data can be changed by [customising the push messages](custom_messages.md) handling in the Notification Plugin to reflect how your NDS sends this data over push notifications.
Expand All @@ -36,7 +36,7 @@ The `payment_received` notification type will be received by the webhook in the
{
"template": "payment_received",
"data": {
"payment_hash": "" // The payment hash that is in progress
"payment_hash": "..." // The payment hash that is in progress
}
}
```
Expand All @@ -50,7 +50,7 @@ The `address_txs_confirmed` notification type will be received by the webhook in
{
"template": "address_txs_confirmed",
"data": {
"address": "" // The address of the swap with confirmed funds
"address": "..." // The address of the swap with confirmed funds
}
}
```
Expand All @@ -66,8 +66,8 @@ The `lnurlpay_info` notification type will be received by the webhook in the fol
{
"template": "lnurlpay_info",
"data": {
"callback_url": "", // The URL of the LNURL service
"reply_url": "" // The URL to reply to this request
"callback_url": "...", // The URL of the LNURL service
"reply_url": "..." // The URL to reply to this request
}
}
```
Expand All @@ -79,7 +79,7 @@ The `lnurlpay_invoice` notification type will be received by the webhook in the
"template": "lnurlpay_invoice",
"data": {
"amount": 0, // The amount in millisatoshis within the min/max sendable range
"reply_url": "" // The URL to reply to this request
"reply_url": "..." // The URL to reply to this request
}
}
```
Expand Down
8 changes: 4 additions & 4 deletions src/notifications/setup_nds.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

Receiving push notifications involves using an Notification Delivery Service (NDS) as an intermediary to receive the webhook event from one of the SDK services. These can be currently one of several services that provide information about events that the Breez SDK registers for. For example, payment events from the LSP or swap transaction confirmation events from the chain service. The NDS then processes this information and dispatches a push notification to the intended mobile device, ensuring the user receives timely updates about incoming events. This architecture necessitates developers set up and maintain their own NDS, tailored to handle and forward these notifications efficiently. An example payload when a `payment_received` POST request to the webhook URL contains the following JSON formatted structure:

```
```json
{
"template": "payment_received",
"data": {
"payment_hash": [payment hash]
"payment_hash": "..." // The payment hash that is in progress
}
}
```

The need to run your own NDS is because it's configured to send push notifications to your application users and therefore should be configured with the required keys and certificates. You can use our [reference NDS implementation](https://github.com/breez/notify) as a starting point or as is. Our implementation of the NDS expects URLs in the following format:
```
https://your-nds-service.com/notify?platform=<ios|android>&token=[PUSH_TOKEN]
https://your-nds-service.com/notify?platform=<ios|android>&token=<PUSH_TOKEN>
```



This is the same format used when [registering a webhook](register_webhook.md) in the Breez SDK, replacing the `PUSH_TOKEN` with the mobile push token. Once the NDS has received such request it will send a push notification to the corresponding device.
This is the same format used when [registering a webhook](using_webhooks.md) in the Breez SDK, replacing the `<PUSH_TOKEN>` with the mobile push token. Once the NDS has received such request it will send a push notification to the corresponding device.

## Mobile push token
Ensure that your mobile application is set up to receive push notifications and can generate a push token. This token uniquely identifies the device for push notifications.
Expand Down

0 comments on commit 205c1a2

Please sign in to comment.