Package: slackapptk
Python3 Toolkit for building Slack appsTheslackapptkpackage is used to facilitate the development of Slack
applications using Python3 and your choice of web frameworks.  As a developer
of Slack apps in Python, I want a library that would allow me to accomplish two
primary goals:Provide a mechanism to route messages received fromapi.slack.comto
the proper code in my app.  This process is sometimes referred to callback
routing.Create /slash-commands with a rich set of feature capabiltiies as
found using the Python standardargparsepackage.NOTE:  The slapapptk package uses the Slack providedslackclientpackage and is not meant to be a replacement.  That said, there arewidgetsdefined
inslackapptk.webthat are not yet available in slackclient; and as slackclient is updated
these widgets will be depreciatedNOTE: For SlackClient <= 2.5If you are looking to develop on the Slack Client 2.5.0 release, please use the branchv1.TLDR; See working exampleThe documentation for usingslackapptkis currently under development.  That
said you can find a complete working example that uses the Flask web-framework
inexample-slackapp; see thatREADME.mdmore details.OverviewA Slack app can receive messages from api.slack.com for a number of reasons and depending
on the way the app was configured in the api.slack.com portal.For the purpose of thisREADMEthe termentrypointwill be used:User entered a/slash-commandUser initiaties some kind ofinteractivityrequest, for example clicking a buttonUser actuates a dropdown and the app has to fetch data from anexternal sourceUser selected anactionattached to a Slack messageApp receives a SlackEventas a result of its configured subscriptionsThe termrequestwill refer to the message recieved from api.slack.com as a result of
any of these entrpoints.When the app is configured in the api.slack.com portal, the developer will
identify the specific app API routes to invoke.  The developer would then need
to write the prerequist code handlers using their API framework of choice,
Flask for example.To create a an app instance:fromslackapptk.appimportSlackAppapp=SlackApp()app.config.token="<My app bot token value>"app.config.signing_secret="<My app signing secret"You can bind your application specific code to handle inbound api.slack.com
messages using the following:app.ic.<interactive-component>.on- where  is one of the followingblock_actions- to bind callbacks for block action requestselect- to bind callbacks for external menu select populationview- to bind callbacks for View submissionview_closed- to bind callbacks for View closedimsg- to bind callbacks to interactive message attachaments(outmoded)dialog- to bind callbacks to Dialog submit(outmoded)app.commands.register- to register your /slash-command parser and callback handlerapp.events- to register all for any Event subscriptionsTo process inbound messages from api.slack.com you will need to call one of the app
handlers from the context of the API route handler.  For example, if you defined
an API route handler for one of your /slash-commands, you would callapp.handler_slash_command()to process ihe message.ExampleA primary motivator for slackapptk is to receive the request and direct it to
the app entrypoint handler that is specific to the request payload.  Consider
an example where the app presents the User with a surface that contains a
button, and the User clicks on that button. The app code creates the button in
a block, and then binds that block ID to the app "interactive component"
handler for block IDs, as shown in this code snippet:fromslack.web.classes.blocksimportSectionBlockfromslack.web.classes.elementsimportButtonElementfromslackapptk.appimportSlackAppfromslackapptk.request.interactiveimportBlockActionRequest,ActionEventfromslackapptk.responseimportResponsedefdemo(app:SlackApp):# this function uses the provided app to send a message to the User so that# they can click a button.  Note this is an incomplete example, but used to# show the machanics of the of the entrypoint bind / callback mechanism.block=SectionBlock(block_id='this is the block id',text='Click the button and see what happens',accessory=ButtonElement(text='Click Me',action_id='button action id',value='10'))# register the block-id callback to the function for handling when the User# clicks the button.app.ic.block_actions.on(block.block_id,on_block_button)# ... assume some code that sends the above block in a Slack# surface like a message or modal view ...defon_block_button(rqst:BlockActionRequest,action:ActionEvent):# this function is called when the app receives the request message from# api.slack.com when the User clicked the button.# send a message back to the User indicating the value of the buttonresp=Response(rqst)resp.send("button pressed, block vlaue is:%s",action.value)The registration / callback mechanism could also be coded as a decorator, for
example:@app.ic.block_actions.on(block.block_id)defon_block_button(rqst:BlockActionRequest,action:ActionEvent):# this function is called when the app receives the request message from# api.slack.com when the User clicked the button.# send a message back to the User indicating the value of the buttonresp=Response(rqst)resp.send("button pressed, block vlaue is:%s",action.value)