From 5f531500853b2810c1f2450adf74d616516ccb28 Mon Sep 17 00:00:00 2001 From: Pomin Wu Date: Tue, 29 Aug 2023 01:14:16 +0000 Subject: [PATCH 1/3] refactor: rename conversation to im --- src/lib/slacko.ml | 14 +++++++------- src/lib/slacko.mli | 22 +++++++++++----------- test/test_slacko.ml | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/lib/slacko.ml b/src/lib/slacko.ml index 6261b26..4cf6041 100644 --- a/src/lib/slacko.ml +++ b/src/lib/slacko.ml @@ -193,7 +193,7 @@ type message = string type channel = ChannelId of string | ChannelName of string -type conversation = string +type im = string type user = UserId of string | UserName of string @@ -202,7 +202,7 @@ type bot = BotId of string type group = GroupId of string | GroupName of string (* TODO: Sure about user? *) -type chat = Channel of channel | Im of conversation | User of user | Group of group +type chat = Channel of channel | Im of im | User of user | Group of group type sort_criterion = Score | Timestamp @@ -230,9 +230,9 @@ let group_of_yojson = function | `String x -> Ok (GroupId x) | _ -> Error "Couldn't parse group type" -let conversation_of_yojson = function +let im_of_yojson = function | `String x -> Ok x - | _ -> Error "Couldn't parse conversation type" + | _ -> Error "Couldn't parse im type" type topic_obj = { value: string; @@ -336,7 +336,7 @@ type file_obj = { (*public_url_shared: ???;*) channels: channel list; groups: group list; - ims: conversation list; + ims: im list; initial_comment: Yojson.Safe.t option [@default None]; num_stars: int option [@default None]; } [@@deriving of_yojson { strict = false }] @@ -883,8 +883,8 @@ let user_of_string s = let group_of_string s = if s.[0] = 'G' then GroupId s else GroupName s -(* TODO Create a conversation if conversation does not exist? *) -let conversation_of_string s = +(* TODO Create a im if im does not exist? *) +let im_of_string s = if s.[0] = 'D' then s else failwith "Not an IM channel" let translate_parsing_error = function diff --git a/src/lib/slacko.mli b/src/lib/slacko.mli index 901b321..da653f2 100644 --- a/src/lib/slacko.mli +++ b/src/lib/slacko.mli @@ -280,7 +280,7 @@ type message type channel (** A type of an IM conversation *) -type conversation +type im (** An user, represented by either a user name or a user id. *) type user @@ -292,7 +292,7 @@ type bot type group (** A place one can post messages to. *) -type chat = Channel of channel | Im of conversation | User of user | Group of group +type chat = Channel of channel | Im of im | User of user | Group of group (** What criterion to use in search. *) type sort_criterion = Score | Timestamp @@ -468,7 +468,7 @@ type groups_rename_obj = { created: timestamp } -(** Information about a direct conversation with a person. *) +(** Information about a direct im with a person. *) type im_obj = { id: string; is_im: bool; @@ -483,7 +483,7 @@ type im_channel_obj = { id: string; } -(** Information about an direct conversation channel. *) +(** Information about an direct im channel. *) type im_open_obj = { no_op: bool option; already_open: bool option; @@ -555,7 +555,7 @@ type file_obj = { (*public_url_shared: ???;*) channels: channel list; groups: group list; - ims: conversation list; + ims: im list; initial_comment: Yojson.Safe.t option; num_stars: int option; } @@ -690,9 +690,9 @@ val bot_of_string : string -> bot id by means of an additional request. *) val channel_of_string: string -> channel -(** Create a conversation type out of a given string. The string is usually - starting with a capital 'D' and represents an IM conversation channel. *) -val conversation_of_string: string -> conversation +(** Create a im type out of a given string. The string is usually + starting with a capital 'D' and represents an IM im channel. *) +val im_of_string: string -> im (** {2 Slack API calls} *) @@ -823,16 +823,16 @@ val groups_set_topic: session -> group -> topic -> topic_result Lwt.t val groups_unarchive: session -> group -> [ `Success | parsed_auth_error | channel_error | `Not_archived | `User_is_restricted | bot_error ] Lwt.t (** Close a direct message channel. *) -val im_close: session -> conversation -> [ `Success of chat_close_obj | parsed_auth_error | channel_error | `User_does_not_own_channel ] Lwt.t +val im_close: session -> im -> [ `Success of chat_close_obj | parsed_auth_error | channel_error | `User_does_not_own_channel ] Lwt.t (** Fetches history of messages and events from direct message channel. *) -val im_history: session -> ?latest:timestamp -> ?oldest:timestamp -> ?count:int -> ?inclusive:bool -> conversation -> history_result Lwt.t +val im_history: session -> ?latest:timestamp -> ?oldest:timestamp -> ?count:int -> ?inclusive:bool -> im -> history_result Lwt.t (** Lists direct message channels for the calling user. *) val im_list: session -> [ `Success of im_obj list | parsed_auth_error ] Lwt.t (** Sets the read cursor in a direct message channel. *) -val im_mark: session -> conversation -> timestamp -> [ `Success | parsed_auth_error | channel_error | not_in_channel_error ] Lwt.t +val im_mark: session -> im -> timestamp -> [ `Success | parsed_auth_error | channel_error | not_in_channel_error ] Lwt.t (** Opens a direct message channel. *) val im_open: session -> user -> [ `Success of im_open_obj | parsed_auth_error | user_error | user_visibility_error ] Lwt.t diff --git a/test/test_slacko.ml b/test/test_slacko.ml index c93a20b..49fad12 100644 --- a/test/test_slacko.ml +++ b/test/test_slacko.ml @@ -292,13 +292,13 @@ let groups_list_tests = fake_slack_tests "groups_list" [ let test_im_history_bad_auth _tctx = let session = Slacko.start_session ?base_url badtoken in - let slackbot = Slacko.conversation_of_string Fake_slack.im_slackbot in + let slackbot = Slacko.im_of_string Fake_slack.im_slackbot in Slacko.im_history session slackbot >|= fun resp -> assert_equal `Invalid_auth resp let test_im_history_no_params _tctx = let session = Slacko.start_session ?base_url token in - let slackbot = Slacko.conversation_of_string Fake_slack.im_slackbot in + let slackbot = Slacko.im_of_string Fake_slack.im_slackbot in Slacko.im_history session slackbot >|= get_success >|= fun history -> assert_equal ~printer:show_abbr_history_obj (abbr_json abbr_history_obj_of_yojson Fake_slack.slackbot_history_json) From bd5f4ceb2d4a253a7f72151805fe51ea6d224b54 Mon Sep 17 00:00:00 2001 From: Pomin Wu Date: Tue, 29 Aug 2023 01:14:16 +0000 Subject: [PATCH 2/3] fix: add missing attributes to im --- src/lib/slacko.ml | 2 ++ src/lib/slacko.mli | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/lib/slacko.ml b/src/lib/slacko.ml index 4cf6041..938c740 100644 --- a/src/lib/slacko.ml +++ b/src/lib/slacko.ml @@ -485,6 +485,8 @@ type im_obj = { user: user; created: Timestamp.t; is_user_deleted: bool; + is_open: bool option [@default None]; + last_read: Timestamp.t option [@default None]; unread_count: int option [@default None]; unread_count_display: int option [@default None]; } [@@deriving of_yojson { strict = false }] diff --git a/src/lib/slacko.mli b/src/lib/slacko.mli index da653f2..5555815 100644 --- a/src/lib/slacko.mli +++ b/src/lib/slacko.mli @@ -475,6 +475,8 @@ type im_obj = { user: user; created: timestamp; is_user_deleted: bool; + is_open: bool option; + last_read: timestamp option; unread_count: int option; unread_count_display: int option; } From 135164296541df727e4bf937aedfeeb5bf745de1 Mon Sep 17 00:00:00 2001 From: Pomin Wu Date: Tue, 29 Aug 2023 14:23:23 +0000 Subject: [PATCH 3/3] fix: add conversation_obj type --- src/lib/slacko.ml | 25 +++++++++++++++++++++++++ src/lib/slacko.mli | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/lib/slacko.ml b/src/lib/slacko.ml index 938c740..4d30b25 100644 --- a/src/lib/slacko.ml +++ b/src/lib/slacko.ml @@ -193,6 +193,8 @@ type message = string type channel = ChannelId of string | ChannelName of string +type conversation = string + type im = string type user = UserId of string | UserName of string @@ -226,6 +228,10 @@ let channel_of_yojson = function | `String x -> Ok (ChannelId x) | _ -> Error "Couldn't parse channel type" +let conversation_of_yojson = function + | `String x -> Ok x + | _ -> Error "Couldn't parse conversation type" + let group_of_yojson = function | `String x -> Ok (GroupId x) | _ -> Error "Couldn't parse group type" @@ -259,6 +265,25 @@ type channel_obj = { num_members: int option [@default None]; } [@@deriving of_yojson { strict = false }] +type conversation_obj = { + id: conversation; + name: string; + is_channel: bool; + created: Timestamp.t; + creator: user; + is_archived: bool; + is_general: bool; + is_member: bool; + topic: topic_obj; + purpose: topic_obj; + last_read: Timestamp.t option [@default None]; + latest: string option [@default None]; + unread_count: int option [@default None]; + unread_count_display: int option [@default None]; + num_members: int option [@default None]; +} [@@deriving of_yojson { strict = false }] + + type user_obj = { id: user; name: string; diff --git a/src/lib/slacko.mli b/src/lib/slacko.mli index 5555815..54c4064 100644 --- a/src/lib/slacko.mli +++ b/src/lib/slacko.mli @@ -279,6 +279,9 @@ type message channel id. *) type channel +(** A channel-like container for a conversation used by the Conversations API. *) +type conversation + (** A type of an IM conversation *) type im @@ -368,6 +371,25 @@ type channel_obj = { num_members: int option; } +(** Object representing information about a Slack channel. *) +type conversation_obj = { + id: conversation; + name: string; + is_channel: bool; + created: timestamp; + creator: user; + is_archived: bool; + is_general: bool; + is_member: bool; + topic: topic_obj; + purpose: topic_obj; + last_read: timestamp option; + latest: string option; + unread_count: int option; + unread_count_display: int option; + num_members: int option; +} + (** Object representing a message attachment field. *) type field_obj = { title: string option;