Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using tgram:// combined with other notification types in notifications settings, the tgram-specific notification length limit is applied to all #2299

Closed
leandertolksdorf opened this issue Apr 11, 2024 · 9 comments · Fixed by #2372
Assignees
Labels
Notifications systems Development of notifications of changes triage

Comments

@leandertolksdorf
Copy link

Describe the bug
When a long diff occurs, the notification sent to my notification targets get truncated, removing diff elements and invalidating the json I prepared in the notification body.

Two examples I just checked have a length of about 3200 characters, but not the same.

The issue occurs with the telegram target, as well as an HTTP request target.

Version
0.45.16

To Reproduce

My notification body:

{"watch_url": {{watch_url|tojson}}, "diff": {{diff_added|tojson}}}

The diff that caused the issue:
https://staking-roll-production.up.railway.app/diff/16755df2-fe52-45c3-be13-9dc105661a62#text

Expected behavior
A clear and concise description of what you expected to happen.

The whole diff is submitted in the notification body.

@dgtlmoon
Copy link
Owner

You dont say which notification target/protocol you are using...

@dgtlmoon
Copy link
Owner

Can you paste some example apprise URL you are using?

@leandertolksdorf
Copy link
Author

@dgtlmoon
I'm using a telegram URL and my own HTTP endpoint:

tgram://xxx/xxx
get://xxx:5000/handle

I just checked with a paste with a notification body {{diff_added|tojson}} and it seems that the diff is cut-off at 3557 characters.

Watch URL (I added the two long lines with numbers to check and both times the same cut-off):
https://paste.fo/raw/01393b9bc961

Diff:
https://staking-roll-production.up.railway.app/diff/9a7eb76a-c40c-4b2b-81a6-5376d33ce083?from_version=1712854181#text

Telegram Notification:
Bildschirmfoto 2024-04-11 um 18 53 24

HTTP-Notification:

Details "(added) 0*********10********20********30********40********50********60********70********80********90********100*******110*******120*******130*******140*******150*******160*******170*******180*******190*******200*******210*******220*******230*******240*******250*******260*******270*******280*******290*******300*******310*******320*******330*******340*******350*******360*******370*******380*******390*******400*******410*******420*******430*******440*******450*******460*******470*******480*******490*******500*******510*******520*******530*******540*******550*******560*******570*******580*******590*******600*******610*******620*******630*******640*******650*******660*******670*******680*******690*******700*******710*******720*******730*******740*******750*******760*******770*******780*******790*******800*******810*******820*******830*******840*******850*******860*******870*******880*******890*******900*******910*******920*******930*******940*******950*******960*******970*******980*******990*******1000******1010******1020******1030******1040******1050******1060******1070******1080******1090******1100******1110******1120******1130******1140******1150******1160******1170******1180******1190******1200******1210******1220******1230******1240******1250******1260******1270******1280******1290******1300******1310******1320******1330******1340******1350******1360******1370******1380******1390******1400******1410******1420******1430******1440******1450******1460******1470******1480******1490******1500******1510******1520******1530******1540******1550******1560******1570******1580******1590******1600******1610******1620******1630******1640******1650******1660******1670******1680******1690******1700******1710******1720******1730******1740******1750******1760******1770******1780******1790******1800******1810******1820******1830******1840******1850******1860******1870******1880******1890******1900******1910******1920******1930******1940******1950******1960******1970******1980******1990******2000******2010******2020******2030******2040******2050******2060******2070******2080******2090******2100******2110******2120******2130******2140******2150******2160******2170******2180******2190******2200******2210******2220******2230******2240******2250******2260******2270******2280******2290******2300******2310******2320******2330******2340******2350******2360******2370******2380******2390******2400******2410******2420******2430******2440******2450******2460******2470******2480******2490******2500******2510******2520******2530******2540******2550******2560******2570******2580******2590******2600******2610******2620******2630******2640******2650******2660******2670******2680******2690******2700******2710******2720******2730******2740******2750******2760******2770******2780******2790******2800******2810******2820******2830******2840******2850******2860******2870******2880******2890******2900******2910******2920******2930******2940******2950******2960******2970******2980******2990******3000******3010******3020******3030******3040******3050******3060******3070******3080******3090******3100******3110******3120******3130******3140******3150******3160******3170******3180******3190******3200******3210******3220******3230******3240******3250******3260******3270******3280******3290******3300******3310******3320******3330******3340******3350******3360******3370******3380******3390******3400******3410******3420******3430******3440******3450******3460******3470******3480******3490******3500******3510******3520******3530******3540******3550****

@dgtlmoon
Copy link
Owner

dgtlmoon commented Apr 11, 2024

@leandertolksdorf
Copy link
Author

@dgtlmoon This doesn‘t explain why the issue also occurs in the HTTP request. The link you provided also mentions a max length of 4096, why is the message then cut-off at 3557 characters?

@leandertolksdorf
Copy link
Author

leandertolksdorf commented Apr 11, 2024

@dgtlmoon
I did some more investigation and found the bug:

The issue occurs when a tgram:// (or any other length-limited notification service's) url is defined alongside a free-length service (like get:// etc.).

That's because in the function notification.process_notification the original n_body, defined in line 127 gets truncated in line 188 for all notification urls instead of just the length-limited one.

# notification.py

def process_notification(n_object, datastore):
    # ...
    # Get the notification body from datastore
    jinja2_env = Environment(loader=BaseLoader)
    n_body = jinja2_env.from_string(n_object.get('notification_body', '')).render(**notification_parameters)
    # ...
        for url in n_object['notification_urls']:
        # ...
            if url.startswith('tgram://'):
                # ...
                n_body = n_body[0:body_limit] # ‼️ n_body is now permanently truncated
        # ...
        apobj.notify(
            title=n_title,
            body=n_body, # ‼️ The truncated n_body gets sent to the other notification urls, too
            body_format=n_format,
            # False is not an option for AppRise, must be type None
            attach=n_object.get('screenshot', None)
        )

@leandertolksdorf
Copy link
Author

@dgtlmoon This is clearly a bug and unintended behavior. I'd be happy to fix this in a PR once I get to it but I don't think this issue should have been closed.

@dgtlmoon dgtlmoon reopened this Apr 15, 2024
@dgtlmoon
Copy link
Owner

@dgtlmoon This is clearly a bug and unintended behavior. I'd be happy to fix this in a PR once I get to it but I don't think this issue should have been closed.

it would help if you wrote in your initital bug report that you are using a mix of notification methods, is that the real issue then? that when tgram:// is specified, that limit of body size is applied to all subsequent notifications?

yes PR's are appreciated - but please include a test case (you can modify/add the existing notifications test case)

@dgtlmoon dgtlmoon changed the title Long notifications are truncated When using tgram:// AND other notification types in notifications settings, the tgram-specific notification length limit is applied to all Apr 15, 2024
@dgtlmoon dgtlmoon added the Notifications systems Development of notifications of changes label Apr 15, 2024
@dgtlmoon dgtlmoon changed the title When using tgram:// AND other notification types in notifications settings, the tgram-specific notification length limit is applied to all When using tgram:// combined with other notification types in notifications settings, the tgram-specific notification length limit is applied to all Apr 16, 2024
dgtlmoon added a commit that referenced this issue May 17, 2024
dgtlmoon added a commit that referenced this issue May 17, 2024
@dgtlmoon
Copy link
Owner

@leandertolksdorf heya! when https://github.com/dgtlmoon/changedetection.io/actions/runs/9124493904 is finished, can you try pull and test the :dev tag container?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Notifications systems Development of notifications of changes triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants