如何发送1:1欢迎消息? [英] How do I send a 1:1 welcome message?

查看:115
本文介绍了如何发送1:1欢迎消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户安装我的Teams机器人时,我希望发送欢迎消息.

I am looking to send a welcome message when a user installs my Teams bot.

我查看了Teams API文档,并收到有关是否应该这样做的混合消息.我已经在各个地方阅读了我的机器人在安装bot时应该收到的对话更新,以及阅读了我不会收到此类事件的各种问题.

I've looked at the Teams API documentation and have received mixed messages on whether this should be possible. I have read in various places that my bot should receive a conversationUpdate when the bot is installed, as well as reading in various issues that I will not receive such an event.

但是,存在具有此功能的机器人. Hipmunk与私有范围一起安装时,向我发送了一条消息,而没有进一步激怒.该机器人如何做到这一点,我该如何复制此功能?

However, a bot exists which has this functionality. Hipmunk, when installed with private scope, sends me a message without being provoked further. How is this bot able to do this, and how can I replicate this functionality?

谢谢

推荐答案

文档可能会发生冲突,因为MS Teams团队在实现所有botframework功能方面取得了非常快的进步.我们还对活动处理程序-我个人不知道这些特定更改是否进行了更改,因此该机器人可以接收Teams ConversationUpdate或由于其他原因而起作用.

Documentation likely conflicts because the MS Teams team is making very fast progress in implementing all of the botframework features. We also have made some pretty big changes to activity handlers--I'm personally not aware whether or not these specific changes made it so the bot can receive the Teams ConversationUpdate or if it works because of something else.

These tables should fairly accurately reflect the current state of activities by channel.

我刚刚测试了一个Teams机器人,该机器人可以在几种情况下捕获每个活动,这是活动处理程序触发的事情:

I just tested a Teams bot that captures every activity with a few scenarios and here's what activity handlers fire:

用户首次添加Bot时(1:1欢迎消息):

  • OnConversationUpdate
  • OnTurn
  • 会员免费会员
  • OnDialog

将Bot安装到频道时(组欢迎消息):

注意:当用户添加到该机器人已经存在的团队(而非团队中的渠道)时,这些应该也会触发,但我无法对此进行测试.

Note: These should also fire when a user is added to a Team (not the channel within the team) where the bot already exists, but I'm not able to test this.

  • OnTurn
  • OnConversationUpdate
  • 会员免费会员
  • OnDialog

收到Bot消息时:

  • OnTurn
  • OnMessage
  • OnDialog

这是我用来测试此代码的代码(来自bot.ts,由

Here's the code I used to test this (from bot.ts, built from 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}`)
    }
}

注意:await next()确保可以为给定活动调用所有适当的活动处理程序,而不是在调用第一个(onTurn)之后停止.

Note: await next() ensures that all appropriate activity handlers can be called for a given activity instead of stopping after the first one (onTurn) is called.

类似的东西应该起作用(来自

Something like this should work (from the 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] });
        }
    }
});

我们正在使用新的活动处理程序来编写示例,但是您可以也是C#中的示例.

We're working on writing samples with the new activity handlers, but you can comb through this Samples Branch to get some ideas. I wrote mine in TypeScript, but it works and there are samples in C#, too.

这篇关于如何发送1:1欢迎消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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