How to use the botbuilder.CardFactory.adaptiveCard function in botbuilder

To help you get started, we’ve selected a few botbuilder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 07.using-adaptive-cards / bot.js View on Github external
async onTurn(context) {
        // See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
        if (context.activity.type === 'message') {
            const randomlySelectedCard = CARDS[Math.floor((Math.random() * CARDS.length - 1) + 1)];
            await context.sendActivity({
                text: 'Here is an Adaptive Card:',
                attachments: [CardFactory.adaptiveCard(randomlySelectedCard)]
            });
        } else {
            await context.sendActivity(`[${ context.activity.type } event detected]`);
        }
    }
}
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 51.cafe-bot / bot.js View on Github external
async welcomeUser(turnContext) {
        // Do we have any new members added to the conversation?
        if (turnContext.activity.membersAdded.length !== 0) {
            // Iterate over all new members added to the conversation
            for (var idx in turnContext.activity.membersAdded) {
                // Greet anyone that was not the target (recipient) of this message
                // 'bot' is the recipient for events from the channel,
                // turnContext.activity.membersAdded === turnContext.activity.recipient.Id indicates the
                // bot was added to the conversation.
                if (turnContext.activity.membersAdded[idx].id !== turnContext.activity.recipient.id) {
                    // Welcome user.
                    await turnContext.sendActivity(`Hello, I am the Contoso Cafe Bot!`);
                    await turnContext.sendActivity(`I can help book a table and more..`);

                    // Send welcome card.
                    await turnContext.sendActivity(MessageFactory.attachment(CardFactory.adaptiveCard(WelcomeCard)));
                }
            }
        }
    }
};
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 17.multilingual-bot / bots / multilingualBot.js View on Github external
this.onMembersAdded(async (context, next) => {
            const membersAdded = context.activity.membersAdded;
            for (let cnt = 0; cnt < membersAdded.length; cnt++) {
                if (membersAdded[cnt].id !== context.activity.recipient.id) {
                    const welcomeCard = CardFactory.adaptiveCard(WelcomeCard);
                    await context.sendActivity({ attachments: [welcomeCard] });
                    await context.sendActivity('This bot will introduce you to translation middleware. Say \'hi\' to get started.');
                }
            }

            // By calling next() you ensure that the next BotHandler is run.
            await next();
        });
github microsoft / BotBuilder-Samples / generators / generator-botbuilder / generators / app / templates / core / bot.js View on Github external
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types

            // Do we have any new members added to the conversation?
            if (context.activity.membersAdded.length !== 0) {
                // Iterate over all new members added to the conversation
                for (var idx in context.activity.membersAdded) {
                    // Greet anyone that was not the target (recipient) of this message
                    // the 'bot' is the recipient for events from the channel,
                    // context.activity.membersAdded == context.activity.recipient.Id indicates the
                    // bot was added to the conversation.
                    if (context.activity.membersAdded[idx].id !== context.activity.recipient.id) {
                        // Welcome user.
                        // When activity type is "conversationUpdate" and the member joining the conversation is the bot
                        // we will send our Welcome Adaptive Card.  This will only be sent once, when the Bot joins conversation
                        // To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details.
                        const welcomeCard = CardFactory.adaptiveCard(WelcomeCard);
                        await context.sendActivity({ attachments: [welcomeCard] });
                    }
                }
            }
        }

        // make sure to persist state at the end of a turn.
        await this.conversationState.saveChanges(context);
        await this.userState.saveChanges(context);
    }
github microsoft / botframework-solutions / templates / Virtual-Assistant-Template / typescript / generator-botbuilder-assistant / generators / app / templates / sample-assistant / src / responses / mainResponses.ts View on Github external
public static async buildNewUserGreetingCard(turnContext: TurnContext, data: any): Promise {
        const introFileName: string = i18next.t('main.introGreetingFile');
        const introPath: string = join(__dirname, '..', 'content', introFileName);
        // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/tslint/config
        const introCard: any = JSON.parse(readFileSync(introPath, 'UTF8'));
        const attachment: Attachment = CardFactory.adaptiveCard(introCard);
        // eslint-disable-next-line @typescript-eslint/tslint/config
        const response: Partial = MessageFactory.attachment(attachment, '', attachment.content.speak, InputHints.AcceptingInput);

        response.suggestedActions = {
            actions: [
                {
                    title: i18next.t('main.helpBtnText1'),
                    type: ActionTypes.ImBack,
                    value: i18next.t('main.helpBtnValue1')
                },
                {
                    title: i18next.t('main.helpBtnText2'),
                    type: ActionTypes.ImBack,
                    value: i18next.t('main.helpBtnValue2')
                },
                {
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 51.cafe-bot / dialogs / whatCanYouDo / index.js View on Github external
async beginDialog(dc, options) {
            await dc.context.sendActivity({ attachments: [CardFactory.adaptiveCard(helpCard)] });
            await dc.context.sendActivity(`Pick a query from the card or you can use the suggestions below.`);
            return await dc.endDialog();
        }
    }
github microsoft / botbuilder-js / samples / rich-cards-es6 / bot.js View on Github external
function createAdaptiveCard() {
    return CardFactory.adaptiveCard({
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "version": "1.0",
        "type": "AdaptiveCard",
        "speak": "Your flight is confirmed for you and 3 other passengers from San Francisco to Amsterdam on Friday, October 10 8:30 AM",
        "body": [
            {
                "type": "TextBlock",
                "text": "Passengers",
                "weight": "bolder",
                "isSubtle": false
            },
            {
                "type": "TextBlock",
                "text": "Sarah Hum",
                "separator": true
            },
github microsoft / botframework-solutions / templates / Enterprise-Template / src / typescript / enterprise-bot / src / dialogs / main / mainResponses.ts View on Github external
public static buildIntroCard(turnContext: TurnContext, data: any): Promise {
        const introPath = i18n.__('main.introPath');
        const introCard = require(introPath);
        const attachment = CardFactory.adaptiveCard(introCard);
        const response = MessageFactory.attachment(attachment, '', attachment.content.speak, InputHints.AcceptingInput);

        response.suggestedActions = {
            actions: [
                {
                    title: i18n.__('main.helpBtnText1'),
                    type: ActionTypes.ImBack,
                    value: i18n.__('main.helpBtnValue1')
                },
                {
                    title: i18n.__('main.helpBtnText2'),
                    type: ActionTypes.ImBack,
                    value: i18n.__('main.helpBtnValue2')
                },
                {
                    title: i18n.__('main.helpBtnText3'),
github OfficeDev / BotBuilder-MicrosoftTeams-node / botbuilder-teams-js / src / activityProcessor / teamsFactory.ts View on Github external
public static adaptiveCard(card: ac.IAdaptiveCard): Attachment {
    return CardFactory.adaptiveCard(card);
  }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 54.teams-task-module / bots / teamsTaskModuleBot.js View on Github external
createAdaptiveCardAttachment() {
        return CardFactory.adaptiveCard({
            version: '1.0.0',
            type: 'AdaptiveCard',
            body: [
                {
                    type: 'TextBlock',
                    text: 'Enter Text Here'
                },
                {
                    type: 'Input.Text',
                    id: 'usertext',
                    placeholder: 'add some text and submit',
                    IsMultiline: true
                }
            ],
            actions: [
                {