下面的代码起作用了--当一个新用户被添加到Teams时,bot会亲自向用户发送欢迎信息,而不是向整个通道发送欢迎消息。由于某些原因,它不再起作用了--我相信它与CreateConversationAsync()方法有关。V4文档声明:“这个方法现在已经过时了,因为ConversationReference参数现在是多余的。请使用不带此参数的重载。”但是,我还没有弄清楚如何正确地更新下面的代码才能工作。
CreateConversationAsync: (此方法将会话引用(现已过时)传递给ContinueConversationAsync())
ConversationReference conversationReference = null;
return await ((BotFrameworkAdapter)turnContext.Adapter).CreateConversationAsync(
teamsChannelId,
serviceUrl,
credentials,
conversationParameters,
async (t1, c1) =>
{
conversationReference = t1.Activity.GetConversationReference();
await Task.FromResult(false).ConfigureAwait(false);
}, cancellationToken).ContinueWith(_ => { return conversationReference; }).ConfigureAwait(false);
ContinueConversationAsync:
if (conversationReference != null)
{
await turnContext.Adapter.ContinueConversationAsync(
BotAppId,
conversationReference,
async (t2, c2) =>
{
await t2.SendActivityAsync(MessageFactory.Text(messages[0]), cancellationToken: c2).ConfigureAwait(false);
},cancellationToken).ConfigureAwait(false);
}
ConversationParameters供参考:
var conversationParameters = new ConversationParameters
{
IsGroup = false,
Bot = this.TeamsHelper.GetRecipient(turnContext),
Members = new List<ChannelAccount>() { member },
TenantId = this.TeamsHelper.GetChannelTennantId(channelData),
TopicName = "Testing",
};
任何帮助都将不胜感激!
var teamsChannelId = turnContext.Activity.TeamsGetChannelId();
var serviceUrl = turnContext.Activity.ServiceUrl;
var credentials = new MicrosoftAppCredentials(BotAppId, BotAppPassword);
var channelData = turnContext.Activity.GetChannelData<TeamsChannelData>();
var conversationParameters = new ConversationParameters
{
IsGroup = false,
Bot = turnContext.Activity.Recipient,
Members = new List<ChannelAccount>() { member },
//TenantId = turnContext.Activity.Conversation.TenantId,
TenantId = channelData.Tenant.Id,
TopicName = "Testing Topic ",
};
var conversationReference = new ConversationReference()
{
ChannelId = teamsChannelId,
Bot = turnContext.Activity.Recipient,
ServiceUrl = serviceUrl,
Conversation = new ConversationAccount() { ConversationType = "channel", IsGroup = false, Id = teamsChannelId, TenantId = channelData.Tenant.Id },
};
await ((BotFrameworkAdapter)turnContext.Adapter).CreateConversationAsync(
teamsChannelId,
serviceUrl,
credentials,
conversationParameters,
async (t1, c1) =>
{
await ((BotFrameworkAdapter)turnContext.Adapter).ContinueConversationAsync(
BotAppId,
conversationReference,
async (t2, c2) =>
{
await t2.SendActivityAsync(MessageFactory.Text("This will be the first response to the new thread"), c2).ConfigureAwait(false);
},
cancellationToken).ConfigureAwait(false);
},
cancellationToken).ConfigureAwait(false);
发布于 2021-09-28 06:37:16
我想向大家提供一个建议:
如果要向用户亲自发送消息,则需要传递1:1 chat的会话Id,而不是通道,因此,会话引用应该如下所示(请参阅CreateConversationAsync中的变量conversationReference ):
await ((BotFrameworkAdapter)turnContext.Adapter).CreateConversationAsync(
"msteams",
serviceUrl,
credentials,
conversationParameters,
async (t1, c1) =>
{
var userConversation = t1.Activity.Conversation.Id;
var conversationReference = new ConversationReference
{
ServiceUrl = serviceUrl,
Conversation = new ConversationAccount
{
Id = userConversation,
},
};
await ((BotFrameworkAdapter)turnContext.Adapter).ContinueConversationAsync(
BotAppId,
conversationReference,
async (t2, c2) =>
{
await t2.SendActivityAsync(MessageFactory.Text("This will be the first response to the new thread"), c2).ConfigureAwait(false);
},
cancellationToken).ConfigureAwait(false);
},
cancellationToken).ConfigureAwait(false);
我能够在本地测试这种方法,而且成功了!
https://stackoverflow.com/questions/68678026
复制相似问题