Skip to content

Commit

Permalink
Merge pull request #1153 from OfficeDev/v-pritka/code-blocks-card
Browse files Browse the repository at this point in the history
added adaptive card changes for code-block card
  • Loading branch information
Prithvi-MSFT authored Mar 12, 2024
2 parents 66c5bc7 + db3acd2 commit 40cbc1d
Show file tree
Hide file tree
Showing 6 changed files with 5,658 additions and 1,086 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions samples/bot-formatting-cards/nodejs/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ The simplest way to run this sample in Teams is to use Teams Toolkit for Visual
![PersonaSet](Images/11.PersonaSet.png)
**Code Block in Adaptive Card:**
![PersonaSet](Images/CodeBlocks.png)
## Deploy the bot to Azure
To learn more about deploying a bot to Azure, see [Deploy your bot to Azure](https://aka.ms/azuredeployment) for a complete list of deployment instructions.
Expand Down
17 changes: 16 additions & 1 deletion samples/bot-formatting-cards/nodejs/bots/botFormattingCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const HTMLConnectorCard = require('../resources/formatHTMLConnectorCard.json');
const CardWithEmoji = require('../resources/adaptiveCardWithEmoji.json');
const PeoplePersonaCardIcon = require('../resources/adaptivePeoplePersonaCardIcon.json');
const PeoplePersonaCardSetIcon = require('../resources/adaptivePeoplePersonaCardSetIcon.json');
const CodeBlocksCard = require('../resources/codeBlocksCard.json');

class BotFormattingCards extends ActivityHandler {
constructor() {
Expand All @@ -28,8 +29,9 @@ class BotFormattingCards extends ActivityHandler {
this.onMessage(async (context, next) => {
const text = context.activity.text;


// Create an array with the valid card options.
const adaptiveFormatCards = ['MentionSupport', 'InfoMasking', 'FullWidthCard', 'StageViewImages', 'OverflowMenu', 'HTMLConnector', 'CardWithEmoji','Persona','PersonaSet'];
const adaptiveFormatCards = ['CodeBlock', 'MentionSupport', 'InfoMasking', 'FullWidthCard', 'StageViewImages', 'OverflowMenu', 'HTMLConnector', 'CardWithEmoji','Persona','PersonaSet'];

// If the `text` is in the Array, a valid card was selected and sends.
if (adaptiveFormatCards.includes(text)) {
Expand Down Expand Up @@ -70,6 +72,10 @@ class BotFormattingCards extends ActivityHandler {
case "PersonaSet":
await context.sendActivity({ attachments: [this.sendPersonaCardSetIcons()] });
break;

case "CodeBlock":
await context.sendActivity({ attachments: [this.sendCodeBlock()] });
break;
}

await context.sendActivity(`You have Selected <b>${text}</b>`);
Expand Down Expand Up @@ -110,6 +116,10 @@ class BotFormattingCards extends ActivityHandler {
return CardFactory.adaptiveCard(MentionSupport);
}

sendCodeBlock() {
return CardFactory.adaptiveCard(CodeBlocksCard);
}

/**
* Sends Sample Adaptive Card With Full Width
*/
Expand Down Expand Up @@ -219,6 +229,11 @@ class BotFormattingCards extends ActivityHandler {
title: 'PersonaSet',
value: 'PersonaSet'
},
{
type: ActionTypes.ImBack,
title: 'CodeBlock',
value: 'CodeBlock'
},
{
type: ActionTypes.ImBack,
title: '',
Expand Down
22 changes: 22 additions & 0 deletions samples/bot-formatting-cards/nodejs/resources/codeBlocksCard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.5",
"body": [
{
"type": "TextBlock",
"text": "editor.js",
"style": "heading"
},
{
"type": "TextBlock",
"text": "Lines 61 - 76"
},
{
"type": "CodeBlock",
"codeSnippet": "/**\npackage l2f.gameserver.model;\n\npublic abstract strictfp class L2Char extends L2Object {\n public static final Short ERROR = 0x0001;\n\n public void moveTo(int x, int y, int z) {\n _ai = null;\n log(\"Shouldn't be called\");\n if (1 > 5) { // what!?\n return;\n }\n }\n}",
"language": "java",
"startLineNumber": 61
}
]
}
Loading

0 comments on commit 40cbc1d

Please sign in to comment.