jmcore.notifications
jmcore.notifications
Notification system for JoinMarket components.
Provides operator notifications through Apprise, supporting multiple notification channels (Gotify, Telegram, Pushover, Discord, email, etc.).
Configuration is via environment variables: - NOTIFY_URLS: Comma-separated list of Apprise URLs (required to enable notifications) - NOTIFY_ENABLED: Set to "false" to disable all notifications (default: true if NOTIFY_URLS set) - NOTIFY_TITLE_PREFIX: Prefix for notification titles (default: "JoinMarket")
Example NOTIFY_URLS: - Gotify: gotify://hostname/token - Telegram: tgram://bot_token/chat_id - Pushover: pover://user_key@token - Discord: discord://webhook_id/webhook_token - Slack: slack://hook_id - Email: mailto://user:pass@smtp.example.com - Multiple: gotify://host/token,tgram://bot/chat
For full list of supported services: https://github.com/caronc/apprise#supported-notifications
Usage: from jmcore.notifications import get_notifier
notifier = get_notifier()
await notifier.notify_fill_request(taker_nick, cj_amount, offer_id)
The module is designed to be: 1. Fire-and-forget: Notification failures don't affect protocol operations 2. Async-first: All notifications are sent asynchronously 3. Privacy-aware: Sensitive data (txids, amounts) can be optionally excluded 4. Configurable: Per-event type enable/disable through environment variables 5. Resilient: Failed notifications are retried in the background with exponential backoff (configurable, enabled by default). This is critical for Tor-routed notifications where transient circuit failures are common.
Attributes
__all__ = ['NotificationConfig', 'NotificationPriority', 'Notifier', 'get_notifier', 'reset_notifier', 'load_notification_config', 'convert_settings_to_notification_config']
module-attribute
Classes
NotificationConfig
Bases: BaseModel
Configuration for the notification system.
All configuration is loaded from environment variables.
Source code in jmcore/src/jmcore/notifications.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
Attributes
check_for_updates: bool = Field(default=False, description='Check GitHub for new releases and include version info in summary notifications. PRIVACY WARNING: polls api.github.com each summary interval.')
class-attribute
instance-attribute
component_name: str = Field(default='', description="Component name to include in notification titles (e.g., 'Maker', 'Taker')")
class-attribute
instance-attribute
enabled: bool = Field(default=False, description='Master switch for notifications')
class-attribute
instance-attribute
include_amounts: bool = Field(default=True, description='Include amounts in notifications')
class-attribute
instance-attribute
include_nick: bool = Field(default=True, description='Include peer nicks in notifications')
class-attribute
instance-attribute
include_txids: bool = Field(default=False, description='Include transaction IDs in notifications (privacy risk)')
class-attribute
instance-attribute
model_config = {'frozen': False}
class-attribute
instance-attribute
notify_all_disconnect: bool = Field(default=True, description='Notify when ALL directory servers are disconnected (critical)')
class-attribute
instance-attribute
notify_coinjoin_complete: bool = Field(default=True, description='Notify on CoinJoin complete')
class-attribute
instance-attribute
notify_coinjoin_failed: bool = Field(default=True, description='Notify on CoinJoin failure')
class-attribute
instance-attribute
notify_coinjoin_start: bool = Field(default=True, description='Notify on CoinJoin start')
class-attribute
instance-attribute
notify_confirmed: bool = Field(default=True, description='Notify on confirmation')
class-attribute
instance-attribute
notify_disconnect: bool = Field(default=False, description='Notify on individual directory server disconnect/reconnect (noisy)')
class-attribute
instance-attribute
notify_fill: bool = Field(default=True, description='Notify on !fill requests')
class-attribute
instance-attribute
notify_mempool: bool = Field(default=True, description='Notify on mempool detection')
class-attribute
instance-attribute
notify_nick_change: bool = Field(default=True, description='Notify on nick change')
class-attribute
instance-attribute
notify_peer_events: bool = Field(default=False, description='Notify on peer connect/disconnect')
class-attribute
instance-attribute
notify_rate_limit: bool = Field(default=True, description='Notify on rate limit bans')
class-attribute
instance-attribute
notify_rejection: bool = Field(default=True, description='Notify on rejections')
class-attribute
instance-attribute
notify_signing: bool = Field(default=True, description='Notify on tx signing')
class-attribute
instance-attribute
notify_startup: bool = Field(default=True, description='Notify on component startup')
class-attribute
instance-attribute
notify_summary: bool = Field(default=True, description='Send periodic summary notifications with CoinJoin stats')
class-attribute
instance-attribute
retry_base_delay: float = Field(default=5.0, ge=1.0, le=60.0, description='Base delay in seconds before the first retry (1-60). Subsequent retries double this delay (exponential backoff).')
class-attribute
instance-attribute
retry_enabled: bool = Field(default=True, description='Retry failed notifications in the background. Retries use exponential backoff and never block the main process.')
class-attribute
instance-attribute
retry_max_attempts: int = Field(default=3, ge=1, le=10, description='Maximum number of retry attempts for a failed notification (1-10)')
class-attribute
instance-attribute
stream_isolation: bool = Field(default=True, description='Use SOCKS5 auth credentials to isolate notification and update-check traffic onto separate Tor circuits (only used if use_tor=True)')
class-attribute
instance-attribute
summary_interval_hours: int = Field(default=24, ge=1, le=168, description='Interval in hours between summary notifications (1-168). Common values: 24 (daily), 168 (weekly)')
class-attribute
instance-attribute
title_prefix: str = Field(default='JoinMarket NG', description='Prefix for all notification titles')
class-attribute
instance-attribute
tor_socks_host: str = Field(default='127.0.0.1', description='Tor SOCKS5 proxy host (only used if use_tor=True)')
class-attribute
instance-attribute
tor_socks_port: int = Field(default=9050, ge=1, le=65535, description='Tor SOCKS5 proxy port (only used if use_tor=True)')
class-attribute
instance-attribute
urls: list[SecretStr] = Field(default_factory=list, description='List of Apprise notification URLs')
class-attribute
instance-attribute
use_tor: bool = Field(default=True, description='Route notifications through Tor SOCKS proxy')
class-attribute
instance-attribute
NotificationPriority
Bases: StrEnum
Notification priority levels (maps to Apprise NotifyType).
Source code in jmcore/src/jmcore/notifications.py
53 54 55 56 57 58 59 | |
Attributes
FAILURE = 'failure'
class-attribute
instance-attribute
INFO = 'info'
class-attribute
instance-attribute
SUCCESS = 'success'
class-attribute
instance-attribute
WARNING = 'warning'
class-attribute
instance-attribute
Notifier
Notification sender using Apprise.
Thread-safe and async-friendly. Notification failures are logged but don't raise exceptions - notifications should never block protocol operations.
Failed notifications are automatically retried in the background with exponential backoff when retry_enabled is True (the default). This is important for Tor-routed notifications where transient circuit failures are common.
Source code in jmcore/src/jmcore/notifications.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 | |
Attributes
config = config or load_notification_config()
instance-attribute
Functions
__init__(config: NotificationConfig | None = None)
Initialize the notifier.
Args: config: Notification configuration. If None, loads from environment.
Source code in jmcore/src/jmcore/notifications.py
297 298 299 300 301 302 303 304 305 306 307 308 | |
notify(title: str, body: str, priority: NotificationPriority = NotificationPriority.INFO) -> bool
async
Send a generic notification.
Source code in jmcore/src/jmcore/notifications.py
1024 1025 1026 1027 1028 1029 1030 1031 | |
notify_all_directories_disconnected() -> bool
async
Notify when disconnected from ALL directory servers (critical).
Source code in jmcore/src/jmcore/notifications.py
779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
notify_all_directories_reconnected(connected_count: int, total_count: int) -> bool
async
Notify when at least one directory server is reconnected after all were lost (recovery).
Source code in jmcore/src/jmcore/notifications.py
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | |
notify_coinjoin_complete(txid: str, cj_amount: int, num_makers: int, total_fees: int) -> bool
async
Notify when CoinJoin completes successfully (taker).
Source code in jmcore/src/jmcore/notifications.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
notify_coinjoin_failed(reason: str, phase: str = '', cj_amount: int = 0) -> bool
async
Notify when CoinJoin fails (taker).
Source code in jmcore/src/jmcore/notifications.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 | |
notify_coinjoin_start(cj_amount: int, num_makers: int, destination: str) -> bool
async
Notify when CoinJoin is initiated (taker).
Source code in jmcore/src/jmcore/notifications.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
notify_confirmed(txid: str, cj_amount: int, confirmations: int, role: str = 'maker') -> bool
async
Notify when CoinJoin is confirmed.
Source code in jmcore/src/jmcore/notifications.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
notify_directory_disconnect(server: str, connected_count: int, total_count: int, reconnecting: bool = True) -> bool
async
Notify when disconnected from a directory server.
Source code in jmcore/src/jmcore/notifications.py
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | |
notify_directory_reconnect(server: str, connected_count: int, total_count: int) -> bool
async
Notify when successfully reconnected to a directory server.
Source code in jmcore/src/jmcore/notifications.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
notify_fill_request(taker_nick: str, cj_amount: int, offer_id: int) -> bool
async
Notify when a !fill request is received (maker).
Source code in jmcore/src/jmcore/notifications.py
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
notify_maker_offline(nick: str, last_seen: str) -> bool
async
Notify when a maker goes offline.
Source code in jmcore/src/jmcore/notifications.py
975 976 977 978 979 980 981 982 983 984 985 | |
notify_mempool(txid: str, cj_amount: int, role: str = 'maker') -> bool
async
Notify when CoinJoin is seen in mempool.
Source code in jmcore/src/jmcore/notifications.py
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
notify_nick_change(old_nick: str, new_nick: str) -> bool
async
Notify when maker nick changes (privacy feature).
Source code in jmcore/src/jmcore/notifications.py
738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
notify_orderbook_status(connected_directories: int, total_directories: int, total_offers: int, total_makers: int) -> bool
async
Notify orderbook status summary.
Source code in jmcore/src/jmcore/notifications.py
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 | |
notify_peer_banned(nick: str, reason: str, duration: int) -> bool
async
Notify when a peer is banned for rate limit violations.
Source code in jmcore/src/jmcore/notifications.py
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 | |
notify_peer_connected(nick: str, location: str, total_peers: int) -> bool
async
Notify when a new peer connects (directory server).
Source code in jmcore/src/jmcore/notifications.py
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 | |
notify_peer_disconnected(nick: str, total_peers: int) -> bool
async
Notify when a peer disconnects (directory server).
Source code in jmcore/src/jmcore/notifications.py
922 923 924 925 926 927 928 929 930 931 932 933 934 935 | |
notify_rejection(taker_nick: str, reason: str, details: str = '') -> bool
async
Notify when rejecting a taker request (maker).
Source code in jmcore/src/jmcore/notifications.py
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
notify_startup(component: str, version: str = '', network: str = '', nick: str = '') -> bool
async
Notify when a component starts up.
Args: component: Component name (e.g., "Maker", "Taker", "Directory", "Orderbook Watcher") version: Optional version string network: Optional network name (e.g., "mainnet", "signet") nick: Optional component nick (e.g., "J5XXXXXXXXX")
Source code in jmcore/src/jmcore/notifications.py
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 | |
notify_summary(period_label: str, total_requests: int, successful: int, failed: int, total_earnings: int, total_volume: int, successful_volume: int = 0, utxos_disclosed: int = 0, version: str | None = None, update_available: str | None = None) -> bool
async
Send a periodic summary notification with CoinJoin statistics.
Args: period_label: Human-readable period (e.g., "Daily", "Weekly") total_requests: Total CoinJoin requests in the period successful: Number of successful CoinJoins failed: Number of failed CoinJoins total_earnings: Total fees earned in sats total_volume: Total CoinJoin volume in sats (all requests) successful_volume: CoinJoin volume in sats (successful only) utxos_disclosed: Number of UTXOs disclosed to takers version: Current version string (e.g., "0.15.0"), shown if provided update_available: Latest version string if an update is available, None otherwise
Source code in jmcore/src/jmcore/notifications.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
notify_tx_signed(taker_nick: str, cj_amount: int, num_inputs: int, fee_earned: int) -> bool
async
Notify when transaction is signed (maker).
Source code in jmcore/src/jmcore/notifications.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
Functions
convert_settings_to_notification_config(settings: JoinMarketSettings, component_name: str = '') -> NotificationConfig
Convert NotificationSettings from JoinMarketSettings to NotificationConfig.
This allows the notification system to use the unified settings system (config file + env vars + CLI args) instead of only environment variables.
Args: settings: JoinMarketSettings instance with notification configuration component_name: Optional component name to include in notification titles. If provided, overrides settings.notifications.component_name. Examples: "Maker", "Taker", "Directory", "Orderbook Watcher"
Returns: NotificationConfig suitable for use with Notifier
Source code in jmcore/src/jmcore/notifications.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
get_notifier(settings: JoinMarketSettings | None = None, component_name: str = '') -> Notifier
Get the global Notifier instance.
The notifier is lazily initialized on first use. Configuration is loaded from JoinMarketSettings if provided, otherwise from environment variables.
Args: settings: Optional JoinMarketSettings instance. If provided, notification configuration will be taken from settings.notifications (which supports config file + env vars + CLI args). If None, falls back to environment variables only (legacy). component_name: Component name to include in notification titles. Examples: "Maker", "Taker", "Directory", "Orderbook Watcher". This makes it easier to identify which component sent a notification when running multiple JoinMarket components.
Returns: Notifier instance
Source code in jmcore/src/jmcore/notifications.py
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | |
load_notification_config() -> NotificationConfig
Load notification configuration from the unified settings system.
This function uses JoinMarketSettings which loads from: 1. Environment variables (NOTIFICATIONS__, TOR__) 2. Config file (~/.joinmarket-ng/config.toml) 3. Default values
Source code in jmcore/src/jmcore/notifications.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
reset_notifier() -> None
Reset the global notifier (useful for testing).
Source code in jmcore/src/jmcore/notifications.py
1076 1077 1078 1079 | |