11# ------------------------------------------------
22# instead of slack_bolt in requirements.txt
3- import asyncio
43import sys
54
65sys .path .insert (1 , ".." )
76# ------------------------------------------------
87
8+ import asyncio
99import logging
10+ from slack_bolt .async_app import AsyncApp
1011
1112logging .basicConfig (level = logging .DEBUG )
1213
13- from slack_bolt .async_app import AsyncApp
14-
1514app = AsyncApp ()
1615
1716
@@ -21,11 +20,12 @@ async def log_request(logger, payload, next):
2120 return await next ()
2221
2322
24- @app .command ("/hello-bolt-python" )
25- async def handle_command (payload , ack , respond , client , logger ):
23+ async def ack_command (payload , ack , logger ):
2624 logger .info (payload )
27- await ack ("Accepted!" )
25+ await ack ("Thanks!" )
26+
2827
28+ async def post_button_message (respond ):
2929 await respond (
3030 blocks = [
3131 {
@@ -45,6 +45,8 @@ async def handle_command(payload, ack, respond, client, logger):
4545 ]
4646 )
4747
48+
49+ async def open_modal (payload , client , logger ):
4850 res = await client .views_open (
4951 trigger_id = payload ["trigger_id" ],
5052 view = {
@@ -66,6 +68,7 @@ async def handle_command(payload, ack, respond, client, logger):
6668 "type" : "external_select" ,
6769 "action_id" : "es_a" ,
6870 "placeholder" : {"type" : "plain_text" , "text" : "Select an item" },
71+ "min_query_length" : 0 ,
6972 },
7073 "label" : {"type" : "plain_text" , "text" : "Search" },
7174 },
@@ -76,6 +79,7 @@ async def handle_command(payload, ack, respond, client, logger):
7679 "type" : "multi_external_select" ,
7780 "action_id" : "mes_a" ,
7881 "placeholder" : {"type" : "plain_text" , "text" : "Select an item" },
82+ "min_query_length" : 0 ,
7983 },
8084 "label" : {"type" : "plain_text" , "text" : "Search (multi)" },
8185 },
@@ -85,6 +89,11 @@ async def handle_command(payload, ack, respond, client, logger):
8589 logger .info (res )
8690
8791
92+ app .command ("/hello-bolt-python" )(
93+ ack = ack_command , lazy = [post_button_message , open_modal ],
94+ )
95+
96+
8897@app .options ("es_a" )
8998async def show_options (ack ):
9099 await ack (
@@ -125,19 +134,22 @@ async def show_multi_options(ack):
125134
126135
127136@app .view ("view-id" )
128- async def view_submission (ack , payload , logger ):
137+ async def handle_view_submission (ack , payload , logger ):
129138 await ack ()
130139 logger .info (payload ["view" ]["state" ]["values" ])
131140
132141
133- @app .action ("a" )
134- async def button_click (ack , respond ):
142+ async def ack_button_click (ack , respond ):
135143 await ack ()
144+ await respond ("Loading ..." )
145+
146+
147+ async def respond_5_seconds_later (respond ):
136148 await asyncio .sleep (5 )
137- await respond (
138- {"response_type" : "in_channel" , "text" : "Clicked!" ,}
139- )
149+ await respond ("Completed!" )
150+
140151
152+ app .action ("a" )(ack = ack_button_click , lazy = [respond_5_seconds_later ])
141153
142154if __name__ == "__main__" :
143155 app .start (3000 )
0 commit comments