C# webchat上的UserProfile状态为null,但directline和emulator上的状态为ok
我正在向我的多对话框机器人传递一个状态访问器。我注意到在webchat上,通过_stateBotAccessor.UserProfileAccessor.GetAsync()检索userProfile时返回null,但conversationData被持久化。通过emulator和directline进行测试,显示正确填充的用户配置文件 下面是我的简单UserProfile类:C# webchat上的UserProfile状态为null,但directline和emulator上的状态为ok,c#,botframework,C#,Botframework,我正在向我的多对话框机器人传递一个状态访问器。我注意到在webchat上,通过_stateBotAccessor.UserProfileAccessor.GetAsync()检索userProfile时返回null,但conversationData被持久化。通过emulator和directline进行测试,显示正确填充的用户配置文件 下面是我的简单UserProfile类: public class UserProfile { public UserProfile(string n
public class UserProfile
{
public UserProfile(string name)
{
this.UserName = name;
}
public string UserName { get; set; }
}
下面是我的简单ConversationData类:
public class ConversationData
{
public ConversationData(string channelId)
{
ChannelId = channelId;
}
// The ID of the user's channel.
public string ChannelId { get; set; }
}
这是我的StateBotAccessor类:
public class StateBotAccessors
{
public StateBotAccessors(ConversationState conversationState, UserState userState)
{
ConversationState = conversationState ?? throw new ArgumentNullException("UserProfile");
UserState = userState ?? throw new ArgumentNullException("ConversationData");
}
public IStatePropertyAccessor<UserProfile> UserProfileAccessor { get; set; }
public IStatePropertyAccessor<ConversationData> ConversationDataAccessor { get; set; }
public IStatePropertyAccessor<DialogState> DialogStateAccessor { get; set; }
public ConversationState ConversationState { get; }
public UserState UserState { get; }
}
测试结果如下所示:
示例webchat和directline客户端位于git项目的/clients文件夹下。
我的webchat客户端很简单:
const res = await fetch('https://directline.botframework.com/v3/directline/conversations',
{
method: 'POST',
headers: {
"Authorization": "Bearer mySecretKey",
},
});
const { token } = await res.json();
var dl = window.WebChat.createDirectLine({ token });
window.WebChat.renderWebChat({
directLine: dl,
user : user,
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
我希望userProfile像在emulator和directline频道上一样在webchat频道上保持不变。有什么我遗漏的吗?webchat频道可能有一些特殊处理?webchat客户端对用户id非常特殊,除非正确配置了特定的用户id,否则会话不会持久化
...
var user = {id: 'test@test.com',
name: 'You'
};
....
var dl = window.WebChat.createDirectLine({ token });
window.WebChat.renderWebChat({
directLine: dl,
userId : user.id,
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
@mjwills我清理了git项目,然后为反映问题的示例directline和webchat客户端添加了一个新文件夹/客户端。@mjwills我再次编辑,并将相关代码放入问题文本本身。谢谢你指导我完成这件事。
var conversationState = await _accessors.ConversationDataAccessor.GetAsync(sc.Context, () => null);
var userProfile = await _accessors.UserProfileAccessor.GetAsync(sc.Context, () => null);
await sc.Context.SendActivityAsync($"conversationState.ChannelId: {conversationState?.ChannelId}");
await sc.Context.SendActivityAsync($"userProfile.UserName: {userProfile?.UserName}");
const res = await fetch('https://directline.botframework.com/v3/directline/conversations',
{
method: 'POST',
headers: {
"Authorization": "Bearer mySecretKey",
},
});
const { token } = await res.json();
var dl = window.WebChat.createDirectLine({ token });
window.WebChat.renderWebChat({
directLine: dl,
user : user,
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
...
var user = {id: 'test@test.com',
name: 'You'
};
....
var dl = window.WebChat.createDirectLine({ token });
window.WebChat.renderWebChat({
directLine: dl,
userId : user.id,
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();