简体   繁体   English

如何在 Microsoft Team 应用程序中使用 @microosft/teamsfx 的 ConversationBot 和 botbuiler 的 EventHandler

[英]How to use ConversationBot from @microosft/teamsfx and EventHandler from botbuiler in the microsoft team app

I am developing an app using teamsfx toolkit and I have two important use case.我正在使用 teamsfx 工具包开发一个应用程序,我有两个重要的用例。

Need to send notifications to particular users via API I also need to send a welcome message to newly installed users.需要通过 API 向特定用户发送通知 我还需要向新安装的用户发送欢迎信息。 I am using ConversationBot from @microosft/temasfx library to set adapter config and send notifications to users using API/notification URL like我正在使用 @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()) {

I also need to extend an EventHandler class to override我还需要扩展一个 EventHandler class 来覆盖

this.onMembersAdded(async (context, next) => {() 

method to send a welcome message.发送欢迎消息的方法。 But I am unable to like these two classes in the same app.但是我无法在同一个应用程序中喜欢这两个类。

I have我有

const bot = new ConversationBot

Like I also have就像我也有

class WelcomeBot extends ActivityHandler
{
this.onMemebersAdded(){//sending welcome message}

So the question is how to link both in the same bot app so that I can send a welcome Message using EventHandler and send Notifications via ConversationBot?所以问题是如何在同一个机器人应用程序中链接两者,以便我可以使用 EventHandler 发送欢迎消息并通过 ConversationBot 发送通知?

If your app is created via Teams Toolkit, probably you have following code (normally in index.js|ts ):如果您的应用程序是通过 Teams Toolkit 创建的,您可能有以下代码(通常在index.js|ts中):

server.post("/api/messages", async (req, res) => {
  await bot.requestHandler(req, res);
});

Here bot is a ConversationBot .这里的bot是一个ConversationBot To integrate your WelcomeBot with ConversationBot , please change the code await bot.requestHandler(req, res);要将WelcomeBotConversationBot集成,请更改代码await bot.requestHandler(req, res); to await bot.adapter.processActivity(req, res, (context) => welcomeBot.run(context)); await bot.adapter.processActivity(req, res, (context) => welcomeBot.run(context));

The full code may look like:完整代码可能如下所示:

/// 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));
});

The details behind are - All bot operations depend on Adapter .背后的细节是——所有的bot操作都依赖于Adapter The ConversationBot provides a helper method requestHandler to simplify the code. ConversationBot提供了一个辅助方法requestHandler来简化代码。 But if you'd like to add your own bot logic to the Adapter , you need to explicitly get Adapter via ConversationBot.adapter , then add your own logic.但是,如果您想将自己的机器人逻辑添加到Adapter中,则需要通过ConversationBot.adapter显式获取Adapter ,然后添加您自己的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Microsoft Teams 上的 Microsoft Bot Framework 中在应用安装时从团队中提取用户 - How do i pull users from a team in Microsoft Bot Framework on Microsoft Teams on app install Microsoft Bot Framework-如何从团队渠道获取用户数据 - Microsoft Bot Framework - How to get user data from team channel 是否可以从外部渠道向微软团队发送消息 - Is it possible to send messages to microsoft team from external channel 如何从 azureBot 记录团队会议 - How to Record Team meeting From as azureBot 如何通过 ms 团队应用程序中的自适应卡发送团队 ID 和频道 ID - How can send Team ID and Channel id through adaptive card from ms teams app Bot应用程序无法使用其他用户角色(Microsoft Bot Framework) - Bot app not working from another User Role (Microsoft Bot Framework) 如何从微软机器人发送电子邮件? - how to send an email from a microsoft bot? Microsoft Teams:将我的自定义应用程序安装到我组织的团队中时出现“出现问题” - Microsoft Teams: "Something went wrong" while installing my custom app into my organization's team 如何使用 Microsoft Graph 客户端作为其他用户从 Microsoft Teams Bot 发送电子邮件? - How to send email from Microsoft Teams Bot using Microsoft Graph Client as a different user? 如何启动从Node.js客户端到Microsoft Bot的对话 - How to start a conversation from nodejs client to microsoft bot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM