Package: slack-blocks-builder
Slack Blocks BuilderVery simple block builder to build messages in the Slack block kit format. The official Slack Block Kit documentation is availablehereand Slack also offers aBlock Kit Builder.This package allows you to configure a block kit conformant message using YAML or JSON files, as well as Pydantic models or dictionaries with only the required parameters.InstallationTo get the latest stable release from PyPi:pipinstallslack-blocks-builderAdd the package to yourrequirements.txtfile:blocks_builer~=0.1.0UsageTo get started, add the package to the file where you'd like to generate the message block kit schema:fromblocks_builerimportBuilderTo generate a block kit type message from a file, regardless of whether it is a YAML or JSON file:message=Builder().build_from_file("path/to/file.yaml")To generate a block kit formatted message from a Python dictionary:message=Builder().build_from_dict(data=data)Finally, in order to generate a block kit message using Pydantic models directly, import the relevant classes.ExamplesYou can generate a sample YAML and a sample JSON file running the following command:generate_sample_filesTo compose a file, the following top key blocks are supported:actionscontextdividerheaderimageinputsectionTo use multiple blocks of the same type, simply add an underscore followed by a number to the key name, for example:section:text:"Thisisthefirstsection"section_2:text:"Thisisthesecondsection"section_3:text:"Thisisthethirdsection"When adding actions, list under theactionkey each block you'd like to add with the necessary parameters:actions:button:text:"Thisisabutton"value:"click_me_123"channels_select:elements:truecheckboxes:options:[{text:"Option1",description:"Option1",value:"option-1"},{text:"Option2",description:"Option2",value:"option-2"}]When adding a context block, use thecontextkey and list under it each context block you'd like to add:context:text:"Thisisacontextblock."image:image_url:"https://www.google.com"When adding a divider, simply set the value of thedividerkey totrue:divider:trueWhen adding a header, add theheaderkey with thetextparameter under it. To control theemojisetting, just add that key under theheaderparameter also:header:text:"Thisisaheaderexample."When adding an image, add theimagekey with theimage_urlparameter under it. To add an image with a title, just add thetitleparameter as well.image:image_url:"https://www.validurl.com"title:"Thisisanimage"When adding an input field, just add theinputkey with the name of the block you'd like to add under it. For each input block, provide the necessary parameters.input:datepicker:elements:truelabel:"Sampledatepicker"When adding a section, add both thetextandaccessoryparameters under section. Accessory should have the parameters required for the specific section block:section:text:"Section1"accessory:image_url:"https://www.validurl.com"Note:If adding a text section, accessory is not required.To generate a sample message with a text section, divider, text and image section and action buttons:section:text:"Hello,AssistanttotheRegionalManagerDwight!*MichaelScott*wantstoknowwhereyou'dliketotakethePaperCompanyinvestorstodinnertonight.\n\n*Pleaseselectarestaurant:*"divider:truesection_2:text:"*FarmhouseThaiCuisine*\n:star::star::star::star:1528reviews\nTheydohavesomeveganoptions,liketherotiandcurry,plustheyhaveatonofsaladstuffandnoodlescanbeorderedwithoutmeat!!Theyhavesomethingforeveryonehere"accessory:image_url:"https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg"section_3:text:"*KinKhao*\n:star::star::star::star:1638reviews\nThestickyricealsogoeswonderfullywiththecaramelizedporkbelly,whichisabsolutelymelt-in-your-mouthandsosoft."accessory:image_url:"https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg"section_4:text:"*LerRos*\n:star::star::star::star:2082reviews\nIwouldreallyrecommendtheYumKohMooYang-Spicylimedressingandroastedquickmarinatedporkshoulder,basilleaves,chili&ricepowder."accessory:image_url:"https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg"divider_2:trueactions:button:text:"Farmhouse""value":"click_me_123"link_button:text:"KinKhao"value:"click_me_123"url:"https://google.com"link_button_2:text:"LerRos"value:"click_me_123"url:"https://google.com"