2
votes

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",
            "[email protected]": `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

1
Is your bot actually installed into the channel? If not, it won't be able to initiate a conversation - Hilton Giesenow
Yes, it is. I'm able to communicate with it. - user1469253
ah, in that case, you don't need to "createConversation", you'd want "SendToConversation", because the conversation exists already. - Hilton Giesenow
@HiltonGiesenow sorry I might have explained it not clearly. I've installed bot to the team. I'm trying to create new group and send there some message. From my understanding I should create new converstaion for newly created group. I can't use sendToConversation since I don't have existing one. - user1469253
@user1469253 - We can see that you're using a Direct Line endpoint. That means the connector client for your Conversations object must have a Direct Line base URI. Can you give us an actual code sample that shows how you're constructing these objects? (Since there are multiple other people in this thread, you will need to @ mention me if you want me to see your reply.) - Kyle Delaney

1 Answers

0
votes

[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.