To use the adaptive-card-transformer you will need plugins, a pluginConfig.json, and a bot. To kickstart a project using the adaptive-card-transformer, leverage the Yeoman generator-AdaptiveCardTransformer to scaffold plugins, a pluginConfig.json, and an echo bot (if needed).
- If you do not have a bot, you can scaffold an echo bot with the generator-AdaptiveCardTransformer.
- After scaffolding the echo bot and selected plugins, the generator will prompt the user to overwrite certain files. This will automatically integrate the
adaptive-card-transformerand plugins into the scaffolded echo bot. - Add logic and templates to your template-selector, pre-processor, and post-processor plugins. For an example, please refer to the Adaptive Card Transformer Example Bot
- Configure the
.npmrcfile in your project root and ensure your PAT token is populated (see the Setup section of the README for more info) - Run
npm installto install all dependencies, includingadaptive-card-transformer - Run
npm startto run the echo bot with with theadaptive-card-transformer
If you already have a bot, follow these steps to integrate the adaptive-card-transformer into your bot:
-
In your bot project, scaffold plugins and the
pluginConfig.jsonwith the Yeoman generator-AdaptiveCardTransformer. -
Create the
.npmrcfile in your project root and ensure your PAT token is populated (see the Setup section of the README for more info) -
Add dependency on the
adaptive-card-transformerto your bot by running:npm install @retaildevcrews/adaptive-card-transformer
-
Import
cardFactoryfrom "botbuilder",adapter, andpluginConfig.jsonto your bot code (see below)import { CardFactory } from "botbuilder" import adapter from "@retaildevcrews/adaptive-card-transformer" // Adaptive Card Transformer Package import pluginConfig from "../plugins/pluginConfig.json" // invoke the adapter with each conversation payload and pluginConfig which identifies which plugins to use const cardJson = await adapter(conversationPayload, pluginConfig) // utilize the adaptive card factory to generate an activity attachment which is ready to be sent to the user (replied by the bot) const card = CardFactory.adaptiveCard(cardJson)
-
Call the adapter - pass in the
conversationPayloadand definedpluginConfiginto the adapter. -
Utilize the adaptive card factory to generate the activity attachment to be send to the user.
-
Run
npm startto run your bot with with theadaptive-card-transformer- Note: If data is not rendering from the conversation payload to the bot correctly, consider modifying the existing templates, adding a custom template, or performing additional data mapping on the conversationPayload.
To modify existing templates or build out new templates, please follow guidance in the Template Design Guidance documentation.
To add a new template to the Adaptive Card Transformer, please follow the guidance in the How to Extend documentation.