MS Enterprise Bot(v4)-如何准确地以编程方式提及用户 [英] MS Enterprise Bot (v4) - how to exactly do a user mention programatically

查看:93
本文介绍了MS Enterprise Bot(v4)-如何准确地以编程方式提及用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的对Microsoft不完整的文档感到厌倦.几天来我一直在脑海里打动,只是为了创建用户提及.在互联网上扫描了一些代码,并尝试进行组合,但是我仍然没有使它起作用.

I'm really tired of microsoft incomplete documentation. I have been bangin my head for a few days just to create a user mention. Scanned the internet for bits of code and tried to combine, but i still havent made it work.

var reply = turnContext.Activity.CreateReply($"Test mention <at>@{name}</at>");
var entity = new Entity();
                entity.SetAs(new Mention()
                {
                    Text = $"<at>@{name}</at>",
                    Mentioned = new ChannelAccount()
                    {
                        Name = $"{name}",
                        Id = id
                    }
                });

if (turnContext.Activity.Entities == null || !turnContext.Activity.Entities.Any())
            {
                var list = new List<Entity> { entity };
                turnContext.Activity.Entities = list;
            }
            else
                turnContext.Activity.Entities.Add(entity);

await turnContext.SendActivityAsync(reply);

有人想过如何以编程方式发布/发送/回复带有用户提及的消息吗?

Anyone have thoughts on how to programatically post/send/reply message with a user mention?

谢谢.

推荐答案

很抱歉,文档并不容易找到. dotnet和Node SDK均未完全支持提及.但是,这可以通过当前的dotnet SDK来完成.这两个SDK现在都完全支持

I apologize that documentation hasn't been easy to find. Mentions aren't fully-supported across both dotnet and Node SDKs yet. However, this is possible to do with the current dotnet SDK. this is now fully supported in both SDKs

您的代码看起来还不错,除了您是将实体添加到TurnContext而不是reply认为这是您的问题).试试这个,我已经测试过并且可以正常工作:

Your code looks pretty good except that you're adding the entity to TurnContext and not the reply I think this is your issue). Try this, which I've tested and works:

var userId = "29:1lpScfExyzx-asdfasdfasdfasdf_fasdfasdfasdfasdfasdfasdfasdfasdfasdf";
var userName = "YourName";

var reply = turnContext.Activity.CreateReply();

reply.Text = $"<at>{ userName }</at> testing....";

var mentioned = new ChannelAccount()
{
    Id = userId,
    Name = userName
};

var entity = new Mention()
{
    Mentioned = mentioned,
    Text = $"<at>{ userName }</at>",
};

reply.Entities = new List<Entity>() { entity };

await turnContext.SendActivityAsync(reply);

确保reply.Text包含entity.Text,否则将不起作用(在示例中,<at>{ userName }</at>都在其中).

Make sure that reply.Text contains entity.Text or this will not work (in the example, <at>{ userName }</at> is in both).

如果遇到问题,Visual Studio不会提供太多错误信息.但是,如果打开"Azure">"Web App Bot">频道",然后查看团队频道问题",则会提供有关可能出问题的更多信息.

If you run into issues, Visual Studio doesn't provide much error information. However, if you open Azure > Your Web App Bot > Channels and look at the Teams Channel Issues, it gives a little more information about what might be wrong.

Teams还有一个 Botbuilder Teams Dotnet SDK ,其中包含其他文档和方法.它充当Botbuilder SDk的包装,使某些特定于Teams的事情更容易.请注意,此搜索有点麻烦,并且与仅支持的此SDK 不同V3机器人.

Teams also has a Botbuilder Teams Dotnet SDK that has additional documentation and methods. It acts as a wrapper around the Botbuilder SDk to make some Teams-specific things easier. Note that this one is kind of tricky to search for and is different from this SDK which only supports V3 bots.

这篇关于MS Enterprise Bot(v4)-如何准确地以编程方式提及用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆