![](/img/trans.png)
[英]How do i pull users from a team in Microsoft Bot Framework on Microsoft Teams on app install
[英]How to use ConversationBot from @microosft/teamsfx and EventHandler from botbuiler in the microsoft team app
我正在使用 teamsfx 工具包开发一个应用程序,我有两个重要的用例。
需要通过 API 向特定用户发送通知 我还需要向新安装的用户发送欢迎信息。 我正在使用 @microosft/temasfx 库中的 ConversationBot 来设置适配器配置并使用 API/通知 URL 向用户发送通知,例如
const bot = new ConversationBot({
// The bot id and password to create BotFrameworkAdapter.
adapterConfig: {
appId: config.botId,
appPassword: config.botPassword,
}}
// and when the server.post api use this to send notification
for (const target of await Mybot.notification.installations()) {
我还需要扩展一个 EventHandler class 来覆盖
this.onMembersAdded(async (context, next) => {()
发送欢迎消息的方法。 但是我无法在同一个应用程序中喜欢这两个类。
我有
const bot = new ConversationBot
就像我也有
class WelcomeBot extends ActivityHandler
{
this.onMemebersAdded(){//sending welcome message}
所以问题是如何在同一个机器人应用程序中链接两者,以便我可以使用 EventHandler 发送欢迎消息并通过 ConversationBot 发送通知?
如果您的应用程序是通过 Teams Toolkit 创建的,您可能有以下代码(通常在index.js|ts
中):
server.post("/api/messages", async (req, res) => {
await bot.requestHandler(req, res);
});
这里的bot
是一个ConversationBot
。 要将WelcomeBot
与ConversationBot
集成,请更改代码await bot.requestHandler(req, res);
await bot.adapter.processActivity(req, res, (context) => welcomeBot.run(context));
完整代码可能如下所示:
/// init somewhere
const bot = new ConversationBot...
const welcomeBot = new WelcomeBot...
/// The "/api/messages" handler
server.post("/api/messages", async (req, res) => {
await bot.adapter.processActivity(req, res, (context) => welcomeBot.run(context));
});
背后的细节是——所有的bot操作都依赖于Adapter
。 ConversationBot
提供了一个辅助方法requestHandler
来简化代码。 但是,如果您想将自己的机器人逻辑添加到Adapter
中,则需要通过ConversationBot.adapter
显式获取Adapter
,然后添加您自己的逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.