@@ -9,6 +9,11 @@ defmodule ExMicrosoftBot.Client.Conversations do
99 alias ExMicrosoftBot.Models
1010 alias ExMicrosoftBot.Client
1111
12+ @ type pagination_opts :: [
13+ page_size: non_neg_integer ( ) ,
14+ continuation_token: String . t ( )
15+ ]
16+
1217 @ doc """
1318 Create a new Conversation.
1419
@@ -87,14 +92,43 @@ defmodule ExMicrosoftBot.Client.Conversations do
8792 |> deserialize_response ( & Models.ResourceResponse . parse / 1 )
8893 end
8994
95+ @ doc """
96+ Fetchs all members in a conversation, with pagination.
97+
98+ @see [API Reference](https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#get-conversation-paged-members)
99+
100+ ## Options
101+ * `page_size`: the suggested page size. As the name indicates, this might not
102+ be honored by the BotFramework API (i.e. all members are
103+ returned instead).
104+ * `continuation_token`: a token received from a previous request to this API
105+ that indicates the next page.
106+
107+ *Note:* The REST API reference doesn't mention `page_size` being a suggested
108+ value, but empirical testing and the
109+ [JavaScript SDK docs](https://docs.microsoft.com/en-us/javascript/api/botframework-connector/conversationsgetconversationpagedmembersoptionalparams?view=botbuilder-ts-latest)
110+ corroborate this.
111+ """
112+ @ spec get_paged_members (
113+ service_url :: String . t ( ) ,
114+ conversation_id :: String . t ( ) ,
115+ opts :: pagination_opts ( )
116+ ) :: { :ok , Models.PagedMembersResult . t ( ) } | Client . error_type ( )
117+ def get_paged_members ( service_url , conversation_id , opts \\ [ ] ) do
118+ service_url
119+ |> conversations_url ( "/#{ conversation_id } /pagedmembers" )
120+ |> add_pagination_opts ( opts )
121+ |> get ( )
122+ |> deserialize_response ( & Models.PagedMembersResult . parse / 1 )
123+ end
124+
90125 @ doc """
91126 This function takes a ConversationId and returns an array of ChannelAccount[]
92127 objects which are the members of the conversation.
93128 @see [API Reference](https://docs.botframework.com/en-us/restapi/connector/#!/Conversations/Conversations_GetConversationMembers).
94129
95130 When ActivityId is passed in then it returns the members of the particular
96131 activity in the conversation.
97-
98132 @see [API Reference](https://docs.botframework.com/en-us/restapi/connector/#!/Conversations/Conversations_GetActivityMembers)
99133 """
100134 @ spec get_members (
@@ -192,4 +226,27 @@ defmodule ExMicrosoftBot.Client.Conversations do
192226
193227 defp conversations_url ( service_url , path ) ,
194228 do: conversations_url ( service_url ) <> path
229+
230+ defp add_pagination_opts ( url , [ ] ) , do: url
231+
232+ defp add_pagination_opts ( url , opts ) do
233+ query =
234+ Enum . reduce ( opts , % { } , fn
235+ { :page_size , page_size } , query -> Map . put ( query , :pageSize , page_size )
236+ { :continuation_token , token } , query -> Map . put ( query , :continuationToken , token )
237+ { unknown , _value } , _query -> raise "unknown pagination param: #{ inspect ( unknown ) } "
238+ end )
239+
240+ url
241+ |> URI . parse ( )
242+ |> Map . put ( :query , encode_query ( query ) )
243+ |> URI . to_string ( )
244+ end
245+
246+ if Kernel . function_exported? ( URI , :encode_query , 2 ) do
247+ # Elixir > v1.12
248+ defp encode_query ( query ) , do: URI . encode_query ( query , :rfc3986 )
249+ else
250+ defp encode_query ( query ) , do: URI . encode_query ( query )
251+ end
195252end
0 commit comments