Skip to content

Slack Blocks API support using notify(...body_format="json") #1337

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

operatorequals
Copy link

@operatorequals operatorequals commented May 18, 2025

Description:

Related issue (if applicable): #641

This PR works towards the comment found here: #641 (comment)

As AppRise does not handle templating universally, it is possible that users have their templates in their code. This PR makes it possible to pass JSON string to body of the Slack plugin to utilize the Blocks API.

As a result, this code should work:

apprise_obj = apprise.Apprise()
apprise_obj.add("...&blocks=yes")

body = json.dumps({"blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Hey there 👋"
      }
    }
  ]
})


apprise_obj.notify(body=body, title="TITLE", body_format='json')

This will honour the title as well as footer and color set by the notify_type.

Finally, the code will fail if the blocks parameter is NOT set in the URL.

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • No lint errors (use flake8)
  • 100% test coverage

Testing

Anyone can help test this source code as follows:

# Create a virtual environment to work in as follows:
python3 -m venv apprise

# Change into our new directory
cd apprise

# Activate our virtual environment
source bin/activate

# Install the branch
pip install git+https://github.com/caronc/apprise.git@<this.branch-name>

# Test out the changes with the following command:
apprise -t "Test Title" -b "Test Message" \
  <apprise url related to ticket>

@joarobles
Copy link

Nice! Looks good to me

@caronc
Copy link
Owner

caronc commented May 24, 2025

I get the direction you're going with this.... Apprise to handle to overhead of setting up all of the connection overhead to where you provide the raw data yourself. To make this more flexible so people cna make custom discord, telegram, and other raw over-rides... it may be better to not use json, but have body_type be raw. Also, should be updated in common.py as a global so it can be used everywhere else too.

Also... more thought is needed i think as input cna be text, html, markdown, and if specified apprise can toggle.. should raw be something set here? Or having it in the URL (granting uses the ability to over-ride it from there) wouldn't pose any issues down the road?

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

Successfully merging this pull request may close these issues.

3 participants