Skip to content

Commit d161c2d

Browse files
committed
slack: construct body in api call
1 parent 7f27e9f commit d161c2d

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

lib/action.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
331331
let%lwt unfurls = List.map links ~f:process |> Lwt.all |> Lwt.map List.filter_opt |> Lwt.map StringMap.of_list in
332332
if Map.is_empty unfurls then Lwt.return "ignored: no links to unfurl"
333333
else begin
334-
let req : Slack_j.chat_unfurl_req = { channel = event.channel; ts = event.message_ts; unfurls } in
335-
match%lwt Slack_api.send_chat_unfurl ~ctx req with
334+
match%lwt Slack_api.send_chat_unfurl ~ctx ~channel:event.channel ~ts:event.message_ts ~unfurls () with
336335
| Ok () -> Lwt.return "ok"
337336
| Error e ->
338337
log#error "%s" e;

lib/api.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ end
1818

1919
module type Slack = sig
2020
val send_notification : ctx:Context.t -> msg:post_message_req -> unit slack_response Lwt.t
21-
val send_chat_unfurl : ctx:Context.t -> chat_unfurl_req -> unit slack_response Lwt.t
21+
22+
val send_chat_unfurl
23+
: ctx:Context.t ->
24+
channel:string ->
25+
ts:string ->
26+
unfurls:message_attachment Common.StringMap.t ->
27+
unit ->
28+
unit slack_response Lwt.t
29+
2230
val send_auth_test : ctx:Context.t -> unit -> auth_test_res slack_response Lwt.t
2331
end

lib/api_local.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525

2626
module Slack_base : Api.Slack = struct
2727
let send_notification ~ctx:_ ~msg:_ = Lwt.return @@ Error "undefined for local setup"
28-
let send_chat_unfurl ~ctx:_ _ = Lwt.return @@ Error "undefined for local setup"
28+
let send_chat_unfurl ~ctx:_ ~channel:_ ~ts:_ ~unfurls:_ () = Lwt.return @@ Error "undefined for local setup"
2929
let send_auth_test ~ctx:_ () = Lwt.return @@ Error "undefined for local setup"
3030
end
3131

lib/api_remote.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ module Slack : Api.Slack = struct
139139
| Error e -> Lwt.return @@ build_error e
140140
end
141141

142-
let send_chat_unfurl ~(ctx : Context.t) req =
142+
let send_chat_unfurl ~(ctx : Context.t) ~channel ~ts ~unfurls () =
143+
let req = Slack_j.{ channel; ts; unfurls } in
143144
let data = Slack_j.string_of_chat_unfurl_req req in
144145
request_token_auth ~name:"unfurl slack links"
145146
~body:(`Raw ("application/json", data))

0 commit comments

Comments
 (0)