@@ -44,14 +44,11 @@ it with this token. It is because the initiator of the create request must be in
4444This will allow you to create, get, list or delete chat threads.
4545
4646``` python
47- from azure.communication.chat import ChatClient
48- from azure.communication.identity._shared.user_credential import CommunicationTokenCredential
49- from azure.communication.identity._shared.user_token_refresh_options import CommunicationTokenRefreshOptions
47+ from azure.communication.chat import ChatClient, CommunicationTokenCredential
5048
5149# Your unique Azure Communication service endpoint
5250endpoint = " https://<RESOURCE_NAME>.communcationservices.azure.com"
53- refresh_options = CommunicationTokenRefreshOptions(token)
54- chat_client = ChatClient(endpoint, CommunicationTokenCredential(refresh_options))
51+ chat_client = ChatClient(endpoint, CommunicationTokenCredential(token))
5552```
5653
5754## Create Chat Thread Client
@@ -67,15 +64,15 @@ chat_thread_client = chat_client.get_chat_thread_client(create_chat_thread_resul
6764```
6865
6966Additionally, the client can also direct so that the request is repeatable; that is, if the client makes the
70- request multiple times with the same Repeatability-Request-ID and it will get back an appropriate response without
71- the server executing the request multiple times. The value of the Repeatability-Request-ID is an opaque string
67+ request multiple times with the same Idempotency-Token and it will get back an appropriate response without
68+ the server executing the request multiple times. The value of the Idempotency-Token is an opaque string
7269representing a client-generated, globally unique for all time, identifier for the request.
7370
7471``` python
7572create_chat_thread_result = chat_client.create_chat_thread(
7673 topic,
7774 thread_participants = thread_participants,
78- repeatability_request_id = repeatability_request_id
75+ idempotency_token = idempotency_token
7976)
8077chat_thread_client = chat_client.get_chat_thread_client(create_chat_thread_result.chat_thread.id)
8178```
@@ -96,11 +93,10 @@ Once you initialized a `ChatClient` class, you can do the following chat operati
9693
9794## Create, get, update, and delete threads
9895
99- Perform CRD(Create-Read-Delete) operations on thread participants
96+ Perform CRD(Create-Read-Delete) operations on threads
10097
10198``` Python
10299create_chat_thread(topic, ** kwargs)
103- get_chat_thread(thread_id, ** kwargs)
104100list_chat_threads(** kwargs)
105101delete_chat_thread(thread_id, ** kwargs)
106102```
@@ -115,6 +111,11 @@ Perform Update operation on thread topic
115111update_topic(topic, ** kwargs)
116112```
117113
114+ ## Get Chat thread properties
115+ ``` python
116+ get_properties(** kwargs)
117+ ```
118+
118119## Send, get, update, and delete messages
119120
120121Perform CRUD(Create-Read-Update-Delete) operations on messages
@@ -133,7 +134,6 @@ Perform CRD(Create-Read-Delete) operations on thread participants
133134
134135``` Python
135136list_participants(** kwargs)
136- add_participant(thread_participant, ** kwargs)
137137add_participants(thread_participants, ** kwargs)
138138remove_participant(participant_id, ** kwargs)
139139```
@@ -177,22 +177,22 @@ Use the `create_chat_thread` method to create a chat thread.
177177 <!-- [User Access Tokens](#user-access-tokens) -->
178178 - ` display_name ` , optional, is the display name for the thread participant.
179179 - ` share_history_time ` , optional, time from which the chat history is shared with the participant.
180- - Use ` repeatability_request_id ` , optional, to specify the unique identifier for the request.
180+ - Use ` idempotency_token ` , optional, to specify the unique identifier for the request.
181181
182182
183183` CreateChatThreadResult ` is the result returned from creating a thread, you can use it to fetch the ` id ` of
184184the chat thread that got created. This ` id ` can then be used to fetch a ` ChatThreadClient ` object using
185185the ` get_chat_thread_client ` method. ` ChatThreadClient ` can be used to perform other chat operations to this chat thread.
186186
187187``` Python
188- # Without repeatability_request_id and thread_participants
188+ # Without idempotency_token and thread_participants
189189topic = " test topic"
190190create_chat_thread_result = chat_client.create_chat_thread(topic)
191191chat_thread_client = chat_client.get_chat_thread_client(create_chat_thread_result.chat_thread.id)
192192```
193193
194194``` Python
195- # With repeatability_request_id and thread_participants
195+ # With idempotency_token and thread_participants
196196from azure.communication.identity import CommunicationIdentityClient
197197from azure.communication.chat import ChatThreadParticipant
198198import uuid
@@ -219,13 +219,13 @@ thread_participants = [ChatThreadParticipant(
219219 share_history_time = datetime.utcnow()
220220)]
221221
222- # obtains repeatability_request_id using some customer logic
223- repeatability_request_id = get_unique_identifier_for_request()
222+ # obtains idempotency_token using some customer logic
223+ idempotency_token = get_unique_identifier_for_request()
224224
225225create_chat_thread_result = chat_client.create_chat_thread(
226226 topic,
227227 thread_participants = thread_participants,
228- repeatability_request_id = repeatability_request_id )
228+ idempotency_token = idempotency_token )
229229thread_id = create_chat_thread_result.chat_thread.id
230230
231231# fetch ChatThreadClient
@@ -240,16 +240,17 @@ def decide_to_retry(error, **kwargs):
240240 return True
241241
242242retry = [thread_participant for thread_participant, error in create_chat_thread_result.errors if decide_to_retry(error)]
243- chat_thread_client.add_participants(retry)
243+ if len (retry) > 0 :
244+ chat_thread_client.add_participants(retry)
244245```
245246
246247
247248### Get a thread
248249
249- Use ` get_chat_thread ` method retrieves a ` ChatThread ` from the service; ` thread_id ` is the unique ID of the thread.
250- - Use ` thread_id ` , required, to specify the unique ID of the thread.
250+ Use ` get_properties ` method retrieves a ` ChatThreadProperties ` from the service; ` thread_id ` is the unique ID of the thread.
251+
251252``` Python
252- chat_thread = chat_client.get_chat_thread( thread_id = thread_id )
253+ chat_thread_properties = chat_thread_client.get_properties( )
253254```
254255
255256### List chat threads
@@ -258,7 +259,7 @@ Use `list_chat_threads` method retrieves the list of created chat threads
258259- Use ` results_per_page ` , optional, The maximum number of messages to be returned per page.
259260- Use ` start_time ` , optional, The start time where the range query.
260261
261- An iterator of ` [ChatThreadInfo ] ` is the response returned from listing threads
262+ An iterator of ` [ChatThreadItem ] ` is the response returned from listing threads
262263
263264``` python
264265from datetime import datetime, timedelta
@@ -267,10 +268,10 @@ import pytz
267268start_time = datetime.utcnow() - timedelta(days = 2 )
268269start_time = start_time.replace(tzinfo = pytz.utc)
269270
270- chat_thread_infos = chat_client.list_chat_threads(results_per_page = 5 , start_time = start_time)
271- for chat_thread_info_page in chat_thread_infos .by_page():
272- for chat_thread_info in chat_thread_info_page :
273- print (chat_thread_info )
271+ chat_threads = chat_client.list_chat_threads(results_per_page = 5 , start_time = start_time)
272+ for chat_thread_item_page in chat_threads .by_page():
273+ for chat_thread_item in chat_thread_item_page :
274+ print (" thread id: " , chat_thread_item.id )
274275```
275276
276277### Update a thread topic
@@ -279,10 +280,10 @@ Use `update_topic` method to update a thread's properties. `topic` is used to de
279280- Use ` topic ` to give thread a new topic;
280281
281282``` python
282- topic= " new topic"
283+ topic = " new topic"
283284chat_thread_client.update_topic(topic = topic)
284285
285- chat_thread = chat_client.get_chat_thread (thread_id)
286+ chat_thread = chat_client.get_properties (thread_id)
286287
287288assert chat_thread.topic == topic
288289```
@@ -322,15 +323,17 @@ sender_display_name='sender name'
322323chat_message_type = ChatMessageType.TEXT
323324
324325# without specifying sender_display_name and chat_message_type
325- send_message_result_id = chat_thread_client.send_message(content)
326+ send_message_result = chat_thread_client.send_message(content)
327+ send_message_result_id = send_message_result.id
326328print (" Message sent: id: " , send_message_result_id)
327329
328330# specifying sender_display_name and chat_message_type
329- send_message_result_w_type_id = chat_thread_client.send_message(
331+ send_message_result_w_type = chat_thread_client.send_message(
330332 content,
331333 sender_display_name = sender_display_name,
332334 chat_message_type = chat_message_type # equivalent to chat_message_type = 'text'
333335)
336+ send_message_result_w_type_id = send_message_result_w_type.id
334337print (" Message sent: id: " , send_message_result_w_type_id)
335338```
336339
@@ -407,55 +410,6 @@ for chat_thread_participant_page in chat_thread_participants.by_page():
407410 print (" ChatThreadParticipant: " , chat_thread_participant)
408411```
409412
410- ### Add single thread participant
411- Use ` add_participant ` method to add a single thread participants to the thread.
412-
413- - Use ` thread_participant ` , required, to specify the ` ChatThreadParticipant ` to be added to the thread;
414- - ` user ` , required, it is the ` CommunicationUserIdentifier ` you created by CommunicationIdentityClient.create_user() from User Access Tokens
415- <!-- [User Access Tokens](#user-access-tokens) -->
416- - ` display_name ` , optional, is the display name for the thread participant.
417- - ` share_history_time ` , optional, time from which the chat history is shared with the participant.
418-
419- When participant is successfully added, no error is thrown. In case of an error encountered while adding participant,
420- a ` RuntimeError ` is thrown
421- ``` python
422- from azure.communication.identity import CommunicationIdentityClient
423- from azure.communication.chat import ChatThreadParticipant
424- from datetime import datetime
425-
426- # create an user
427- identity_client = CommunicationIdentityClient.from_connection_string(' <connection_string>' )
428- new_user = identity_client.create_user()
429-
430- # # conversely, you can also add an existing user to a chat thread; provided the user_id is known
431- # from azure.communication.identity import CommunicationUserIdentifier
432- #
433- # user_id = 'some user id'
434- # user_display_name = "Wilma Flinstone"
435- # new_user = CommunicationUserIdentifier(user_id)
436- # participant = ChatThreadParticipant(
437- # user=new_user,
438- # display_name=user_display_name,
439- # share_history_time=datetime.utcnow())
440-
441- def decide_to_retry (error , ** kwargs ):
442- """
443- Insert some custom logic to decide if retry is applicable based on error
444- """
445- return True
446-
447- participant = ChatThreadParticipant(
448- user = new_user,
449- display_name = ' Fred Flinstone' ,
450- share_history_time = datetime.utcnow())
451-
452- try :
453- chat_thread_client.add_participant(thread_participant = participant)
454- except RuntimeError as e:
455- if e is not None and decide_to_retry(error = e):
456- chat_thread_client.add_participant(thread_participant = participant)
457-
458- ```
459413### Add thread participants
460414
461415Use ` add_participants ` method to add thread participants to the thread.
@@ -466,7 +420,7 @@ Use `add_participants` method to add thread participants to the thread.
466420 - ` display_name ` , optional, is the display name for the thread participant.
467421 - ` share_history_time ` , optional, time from which the chat history is shared with the participant.
468422
469- A ` list(tuple(ChatThreadParticipant, CommunicationError )) ` is returned. When participant is successfully added,
423+ A ` list(tuple(ChatThreadParticipant, ChatError )) ` is returned. When participant is successfully added,
470424an empty list is expected. In case of an error encountered while adding participant, the list is populated
471425with the failed participants along with the error that was encountered.
472426
@@ -547,7 +501,8 @@ Use `send_read_receipt` method to post a read receipt event to a thread, on beha
547501- Use ` message_id ` to specify the id of the message whose read receipt is to be sent
548502``` python
549503content= ' hello world'
550- send_message_result_id = chat_thread_client.send_message(content)
504+ send_message_result = chat_thread_client.send_message(content)
505+ send_message_result_id = send_message_result.id
551506chat_thread_client.send_read_receipt(message_id = send_message_result_id)
552507```
553508
0 commit comments