Git Product home page Git Product logo

slackblocks's Introduction

slackblocks

PyPI - License Python Versions PyPI Downloads Build Status Coverage Status

What is it?

slackblocks is a Python API for building messages in the fancy new Slack Block Kit API.

It was created by Nicholas Lambourne for the UQCS Slack Bot because he hates writing JSON.

N.B: This is still WIP software and some of the more tricky interactive Block elements have yet to be implemented.

Requirements

slackblocks requires Python >= 3.6.

As of version 0.1.0 it has no dependencies outside the Python standard library.

Installation

pip install slackblocks

Usage

from slackblocks import Message, SectionBlock


block = SectionBlock("Hello, world!")
message = Message(channel="#general", blocks=block)
message.json()

Will produce the following JSON string:

{
    "channel": "#general",
    "mrkdwn": true,
    "blocks": [
        {
            "type": "section",
            "block_id": "992ceb6b-9ad4-496b-b8e6-1bd8a632e8b3",
            "text": {
                "type": "mrkdwn",
                "text": "Hello, world!",
                "verbatim": false
            }
        }
    ]
}

Which can be sent as payload to the Slack message API HTTP endpoints.

Of more practical uses is the ability to unpack the objects directly into the Python Slack Client in order to send messages:

from os import environ
from slack import WebClient
from slackblocks import Message, SectionBlock


client = WebClient(token=environ["SLACK_API_TOKEN"])
block = SectionBlock("Hello, world!")
message = Message(channel="#general", blocks=block)

response = client.chat_postMessage(**message)

Note the ** operator in front of the message object.

Can I use this in my project?

Yes, please do! The code is all open source and BSD-3.0 licensed.

slackblocks's People

Contributors

nicklambourne avatar andreweckart avatar confiq avatar braewebb avatar kennethtxytqw avatar tho-can-code avatar tris-tan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.