InteractionBuilder
source
InteractionBuilder
InteractionBuilder ()
Utility class for creating interactive Slack Block Kit elements.
First, let’s start at the top of the message, which would be the message’s header:
source
InteractionBuilder.create_actions_block
InteractionBuilder.create_actions_block (elements:List[Dict[str,Any]])
*Create an actions block for Slack messages.
Args: elements: List of interactive elements
Returns: Slack block kit actions object*
test_eq(
InteractionBuilder.create_actions_block(
InteractionBuilder.create_button('Another Button' ,'button_2_clicked' )),
{'type' : 'actions' ,
'elements' : {'type' : 'button' ,
'text' : {'type' : 'plain_text' , 'text' : 'Another Button' , 'emoji' : True },
'action_id' : 'button_2_clicked' }}
)
InteractionBuilder.create_actions_block(
InteractionBuilder.create_button('Another Button' ,'button_2_clicked' )
)
{'type': 'actions',
'elements': {'type': 'button',
'text': {'type': 'plain_text', 'text': 'Another Button', 'emoji': True},
'action_id': 'button_2_clicked'}}
source
InteractionBuilder.create_datepicker
InteractionBuilder.create_datepicker (action_id:str, placeholder:str,
initial_date:Optional[str]=None)
*Create a date picker element.
Args: action_id: Identifier for the date picker placeholder: Placeholder text initial_date: Optional initial date (YYYY-MM-DD format)
Returns: Slack block kit datepicker object*
test_eq(InteractionBuilder.create_datepicker('start_date' ,'Pick a Start Date' ),
{'type' : 'datepicker' ,
'action_id' : 'start_date' ,
'placeholder' : {'type' : 'plain_text' ,
'text' : 'Pick a Start Date' ,
'emoji' : True }})
InteractionBuilder.create_datepicker('start_date' ,'Pick a Start Date' )
{'type': 'datepicker',
'action_id': 'start_date',
'placeholder': {'type': 'plain_text',
'text': 'Pick a Start Date',
'emoji': True}}
source
InteractionBuilder.create_static_select
InteractionBuilder.create_static_select (action_id:str, placeholder:str,
options:List[Tuple[str,str]])
*Create a dropdown select element.
Args: action_id: Identifier for the select placeholder: Placeholder text options: List of (text, value) tuples for options
Returns: Slack block kit static_select object*
test_eq(InteractionBuilder.create_static_select('credit_action' ,'Choose and Action' ,[('Issue Creidt' ,'issue_credit' ),('Ignore' ,'ignore' )]),
{'type' : 'static_select' ,
'action_id' : 'credit_action' ,
'placeholder' : {'type' : 'plain_text' ,
'text' : 'Choose and Action' ,
'emoji' : True },
'options' : [{'text' : {'type' : 'plain_text' ,
'text' : 'Issue Creidt' ,
'emoji' : True },
'value' : 'issue_credit' },
{'text' : {'type' : 'plain_text' , 'text' : 'Ignore' , 'emoji' : True },
'value' : 'ignore' }]})
InteractionBuilder.create_static_select('credit_action' ,'Choose and Action' ,[('Issue Creidt' ,'issue_credit' ),('Ignore' ,'ignore' )])
{'type': 'static_select',
'action_id': 'credit_action',
'placeholder': {'type': 'plain_text',
'text': 'Choose and Action',
'emoji': True},
'options': [{'text': {'type': 'plain_text',
'text': 'Issue Creidt',
'emoji': True},
'value': 'issue_credit'},
{'text': {'type': 'plain_text', 'text': 'Ignore', 'emoji': True},
'value': 'ignore'}]}
source
InteractionBuilder.create_multi_select
InteractionBuilder.create_multi_select (action_id:str, placeholder:str,
options:List[Tuple[str,str]])
*Create a multi-select dropdown element.
Args: action_id: Identifier for the multi-select placeholder: Placeholder text options: List of (text, value) tuples for options
Returns: Slack block kit multi_static_select object*
test_eq(InteractionBuilder.create_multi_select('select_multiple' ,'Select Option(s)' ,[('One' ,'one' ),('Two' ,'two' )]),
{'type' : 'multi_static_select' ,
'action_id' : 'select_multiple' ,
'placeholder' : {'type' : 'plain_text' ,
'text' : 'Select Option(s)' ,
'emoji' : True },
'options' : [{'text' : {'type' : 'plain_text' , 'text' : 'One' , 'emoji' : True },
'value' : 'one' },
{'text' : {'type' : 'plain_text' , 'text' : 'Two' , 'emoji' : True },
'value' : 'two' }]})
InteractionBuilder.create_multi_select('select_multiple' ,'Select Option(s)' ,[('One' ,'one' ),('Two' ,'two' )])
{'type': 'multi_static_select',
'action_id': 'select_multiple',
'placeholder': {'type': 'plain_text',
'text': 'Select Option(s)',
'emoji': True},
'options': [{'text': {'type': 'plain_text', 'text': 'One', 'emoji': True},
'value': 'one'},
{'text': {'type': 'plain_text', 'text': 'Two', 'emoji': True},
'value': 'two'}]}
source
InteractionBuilder.create_users_select
InteractionBuilder.create_users_select (action_id:str, placeholder:str)
*Create a user select element.
Args: action_id: Identifier for the users select placeholder: Placeholder text
Returns: Slack block kit users_select object*
test_eq(InteractionBuilder.create_users_select('selected_user' ,'Select a User' ),
{'type' : 'users_select' ,
'action_id' : 'selected_user' ,
'placeholder' : {'type' : 'plain_text' , 'text' : 'Select a User' , 'emoji' : True }})
InteractionBuilder.create_users_select('selected_user' ,'Select a User' )
{'type': 'users_select',
'action_id': 'selected_user',
'placeholder': {'type': 'plain_text', 'text': 'Select a User', 'emoji': True}}
source
InteractionBuilder.create_channels_select
InteractionBuilder.create_channels_select (action_id:str,
placeholder:str)
*Create a channel select element.
Args: action_id: Identifier for the channels select placeholder: Placeholder text
Returns: Slack block kit channels_select object*
test_eq(InteractionBuilder.create_channels_select('selected_channel' ,'Select a Channel' ),
{'type' : 'channels_select' ,
'action_id' : 'selected_channel' ,
'placeholder' : {'type' : 'plain_text' ,
'text' : 'Select a Channel' ,
'emoji' : True }})
InteractionBuilder.create_channels_select('selected_channel' ,'Select a Channel' )
{'type': 'channels_select',
'action_id': 'selected_channel',
'placeholder': {'type': 'plain_text',
'text': 'Select a Channel',
'emoji': True}}
source
InteractionBuilder.detect_and_create_interactive_elements
InteractionBuilder.detect_and_create_interactive_elements
(option_names:
List[str], opt
ion_values:Lis
t[str], action
_type:Optional
[str]=None, me
tadata:Optiona
l[str]=None, v
iew_info:Optio
nal[Dict[str,A
ny]]=None)
*Smartly detect and create appropriate interactive elements.
Args: option_names: List of option names option_values: List of option values action_type: Optional explicit action type metadata: Optional metadata to include in action_id view_info: Optional view information for embedding in metadata
Returns: List of interactive elements*
test_eq(InteractionBuilder.detect_and_create_interactive_elements(['Start Date' ],['start_date' ],'selected_start_date' ),
[{'type' : 'button' ,
'text' : {'type' : 'plain_text' , 'text' : 'Start Date' , 'emoji' : True },
'action_id' : 'tk_interaction_sele_0' ,
'value' : 'start_date' ,
'style' : 'primary' }])
InteractionBuilder.detect_and_create_interactive_elements(['Start Date' ],['start_date' ],'selected_start_date' )
[{'type': 'button',
'text': {'type': 'plain_text', 'text': 'Start Date', 'emoji': True},
'action_id': 'tk_interaction_sele_0',
'value': 'start_date',
'style': 'primary'}]