Bre*_*art 3 botframework microsoft-teams
当用户安装我的Teams机器人时,我希望发送欢迎消息。
我查看了Teams API文档,并收到了有关是否应该这样做的混合消息。我已经在各个地方阅读了我的机器人在安装bot时应该收到的会话更新,以及阅读了各种我不会收到此类事件的问题。
但是,存在具有此功能的机器人。Hipmunk与私有作用域一起安装时,向我发送了一条消息,而没有进一步激怒。该机器人如何做到这一点,以及如何复制此功能?
谢谢
文档可能会发生冲突,因为MS团队团队在实现所有botframework功能方面取得了非常快的进展。我们还对活动处理程序进行了相当大的更改- 我个人不知道这些特定更改是否进行了更改,因此该机器人可以接收Teams ConversationUpdate或由于其他原因而起作用。
这些表格应按渠道相当准确地反映活动的当前状态。
我刚刚测试了一个Teams机器人,该机器人可以在几种情况下捕获每个活动,这是活动处理程序触发的内容:
当用户首次添加Bot时(1:1欢迎消息):
将Bot安装到频道时(组欢迎消息):
注意:这些应该也火了,当用户被添加到机器人已存在的团队(不队内通道),但我不能对此进行测试。
向机器人发送消息时:
这是我用来测试此代码的代码(来自bot.ts,由Echo Bot Sample构建):
import { ActivityHandler, MessageFactory, TurnContext } from 'botbuilder';
export class MyBot extends ActivityHandler {
constructor() {
super();
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
this.onTurn(async (turnContext, next) => { await this.sendTeamsMessage('onTurn', turnContext); await next();});
this.onMembersAdded(async (turnContext, next) => { await this.sendTeamsMessage('onMembersAdded', turnContext); await next();});
this.onMembersRemoved(async (turnContext, next) => { await this.sendTeamsMessage('onMembersRemoved', turnContext); await next();});
this.onEvent(async (turnContext, next) => { await this.sendTeamsMessage('onEvent', turnContext); await next();});
this.onConversationUpdate(async (turnContext, next) => { await this.sendTeamsMessage('onConversationUpdate', turnContext); await next();});
this.onMessage(async (turnContext, next) => { await this.sendTeamsMessage('onMessage', turnContext); await next();});
this.onTokenResponseEvent(async (turnContext, next) => { await this.sendTeamsMessage('onTokenResponseEvent', turnContext); await next();});
this.onUnrecognizedActivityType(async (turnContext, next) => { await this.sendTeamsMessage('onUnrecognizedActivityType', turnContext); await next();});
this.onDialog(async (turnContext, next) => { await this.sendTeamsMessage('onDialog', turnContext); await next();});
}
private sendTeamsMessage = async (activityHandlerName: string, turnContext: TurnContext) => {
const message = MessageFactory.text(`**[${activityHandlerName}]** event received`);
await turnContext.sendActivity(message);
console.log(`Sent: ${message.text}`)
}
}
Run Code Online (Sandbox Code Playgroud)
注意:await next()确保可以为给定活动调用所有适当的活动处理程序,而不是在onTurn调用第一个()之后停止。
这样的事情应该可以工作(来自Core Bot Sample):
this.onMembersAdded(async (context) => {
const membersAdded = context.activity.membersAdded;
for (const member of membersAdded) {
if (member.id !== context.activity.recipient.id) {
const welcomeCard = CardFactory.adaptiveCard(WelcomeCard);
await context.sendActivity({ attachments: [welcomeCard] });
}
}
});
Run Code Online (Sandbox Code Playgroud)
我们正在使用新的活动处理程序编写示例,但是您可以梳理此示例分支以获取一些想法。我用TypeScript编写了我的代码,但是它可以工作,并且在C#中也有示例。
| 归档时间: |
|
| 查看次数: |
388 次 |
| 最近记录: |