简体   繁体   中英

MS Teams bot - create conversation in newly created Group returns 405 BadArgument

I'm trying to create new convesation for just created channel using Nodejs + botframework v4.9.2.

I've

I'm running bot locally and proxying via ngrok. Also I can access GET /v3/conversations.

Updated code

Get Team Memebers GET ${graphUrl}/groups/${teamId}/members

Create new Channel

const createChannelRequest: IGraphCreateChannelBody = {
    "@odata.type": "#Microsoft.Teams.Core.channel",
    displayName: channelName,
    description: `This channel is for incident id : ${incidentId}`,
    members: membersIds.map(memberId => (
        {
            "@odata.type": "#microsoft.graph.aadUserConversationMember",
            "user@odata.bind": `https://graph.microsoft.com/beta/users('${memberId}')`,
            roles: ["owner"]
        }
    ))
};

return await graphClient.createChannel(teamId, createChannelRequest);

createChannel is basically POST ${graphUrl}/teams/${teamId}/channels

Create new Tab POST ${graphUrl}/teams/${req.teamId}/channels/${req.channelId}/tabs where channelId is createChannelResponse.id

Create new conversation

const client = new BotConnector.ConnectorClient(credentials, {baseUri: serviceUrl});
const {bot} = TurnContext.getConversationReference(activity);
const createConversationResponse = await client.conversations.createConversation({
    bot,
    activity: incidentActivity,
    members: teamMembers.value.map(member => ({
        id: member.id,
        name: member.displayName
    })),
    channelData: {
        channel: {
            id: newIncidentChannelId
        },
        tenant: {
            id: tenantId
        }
    },
    isGroup: true
});

where createConversation fails with 405

[Posting a complete answer, based on the comments above]

There's no need (and it won't work), in the context of Teams , to use createConversation , because the conversation is created the moment the Team/Channel/Group chat itself is created ( createConversation exists for other Bot Framework scenarios, and is not applicable for Teams). As a result SendToConversation is the correct operation to use.

As to how to use SendToConversation , there are certain important variables you need to have already your side, and the most common time to get these is when your bot is added to the channel/chat/whatever in the first place. You can read more about that here , but more generally, this is considered something called "proactive" messaging, in Teams, and it's worth reading up on that topic more. Please see here and here as good starting points.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM