How to Create Chat Threads and Send Messages to Microsoft Teams Users with Azure Communication Services

devuser61 0 Reputation points
2025-01-31T07:00:56.02+00:00

I have Microsoft Teams users and obtain access tokens for Azure Communication Services to make calls using Azure SDKs. I want to send messages using the @azure/communication-chat SDK but encounter an error while creating a chat thread. It works with ACS users directly, but not for Teams users.

Error:

"CommunicationError": {
    "Code": "Forbidden",
    "Details": []
}
Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
1,234 questions
{count} votes

2 answers

Sort by: Most helpful
  1. devuser61 0 Reputation points
    2025-02-11T07:29:19.89+00:00

    hi @Shree Hima Bindu Maganti

    when i give user id as 8:orgid:6272876c-3b81-48a2-86d0-5b1d03fc1600 i am getting below error

    {

    "CommunicationError": {

    "Code": "BadRequest",
    
    "Message": "The provided microsoft teams user id (8:orgid:6272876c-3b81-48a2-86d0-5b1d03fc1600) is invalid.",
    
    "Details": []
    

    }

    }

    when i give 6272876c-3b81-48a2-86d0-5b1d03fc1600 i am getting below error.

    {

    "CommunicationError": {

    "Code": "Forbidden",
    
    "Details": []
    

    }

    }

    code snippet i am using :

    const teamsParticipant:MicrosoftTeamsUserIdentifier = { microsoftTeamsUserId : "6272876c-3b81-48a2-86d0-5b1d03fc1600"};

        const chatParticipant:ChatParticipant = {
    
            id : teamsParticipant,
    
            displayName: "Dev 66"
    
        };
    
        let participants: ChatParticipant[] = [];
    
        participants.push(chatParticipant);
    
        const createChatThreadOptions:CreateChatThreadOptions = {
    
            participants : participants,
    
        };
    
        const createChatThreadRequest:CreateChatThreadRequest ={
    
            topic : "Hello teams"
    
        };
    
        const createChatThreadResult:CreateChatThreadResult =  await chatClient.createChatThread(createChatThreadRequest,createChatThreadOptions);
    
    	
    

    i am seeing chat in acs scope when i decode my acs access token:

    	"scp": 1024,
    
    "csi": "1739251188",
    
    "exp": 1739256777,
    
    "rgn": "amer",
    
    "tid": "e3a46007-31cb-4529-b8cc-1e59b97ebdbd",
    
    "acsScope": "voip,chat",
    

    also i went through the documentation teams interoperability at https://learn.microsoft.com/en-us/azure/communication-services/concepts/teams-interop i am seeing that for teams user chat is enabled via Graph api only. is this the reason why i am not able to create chat thread.

    User's image


  2. Shree Hima Bindu Maganti 4,775 Reputation points Microsoft External Staff Moderator
    2025-02-11T09:25:26.4633333+00:00

    Hi @devuser61 ,
    Thankyou for your Response.
    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer.
    sol:

    Also i went through the documentation teams interoperability at https://learn.microsoft.com/en-us/azure/communication-services/concepts/teams-interop i am seeing that for teams user chat is enabled via Graph api only. is this the reason why i am not able to create chat thread.

    User's image
    If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.