Azure / Azure/azure-sdk-for-python
Enabling chat between ACS user and Teams user
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
- **Package Name**: azure-communication-chat
- **Package Version**: 1.3.0
- **Operating System**: Windows 11 Enterprise
- **Python Version**: 3.9.11
**Describe the bug**
I am building a web application where I create a chat thread using ACS SDK and looking to enable communication between ACS user and Microsoft team's user, currently when trying to add Microsoft teams users to the chat thread I am facing the following error:
**Error**
Traceback (most recent call last):
File "c:\Users\030821958\UTS-Project\experiments\add_teams_user_acs_chat\chat_teams_user.py", line 400, in
sample.add_participants_w_check()
File "c:\Users\030821958\UTS-Project\experiments\add_teams_user_acs_chat\chat_teams_user.py", line 315, in add_participants_w_check
result = chat_thread_client.add_participants(thread_participants)
File "C:\Users\030821958SA\UTS-Project\experiments\add_teams_user_acs_chat\venv\lib\site-packages\azure\core\tracing\decorator.py", line 94, in wrapper_use_tracer
return func(*args, **kwargs)
File "C:\Users\030821958\UTS-Project\experiments\add_teams_user_acs_chat\venv\lib\site-packages\azure\communication\chat\_chat_thread_client.py", line 547, in add_participants
response = CommunicationErrorResponseConverter.convert(
File "C:\Users\030821958\UTS-Project\experiments\add_teams_user_acs_chat\venv\lib\site-packages\azure\communication\chat\_utils.py", line 56, in convert
_thread_participants_dict = create_dict(participants=participants)
File "C:\Users\030821958\UTS-Project\experiments\add_teams_user_acs_chat\venv\lib\site-packages\azure\communication\chat\_utils.py", line 53, in create_dict
result[participant.identifier.properties['id']] = participant
KeyError: 'id'
**code**
```
def add_participants_w_check(self):
from azure.communication.chat import CommunicationUserIdentifier, CommunicationIdentifier, MicrosoftTeamsUserIdentifier
# initially remove already added user
thread_id = self._thread_id
chat_client = self._chat_client
user = self.new_user
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)
chat_thread_client.remove_participant(user)
# [START add_participants]
from azure.communication.chat import ChatParticipant
from datetime import datetime
def decide_to_retry(error):
"""
Custom logic to decide whether to retry to add or not
"""
return True
# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)
# create `user` using CommunicationIdentityClient.create_user method for new users;
# else for existing users set `user` = CommunicationUserIdentifier(some_user_id)
new_participant = ChatParticipant(
identifier=user,
display_name='name',
share_history_time=datetime.utcnow())
teams_user = ChatParticipant(
identifier = MicrosoftTeamsUserIdentifier(""),
display_name='name',
share_history_time=datetime.utcnow())
# create list containing one or more participants
thread_participants = [new_participant, teams_user]
result = chat_thread_client.add_participants(thread_participants)
# list of participants which were unsuccessful to be added to chat thread
retry = [p for p, e in result if decide_to_retry(e)]
if retry:
chat_thread_client.add_participants(retry)
# [END add_participants]
print("add_participants_w_check succeeded")
```
**Additional context**
I am trying to replicate this behavior as mentioned in [Q&A](https://learn.microsoft.com/en-us/answers/questions/1655403/how-can-i-enable-chat-communication-between-extern) is it possible to bridge a chat solution between ACS user and Teams user without creating a [meeting link](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/chat/meeting-interop?pivots=platform-web) ?
Contributor guide
Assessment
This issue has not been assessed yet.