简体   繁体   English

MS Teams 机器人 - 在新创建的组中创建对话返回 405 BadArgument

[英]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.我正在尝试使用 Nodejs + botframework v4.9.2 为刚刚创建的频道创建新的对话。

I've我有

I'm running bot locally and proxying via ngrok.我在本地运行机器人并通过 ngrok 代理。 Also I can access GET /v3/conversations.我也可以访问 GET /v3/conversations。

Updated code更新代码

Get Team Memebers GET ${graphUrl}/groups/${teamId}/members获取团队成员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 createChannel 基本上是POST ${graphUrl}/teams/${teamId}/channels

Create new Tab POST ${graphUrl}/teams/${req.teamId}/channels/${req.channelId}/tabs where channelId is createChannelResponse.id创建新标签POST ${graphUrl}/teams/${req.teamId}/channels/${req.channelId}/tabs其中 channelId 是 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 createConversation 以 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).Teams的上下文中没有必要(也不会工作)使用createConversation ,因为对话是在创建 Team/Channel/Group 聊天本身的那一刻创建的( createConversation存在于其他 Bot Framework 场景中,并且是不适用于团队)。 As a result SendToConversation is the correct operation to use.因此, SendToConversation是正确的操作。

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.至于如何使用SendToConversation ,您需要准备好一些重要的变量,最常见的获得这些变量的时间是当您的机器人首先添加到频道/聊天/其他任何内容时。 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.您可以在此处阅读有关此内容的更多信息,但更一般地说,这在 Teams 中被认为是一种称为“主动”消息传递的东西,值得更多地阅读该主题。 Please see here and here as good starting points.请参阅此处此处作为良好的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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