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

Cannot post to Discord some complex messages #1241

Open
auanasgheps opened this issue Nov 19, 2024 · 6 comments
Open

Cannot post to Discord some complex messages #1241

auanasgheps opened this issue Nov 19, 2024 · 6 comments
Labels

Comments

@auanasgheps
Copy link

📣 Notification Service(s) Impacted
Discord

🐞 Describe the bug
I'm unable to post some messages to Discord. It seems that it gets crazy when complex text/characters are posted, and Apprise throws Bad Request - Unsupported Parameters., error=400.

I own a shell script that manages SnapRAID operations and I just started integrating it with Apprise.
This issue is present only with a specific output that I'm trying to post to Discord. I'm sure it's something to do with escaping, but I don't know much about this topic.
However, the same exact output can be posted to Telegram with no issues.

I've attacched a very dumb test script to replicate the issue but you need SnapRAID installed.

#!/bin/bash
function main(){

function show_snapraid_info() {
  local command_output=$($1)
  echo "$2"
  echo "\`\`\`"
  echo "$command_output"
  echo "\`\`\`"
  INFO_MESSAGE="$2 - \`\`\`$command_output\`\`\`"
  }


APPRISE_URL="discord://<webhook url>"

# Run info command
show_snapraid_info "snapraid status" "### SnapRAID Status"


# Send the message via Apprise to Discord
apprise -vvv -b "Test" -b "$INFO_MESSAGE" "$APPRISE_URL"?format=markdown
}

main

I've attached the command ouput because GitHub isn't able to format it properly
apprise script output.txt

💡 Screenshots and Logs

The same output successfully posted to Telegram by only chaning the URL

immagine

💻 Your System Details:

  • OS: Debian 11
  • Python Version: Python 3.11.2
  • Apprise 1.9.0 installed via pipx

🔮 Additional context
Simpler messages can be posted to Discord, no problem.

@caronc
Copy link
Owner

caronc commented Nov 20, 2024

I notice you're trying to push the content as markdown (in the Apprise URL you used) the table as you share it is very broken Markdown, so it makes sense that maybe this is why the Discord server is rejecting your message.

what happens if you do something like: ?format=text instead?

Does it work then?

@auanasgheps
Copy link
Author

If i disable the markdown command, it works:

immagine

Same if I add "?format=text" but I believe it's the default option.

How should I tackle such scenario?

Telegram just works fine and formats markdown properly. I tried local markdown formatting before sending the message but doesn't work well.

@caronc
Copy link
Owner

caronc commented Nov 28, 2024

It's not that it isn't working, it's just trying to interpret what you provide it as Markdown.

I could change the default to text. A lot of people use Discord, so it may have repercussions. Apprise URLs are usually built once and never change thereafter.

If you control the input and 'know' it is text, and yours controlling the Apprise call under the hood, then absolutely tell it you're feeding it text. Use option one above.

@caronc
Copy link
Owner

caronc commented Dec 15, 2024

Any update to this or can i close this off?

@auanasgheps
Copy link
Author

Apologies for the delay, I didn't had the time to continue this project. Please allow some days as I should work on this

@auanasgheps
Copy link
Author

auanasgheps commented Dec 20, 2024

So I ended up with a workaround, but it's not really a fix: if discord:// is found in the array of Apprise URLs I don't format it as markdown (ugly, but works), otherwise it uses markdown.

I think the problem is in Discord, not Apprise, because other services handle the same conent perfectly fine.

You can close this if you want.

 if [ "$APPRISE" -eq 1 ]; then
    for APPRISE_URL_U in "${APPRISE_URL[@]}"; do
        if [[ "$APPRISE_URL_U" == *"discord://"* ]]; then
            # For Discord, use the URL without format (markdown) parameter
            "$APPRISE_BIN" -v -b "$INFO_MESSAGE" "$APPRISE_URL_U"
        else
            # For all other services, use markdown formatting
            APPRISE_URL_FORMAT="${APPRISE_URL_U}?format=markdown"
            "$APPRISE_BIN" -v -b "$INFO_MESSAGE" "$APPRISE_URL_FORMAT"
        fi
    done
  fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants