Search code examples
node.jstypescriptmicrosoft-teamsbotframework

Mention user in heroCard botframework (nodejs)


The user wants to return a message to a teams channel. In the card, I would like to mention the user that sent the message back to the channel. Following the instructions on the Microsoft Docs did not work. Using that TextEncoder, the user's name would get encoded and just sent back as numbers (eg. 82,111,115,105,101,114,115,44,32,74,97,115,112,10,....).

The way it is set up below returns the user's name, but not as a mention, just the text. How do I turn this into code that actually mentions the user?

I also tried using context.activity.from.name in the heroCard, but that didn't mention the user either.

const mention = {
            mentioned: context.activity.from,
            text: `<at>${context.activity.from.name}</at>`,
            type: 'mention'
        } as Mention;

        const heroCard = CardFactory.heroCard(
            `Returned question by ${ mention.mentioned.name }`,
            `${ mention.mentioned.name } You can internally discuss the user request below. ` +
            'Once ready, one person can take ownership of the conversation with the user by pressing the button. ' +
            'The user\'s question: ' + teamsSupport.question,
            null,
            CardFactory.actions([
                {
                    title: 'Takeover conversation',
                    type: ActionTypes.MessageBack,
                    displayText: `I will take this conversation.`,
                    text: this.configService.get<string>('TakeoverConfirmation') + teamsSupport.sessionId,
                    value: ''
                },
                {
                    title: 'Show chat history',
                    type: ActionTypes.OpenUrl,
                    value: 'https://****/conversations/' + teamsSupport.sessionId
                }
            ])
        );

        const suggestedActions = MessageFactory.attachment(heroCard);
        suggestedActions.entities = [mention];

Solution

  • As Wajeed-MSFT correctly stated, Mentions are not supported in heroCards.

    They are however supported for Text Messages and Adaptive cards and this works for me.