1212import java .util .Arrays ;
1313import java .util .HashMap ;
1414import java .util .Map ;
15+ import java .util .regex .Pattern ;
1516
1617import static com .slack .api .model .block .Blocks .*;
1718import static com .slack .api .model .block .composition .BlockCompositions .dispatchActionConfig ;
@@ -150,15 +151,116 @@ public static void main(String[] args) throws Exception {
150151 return ctx .ack ();
151152 });
152153
153- // Note that this is still in beta as of Nov 2023
154- app .event (FunctionExecutedEvent .class , (req , ctx ) -> {
155- // TODO: future updates enable passing callback_id as below
154+ /* Example App Manifest
155+ {
156+ "display_information": {
157+ "name": "manifest-test-app-2"
158+ },
159+ "features": {
160+ "bot_user": {
161+ "display_name": "test-bot",
162+ "always_online": true
163+ }
164+ },
165+ "oauth_config": {
166+ "scopes": {
167+ "bot": [
168+ "commands",
169+ "chat:write",
170+ "app_mentions:read"
171+ ]
172+ }
173+ },
174+ "settings": {
175+ "event_subscriptions": {
176+ "bot_events": [
177+ "app_mention",
178+ "function_executed"
179+ ]
180+ },
181+ "interactivity": {
182+ "is_enabled": true
183+ },
184+ "org_deploy_enabled": true,
185+ "socket_mode_enabled": true,
186+ "token_rotation_enabled": false,
187+ "hermes_app_type": "remote",
188+ "function_runtime": "remote"
189+ },
190+ "functions": {
191+ "hello": {
192+ "title": "Hello",
193+ "description": "Hello world!",
194+ "input_parameters": {
195+ "amount": {
196+ "type": "number",
197+ "title": "Amount",
198+ "description": "How many do you need?",
199+ "is_required": false,
200+ "hint": "How many do you need?",
201+ "name": "amount",
202+ "maximum": 10,
203+ "minimum": 1
204+ },
205+ "user_id": {
206+ "type": "slack#/types/user_id",
207+ "title": "User",
208+ "description": "Who to send it",
209+ "is_required": true,
210+ "hint": "Select a user in the workspace",
211+ "name": "user_id"
212+ },
213+ "message": {
214+ "type": "string",
215+ "title": "Message",
216+ "description": "Whatever you want to tell",
217+ "is_required": false,
218+ "hint": "up to 100 characters",
219+ "name": "message",
220+ "maxLength": 100,
221+ "minLength": 1
222+ }
223+ },
224+ "output_parameters": {
225+ "amount": {
226+ "type": "number",
227+ "title": "Amount",
228+ "description": "How many do you need?",
229+ "is_required": false,
230+ "hint": "How many do you need?",
231+ "name": "amount",
232+ "maximum": 10,
233+ "minimum": 1
234+ },
235+ "user_id": {
236+ "type": "slack#/types/user_id",
237+ "title": "User",
238+ "description": "Who to send it",
239+ "is_required": true,
240+ "hint": "Select a user in the workspace",
241+ "name": "user_id"
242+ },
243+ "message": {
244+ "type": "string",
245+ "title": "Message",
246+ "description": "Whatever you want to tell",
247+ "is_required": false,
248+ "hint": "up to 100 characters",
249+ "name": "message",
250+ "maxLength": 100,
251+ "minLength": 1
252+ }
253+ }
254+ }
255+ }
256+ }
257+ */
258+
259+ // app.event(FunctionExecutedEvent.class, (req, ctx) -> {
156260 // app.function("hello", (req, ctx) -> {
157- // app.function(Pattern.compile("^he.+$"), (req, ctx) -> {
261+ app .function (Pattern .compile ("^he.+$" ), (req , ctx ) -> {
158262 ctx .logger .info ("req: {}" , req );
159263 ctx .client ().chatPostMessage (r -> r
160- // TODO: remove this token passing by enhancing bolt internals
161- .token (req .getEvent ().getBotAccessToken ())
162264 .channel (req .getEvent ().getInputs ().get ("user_id" ).asString ())
163265 .text ("hey!" )
164266 .blocks (asBlocks (actions (a -> a .blockId ("b" ).elements (asElements (
@@ -174,14 +276,10 @@ public static void main(String[] args) throws Exception {
174276 Map <String , Object > outputs = new HashMap <>();
175277 outputs .put ("user_id" , req .getPayload ().getFunctionData ().getInputs ().get ("user_id" ).asString ());
176278 ctx .client ().functionsCompleteSuccess (r -> r
177- // TODO: remove this token passing by enhancing bolt internals
178- .token (req .getPayload ().getBotAccessToken ())
179279 .functionExecutionId (req .getPayload ().getFunctionData ().getExecutionId ())
180280 .outputs (outputs )
181281 );
182282 ctx .client ().chatUpdate (r -> r
183- // TODO: remove this token passing by enhancing bolt internals
184- .token (req .getPayload ().getBotAccessToken ())
185283 .channel (req .getPayload ().getContainer ().getChannelId ())
186284 .ts (req .getPayload ().getContainer ().getMessageTs ())
187285 .text ("Thank you!" )
@@ -190,14 +288,10 @@ public static void main(String[] args) throws Exception {
190288 });
191289 app .blockAction ("remote-function-button-error" , (req , ctx ) -> {
192290 ctx .client ().functionsCompleteError (r -> r
193- // TODO: remove this token passing by enhancing bolt internals
194- .token (req .getPayload ().getBotAccessToken ())
195291 .functionExecutionId (req .getPayload ().getFunctionData ().getExecutionId ())
196292 .error ("test error!" )
197293 );
198294 ctx .client ().chatUpdate (r -> r
199- // TODO: remove this token passing by enhancing bolt internals
200- .token (req .getPayload ().getBotAccessToken ())
201295 .channel (req .getPayload ().getContainer ().getChannelId ())
202296 .ts (req .getPayload ().getContainer ().getMessageTs ())
203297 .text ("Thank you!" )
@@ -206,8 +300,6 @@ public static void main(String[] args) throws Exception {
206300 });
207301 app .blockAction ("remote-function-modal" , (req , ctx ) -> {
208302 ctx .client ().viewsOpen (r -> r
209- // TODO: remove this token passing by enhancing bolt internals
210- .token (req .getPayload ().getBotAccessToken ())
211303 .triggerId (req .getPayload ().getInteractivity ().getInteractivityPointer ())
212304 .view (view (v -> v
213305 .type ("modal" )
@@ -223,8 +315,6 @@ public static void main(String[] args) throws Exception {
223315 )))
224316 )));
225317 ctx .client ().chatUpdate (r -> r
226- // TODO: remove this token passing by enhancing bolt internals
227- .token (req .getPayload ().getBotAccessToken ())
228318 .channel (req .getPayload ().getContainer ().getChannelId ())
229319 .ts (req .getPayload ().getContainer ().getMessageTs ())
230320 .text ("Thank you!" )
@@ -236,7 +326,6 @@ public static void main(String[] args) throws Exception {
236326 Map <String , Object > outputs = new HashMap <>();
237327 outputs .put ("user_id" , ctx .getRequestUserId ());
238328 ctx .client ().functionsCompleteSuccess (r -> r
239- // TODO: remove this token passing by enhancing bolt internals
240329 .token (req .getPayload ().getBotAccessToken ())
241330 .functionExecutionId (req .getPayload ().getFunctionData ().getExecutionId ())
242331 .outputs (outputs )
@@ -247,7 +336,6 @@ public static void main(String[] args) throws Exception {
247336 Map <String , Object > outputs = new HashMap <>();
248337 outputs .put ("user_id" , ctx .getRequestUserId ());
249338 ctx .client ().functionsCompleteSuccess (r -> r
250- // TODO: remove this token passing by enhancing bolt internals
251339 .token (req .getPayload ().getBotAccessToken ())
252340 .functionExecutionId (req .getPayload ().getFunctionData ().getExecutionId ())
253341 .outputs (outputs )
0 commit comments