azure - Azure Bot Framework - Direct Line 集成在用户键入内容之前不会显示介绍性消息
问题描述
我已经部署了一个 Azure 机器人,现在我正在尝试使其可用于测试。
我已按照此处的说明将机器人嵌入到单独的 Azure Web 应用程序(在 html 页面内) ,但在您键入内容之前不会显示介绍性消息。
所以要测试我的测试人员必须输入“go”(或类似的)来开始测试机器人。
使用模拟器测试 localhost 是可以的。
通过 Azure 门户进行测试也可以(但我的测试人员无法访问 Azure 门户)。
解决方案
在您的 Bot 文件中,添加以下代码:
protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
{
try
{
foreach (var member in membersAdded)
{
if (member.Id != turnContext.Activity.Recipient.Id)
{
var Userid=turnContext.Activity.From.Name;
UserProfile userProfile = await _botStateService.UserProfileAccessors.GetAsync(turnContext, () => new UserProfile());
userProfile.name = Userid;
await _botStateService.UserProfileAccessors.SetAsync(turnContext, userProfile);
await turnContext.SendActivityAsync(MessageFactory.Text($" Hi, bot here "), cancellationToken);
}
}
}
推荐阅读
- python - 从 pandas 数据框数据透视表创建图
- parsing - Boost Spirit X3 支持左递归吗?
- python - 如何通过 Python 中的 LXML 引用父元素并删除 RSS XML 中的父元素?
- javascript - 在 Click 函数中访问“this”
- javascript - 使用带有 Materialize v1.0.0 的 React.JS 无法初始化 JS
- php - 条纹电子邮件收据项目
- java - “selection”和“selectionArgs”子句如何为 ContentProvider 工作
- tfs - 使 release def 上下文菜单项有条件地不可见
- java - Java - PDF 转 PCL
- spring-boot - 使用 spring-boot 2.0.2.RELEASE 并且 FlyWay 没有运行。没有错误