问题描述
有一个对话历史记录"示例: https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/22.conversation-history
There is a sample for Conversation History: https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/22.conversation-history
实际上,在我尝试运行成绩单时,无法发送成绩单.特别是这一行:
Actually sending the transcript doesn't work in my attempts to run it. Specifically this line:
await connectorClient.Conversations.SendConversationHistoryAsync(activity.Conversation.Id, transcript, cancellationToken: cancellationToken);
我收到以下异常:
我可以确认记录文件已保存在我的Blob存储中,并且可以遍历从Blob中检索到的活动.
I can confirm that the transcript files are saved in my blob storage, and I can iterate through the activities retrieved from the blob.
(1)要使SendConversationHistoryAsync()正常工作,我缺少什么?
(1) What am I missing to get SendConversationHistoryAsync() to work?
(2)发送时,实际成绩单是什么样子? (仅遍历我的活动并处理每种活动类型并发出自己的对话历史记录消息是否值得?)
(2) What does the actual transcript look like when sent? (Is it worth it to just iterate through my activities and handle each activity type and make my own conversation history message?)
推荐答案
ConversationHistory 示例功能正常.但是,当使用 WebChat 或 Emulator 通道时,必须更新Activity.Id
.否则,WebChat控件将过滤掉它们(如果已经存在):
The ConversationHistory sample functions as expected. But, when using the WebChat or Emulator channels, the Activity.Id
s must be updated. Otherwise, the WebChat control will filter them out if already present:
bool updateActivities = new[] { Channels.Webchat, Channels.Emulator, Channels.Directline, }
.Contains(activity.ChannelId);
var incrementId = 0;
//get current id to ensure we do not overlap
if (updateActivities && activity.Id.Contains("|"))
{
int.TryParse(activity.Id.Split('|')[1], out incrementId);
}
/* get activities */
foreach (var a in activities)
{
incrementId++;
a.Id = string.Concat(activity.Conversation.Id, "|", incrementId.ToString().PadLeft(7, '0'));
a.Timestamp = DateTimeOffset.UtcNow;
a.ChannelData = string.Empty; // WebChat uses ChannelData for id comparisons, so clear it
}
var transcript = new Transcript(activities);
await connectorClient.Conversations.SendConversationHistoryAsync(activity.Conversation.Id,
transcript, cancellationToken: cancellationToken);
这篇关于如何发送聊天记录? SendConversationHistoryAsync()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!