[英]MS Teams bot - create conversation in newly created Group returns 405 BadArgument
我正在嘗試使用 Nodejs + botframework v4.9.2 為剛剛創建的頻道創建新的對話。
我有
Conversations.createConversation
from bot sdk, it's basically calling POST https://directline.botframework.com/v3/conversations with passing new channel id and getting 405 BadArgument This channel does not support this operation
我在本地運行機器人並通過 ngrok 代理。 我也可以訪問 GET /v3/conversations。
更新代碼
獲取團隊成員GET ${graphUrl}/groups/${teamId}/members
創建新頻道
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 基本上是POST ${graphUrl}/teams/${teamId}/channels
創建新標簽POST ${graphUrl}/teams/${req.teamId}/channels/${req.channelId}/tabs
其中 channelId 是 createChannelResponse.id
創建新對話
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
});
createConversation 以 405 失敗的地方
[根據上述評論發布完整答案]
在Teams的上下文中沒有必要(也不會工作)使用createConversation
,因為對話是在創建 Team/Channel/Group 聊天本身的那一刻創建的( createConversation
存在於其他 Bot Framework 場景中,並且是不適用於團隊)。 因此, SendToConversation
是正確的操作。
至於如何使用SendToConversation
,您需要准備好一些重要的變量,最常見的獲得這些變量的時間是當您的機器人首先添加到頻道/聊天/其他任何內容時。 您可以在此處閱讀有關此內容的更多信息,但更一般地說,這在 Teams 中被認為是一種稱為“主動”消息傳遞的東西,值得更多地閱讀該主題。 請參閱此處和此處作為良好的起點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.