bot框架 - 静态菜单

发布于 2025-02-06 01:38:07 字数 240 浏览 2 评论 0原文

我正在使用Bot Framework(C#)创建聊天机器人,我在OnTurnAsync方法上添加了建议的操作,以显示用户作为菜单,但是当我运行机器人时,建议的操作方法将为每个活动运行,并将菜单显示为用户以来,由于我在OnTurnAsync方法中调用了它,因此是否有任何方法或方法可以将此建议的菜单添加为静态菜单,或者在用户加入对话时仅加载一次(请注意,我尝试在OnMemberAddedEdasync方法中拨打它,但是它显示了只有在开始时就消失了,随着操作的继续)。

Im creating a chatbot using bot framework (c#), I have added a suggested actions on onturnasync method to show up to the user as a menu, but when i run the bot the suggested actions method will run for each activity and show the menus to the user since i called it in onturnasync method, is there any method or way i can add this suggested menu as a static or to load only once when the user joins the conversation, (note I tried called it in onmemberaddedasync method , but it shows only at the starting and disappears as the operation continues).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久而酒知 2025-02-13 01:38:07

我可能制作此“静态菜单”的方式是使用中间件

目前,我有一个最初为网络聊天开发的聊天机器人。后来有一些冲刺,客户要求包括MS Teams频道。这给我带来了一些问题,因为不支持建议的某些功能。因此,当机器人位于MS Teams频道中时,我使用中间件用英雄卡代替了建议的动作。

我在您的位置要做的是创建一个中间件,并在发送之前将您的静态菜单附加到消息上。

您可以检查文档以获取有关 Middlewares。

如果我本周有一些空闲时间,我将创建一个简单的机器人来显示如何做到。

最良好的问候!

更新25/6/2022

我使用示例bot 在这里

三个组件对话框:

  • https://github.com/sempjc/botwithstaticmenu/blob/blob/master/staticmenubot/rootdialog.cs”
  • 用户配置文件
  • =“ https://github.com/sempjc/botwithstaticmenu/blob/master/staticmenubot/userprofiledialog.cs” rel =“ nofollow noreferrer”> “ /sempjc/botwithstaticmenu/blob/master/staticmenubot/weatherdialog.cs“ rel =“ nofollow noreferrer”>天气对话框
  • 取消命令(不是实际的对话框)

,以了解中间件的工作方式, ://github.com/sempjc/botwithstaticmenu/blob/master/staticmenubot/staticmenumiddleware.cs“ rel =“ nofollow noreferrer”> staticmenumiddleware

如何在您的项目中复制它?

  1. 为静态菜单创建中间件。就我而言,逻辑查找活动数组中的最后一个元素,并按照建议的操作附加静态菜单。
  2. 中间件添加为单身人士。
  3. 在您的
  4. 在机器人适配器的构造函数中,添加以下行use(< middleware_variable>),其中midderware_variable是您的依赖关系的名称。

希望此示例代码结果对每个人有帮助。
如果出现任何问题,我将尽快回答。

The way I probably make this "Static Menu" is using a middleware.

Currently I have a chatbot originally developed for a Webchat. Some sprint later, client requested to include MS Teams Channel. That create me some problems, because some features like suggested action is not supported. So I used middleware to replace suggested actions with Hero Cards, when bot is in MS Teams Channel.

What I do in your place is create a middleware and append your static menu to the message before send.

You can check the documentation for more details about middlewares.

If I have some free time this week, I will create a simple bot to show how you can do it.

Best regard!

Update 25/6/2022

I created a repository with a sample bot here

The sample bot is a bot with three component dialogs:

To understand how the middleware work go to StaticMenuMiddleware.

How to replicate this in your project?

  1. Create a middleware for your static menu. In my case the logic look for the last element in the activity array and append the static menu as Suggested Actions.
  2. Add this middleware as a singleton in your Startup.cs
  3. Modify your BotAdapter's constructor so it expect an IMiddleware as a dependency. Is possible to pass a list of IMiddleware but... is out of scope in this sample.
  4. Inside your Bot Adapter's constructor add the following line Use(<middleware_variable>), where middleware_variable is the name of your dependency.

Hope this sample code result helpful to everyone.
If any question arise, I will try to answer as soon as possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文