Skip to content

Commit 7c0da24

Browse files
committed
fix interaction payloads for block actions
1 parent bfb9197 commit 7c0da24

5 files changed

Lines changed: 233 additions & 63 deletions

File tree

lib/block_kit.atd

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ type json <ocaml module="Yojson.Basic" t="t"> = abstract
22

33
type view = [
44
| Modal <json name="modal"> of modal
5+
| Home <json name="home"> of json
56
] <ocaml repr="classic"> <json adapter.ocaml="Atdgen_runtime.Json_adapter.Type_field">
67

78
type modal <ocaml attr="deriving make"> = {
@@ -22,11 +23,17 @@ type modal <ocaml attr="deriving make"> = {
2223
type blocks = block list
2324

2425
type block = [
26+
| Actions <json name = "actions"> of actions
2527
| Divider <json name = "divider"> of divider
2628
| Input <json name = "input"> of input
2729
| Section <json name = "section"> of section
2830
] <ocaml repr="classic"> <json adapter.ocaml="Atdgen_runtime.Json_adapter.Type_field">
2931

32+
type actions <ocaml attr="deriving make"> = {
33+
elements : element list <ocaml valid="fun l -> List.length l <= 25">;
34+
?block_id : string nullable <ocaml valid="fun s -> String.length s <= 255">
35+
}
36+
3037
type divider <ocaml attr="deriving make"> = {
3138
block_id : string nullable <ocaml valid="fun s -> String.length s <= 255">
3239
}
@@ -54,7 +61,7 @@ type element = [
5461
| Button <json name = "button"> of button
5562
| Plain_text_input <json name = "plain_text_input"> of plain_text_input
5663
| Multi_static_select_menu <json name = "multi_static_select"> of multi_static_select_menu
57-
| Multi_users_select_menu <json name = "multi_users_select_menu"> of multi_users_select_menu
64+
| Multi_users_select_menu <json name = "multi_users_select"> of multi_users_select_menu
5865
| Static_select_menu <json name = "static_select"> of static_select_menu
5966
] <ocaml repr="classic"> <json adapter.ocaml="Atdgen_runtime.Json_adapter.Type_field">
6067

@@ -92,7 +99,7 @@ type multi_static_select_menu <ocaml attr="deriving make"> = {
9299

93100
type multi_users_select_menu <ocaml attr="deriving make"> = {
94101
?action_id : string nullable <ocaml valid="fun s -> String.length s <= 255">;
95-
?initial_users : string nullable;
102+
?initial_users : string list nullable;
96103
?confirm : confirmation_dialog_object nullable;
97104
?max_selected_items : int nullable <ocaml valid="fun i -> i >= 1">;
98105
?focus_on_load : bool nullable;

lib/block_kit_safe.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ let make_button ~(text : plain_text) ?action_id ?url ?value ?style ?confirm ?acc
147147

148148
(******************* Blocks ***********************)
149149

150+
let make_actions ~elements ?block_id () = Block_kit_j.(Actions (make_actions ~elements ?block_id ()))
150151
let make_divider ?block_id () = Block_kit_j.(Divider (make_divider ?block_id ()))
151152

152153
let make_input ~(label : plain_text) ~element ?dispatch_action ?block_id ?(hint : plain_text option) ?optional () =

lib/slack.atd

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -701,23 +701,25 @@ type 'ok slack_response = ('ok, slack_api_error) http_response
701701

702702

703703
type interaction = [
704-
| Shortcut <json name="shortcut"> of interaction_payload
705-
| Message_actions <json name="message_action"> of interaction_payload
706-
| Block_actions <json name="block_actions"> of interaction_payload
707-
| View_submission <json name="view_submission"> of json
708-
| View_closed <json name="view_closed"> of json
704+
| Shortcut <json name="shortcut"> of interaction_payload
705+
| Message_actions <json name="message_action"> of interaction_payload
706+
| Block_actions <json name="block_actions"> of interaction_payload
707+
| View_submission <json name="view_submission"> of json
708+
| View_closed <json name="view_closed"> of json
709709
] <ocaml repr="classic"> <json adapter.ocaml="Atdgen_runtime.Json_adapter.Type_field">
710710

711711
type interaction_payload = {
712712
trigger_id: string;
713713
token: string;
714714
team: interaction_team;
715+
?container : json nullable; (* Only available in block_actions *)
715716
?callback_id: string nullable;
716717
?response_url: string nullable;
717718
?message: interaction_message nullable;
718719
?user: interaction_user nullable;
719720
?channel : interaction_channel nullable;
720721
?actions : interaction_action list nullable;
722+
?view : view nullable;
721723
?state : json nullable
722724
}
723725

@@ -761,11 +763,18 @@ type open_views_req <ocaml attr="deriving make"> = {
761763
?interactivity_pointer : string nullable;
762764
}
763765

766+
type view_res = {
767+
id : string;
768+
team_id : string;
769+
hash : string
770+
(* https://api.slack.com/methods/views.open#examples *)
771+
}
772+
764773
type open_views_res = {
765774
ok : bool;
766-
view : view;
775+
view : view_res;
767776
~response_metadata <ocaml default="[]">: (string * json) list <json repr="object">;
768-
}
777+
}
769778

770779
type push_views_req <ocaml attr="deriving make"> = {
771780
view: view;
@@ -794,11 +803,11 @@ type update_views_res = {
794803
}
795804

796805
type get_permalink_req <ocaml attr="deriving make"> = {
797-
channel: string;
798-
message_ts: string;
806+
channel: string;
807+
message_ts: string;
799808
}
800809

801810
type get_permalink_res = {
802-
channel: string;
803-
permalink: string;
811+
channel: string;
812+
permalink: string;
804813
}

lib/utils.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let process_slack_interaction (ctx : Context.t) headers body ~interaction_handle
5656
| [] -> Lwt.return_error "Empty payload"
5757
| payload :: _ ->
5858
match interaction_of_string payload with
59-
| exception Yojson.Json_error e -> Lwt.return_error (sprintf "Invalid interaction: %s" e)
59+
| exception Yojson.Json_error e -> Lwt.return_error (sprintf "Invalid interaction: %s, payload: %s" e payload)
6060
| interaction ->
6161
match validate_signature ?signing_key:ctx.secrets.slack_signing_secret ~headers body with
6262
| Error e -> Lwt.return_error (sprintf "signature not validated: %s" e)

0 commit comments

Comments
 (0)