@@ -232,27 +232,30 @@ type connection_result =
232
232
| Giveup
233
233
| Connected of connection
234
234
235
- let create_connection slack_teamid input_handler handle_permanent_failure =
235
+ let create_connection uid slack_teamid input_handler handle_permanent_failure =
236
236
logf `Debug " Create websocket connection for Slack team %s"
237
237
(Slack_api_teamid. to_string slack_teamid);
238
238
catch
239
239
(fun () ->
240
- Slack_user. get_bot_access_token slack_teamid >> = fun access_token ->
241
- Slack_api. rtm_start access_token >> = fun resp ->
242
- match Slack_util. extract_result resp with
240
+ Slack_user. get_bot_access_token_opt ~uid slack_teamid >> = function
243
241
| None ->
244
- return Retry
245
- | Some x ->
246
- let ws_url = x.Slack_api_t. url in
247
- let waiting_for_pong = ref None in
248
- create_websocket_connection ws_url
249
- input_handler waiting_for_pong >> = fun send ->
250
- let conn = {
251
- conn_id = slack_teamid;
252
- send;
253
- waiting_for_pong;
254
- } in
255
- return (Connected conn)
242
+ return Giveup
243
+ | Some access_token ->
244
+ Slack_api. rtm_start access_token >> = fun resp ->
245
+ match Slack_util. extract_result resp with
246
+ | None ->
247
+ return Retry
248
+ | Some x ->
249
+ let ws_url = x.Slack_api_t. url in
250
+ let waiting_for_pong = ref None in
251
+ create_websocket_connection ws_url
252
+ input_handler waiting_for_pong >> = fun send ->
253
+ let conn = {
254
+ conn_id = slack_teamid;
255
+ send;
256
+ waiting_for_pong;
257
+ } in
258
+ return (Connected conn)
256
259
)
257
260
(fun e ->
258
261
if is_permanent_failure e then (
@@ -268,6 +271,7 @@ let get_connection slack_teamid =
268
271
with Not_found -> None
269
272
270
273
let obtain_connection
274
+ uid
271
275
slack_teamid
272
276
create_input_handler
273
277
handle_permanent_failure =
@@ -278,6 +282,7 @@ let obtain_connection
278
282
| None ->
279
283
let input_handler = create_input_handler () in
280
284
create_connection
285
+ uid
281
286
slack_teamid
282
287
input_handler
283
288
handle_permanent_failure >> = fun result ->
@@ -410,7 +415,8 @@ let rec check_connection_until_failure slack_teamid =
410
415
still works, and create a new connection if the previous one
411
416
is no longer usable, and so on.
412
417
*)
413
- let keep_connected slack_teamid create_input_handler handle_permanent_failure =
418
+ let keep_connected
419
+ uid slack_teamid create_input_handler handle_permanent_failure =
414
420
if connection_existed slack_teamid then (
415
421
(* assume that another keep_connected job already exists *)
416
422
interrupt_sleeper slack_teamid;
@@ -423,7 +429,7 @@ let keep_connected slack_teamid create_input_handler handle_permanent_failure =
423
429
let connect () =
424
430
Apputil_error. catch_and_report " Slack WS keep_connected"
425
431
(fun () ->
426
- obtain_connection slack_teamid
432
+ obtain_connection uid slack_teamid
427
433
create_input_handler
428
434
handle_permanent_failure
429
435
>> = function
@@ -474,6 +480,7 @@ let keep_connected slack_teamid create_input_handler handle_permanent_failure =
474
480
*)
475
481
let test () =
476
482
keep_connected
483
+ (Uid. make () )
477
484
(Slack_api_teamid. of_string " T19BY0R8X" )
478
485
(fun () send s ->
479
486
Printf. printf " Received %S\n %!" s;
0 commit comments