Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cards bot sample #68

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions samples/basic/cards/nodejs/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
registry=https://registry.npmjs.org/
@microsoft:registry=https://pkgs.dev.azure.com/ConversationalAI/BotFramework/_packaging/SDK/npm/registry/
package-lock=false
107 changes: 107 additions & 0 deletions samples/basic/cards/nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Cards-bot

This is a sample of a simple Agent that is hosted on an Node.js web service. This Agent is configured to show how to create a bot that uses rich cards to enhance your bot design.

## Prerequisites

- [Node.js](https://nodejs.org) version 20 or higher

```bash
# determine node version
node --version
```

## Running this sample

1. Open this folder from your IDE or Terminal of preference
1. Install dependencies

```bash
npm install
```

### Run in localhost, anonymous mode

1. Create the `.env` file (or rename env.TEMPLATE)

```bash
cp env.TEMPLATE .env
```

1. Start the application

```bash
npm start
```

At this point you should see the message

```text
Server listening to port 3978 for appId debug undefined
```

The bot is ready to accept messages.

### Interact with the bot from the Teams App Test Tool

To interact with the bot you need a chat client, during the install phase we have acquired the `teams-test-app-tool` than can be used to interact with your bot running in `localhost:3978`

1. Start the test tool with

```bash
npm run test-tool
```

The tool will open a web browser showing the Teams App Test Tool, ready to send messages to your bot.

Alternatively you can run the next command to start the bot and the test tool with a single command (make sure you stop the bot started previously):

```bash
npm test
```

Refresh the browser to start a new conversation with the Cards bot.

You should see a message with the list of available cards in Agents:
- Adaptive Card
- Animation Card
- Audio Card
- Hero Card
- Receipt Card
- O365 Connector Card
- Thumbnail Card
- Video Card

### Interact with the bot from WebChat using Azure Bot Service

1. [Create an Azure Bot](https://aka.ms/AgentsSDK-CreateBot)
- Record the Application ID, the Tenant ID, and the Client Secret for use below

2. Configuring the token connection in the Agent settings
1. Open the `env.TEMPLATE` file in the root of the sample project, rename it to `.env` and configure the following values:
1. Set the **clientId** to the AppId of the bot identity.
2. Set the **clientSecret** to the Secret that was created for your identity.
3. Set the **tenantId** to the Tenant Id where your application is registered.

3. Install the tool [dev tunnel](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started?tabs=windows)
4. Run `dev tunnels`. See [Create and host a dev tunnel](https://learn.microsoft.com/en-us/azure/developer/dev-tunnels/get-started?tabs=windows) and host the tunnel with anonymous user access command as shown below:

```bash
devtunnel host -p 3978 --allow-anonymous
```

5. Take note of the url shown after `Connect via browser:`

6. On the Azure Bot, select **Settings**, then **Configuration**, and update the **Messaging endpoint** to `{tunnel-url}/api/messages`

7. Start the Agent using `npm start`

8. Select **Test in WebChat** on the Azure portal.

### Deploy to Azure

[TBD]

## Further reading

To learn more about building Bots and Agents, see our [Microsoft 365 Agents SDK](https://github.com/microsoft/agents) repo.
4 changes: 4 additions & 0 deletions samples/basic/cards/nodejs/env.TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# rename to .env
tenantId=
clientId=
clientSecret=
28 changes: 28 additions & 0 deletions samples/basic/cards/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "cards-bot",
"version": "1.0.0",
"private": true,
"description": "Agents cards bot sample",
"author": "Microsoft",
"license": "MIT",
"main": "./lib/index.js",
"scripts": {
"build": "tsc --build",
"prestart": "npm run build",
"start": "node --env-file .env ./dist/index.js",
"test-tool": "teamsapptester start",
"test": "npm-run-all -p -r start test-tool"
},
"dependencies": {
"@microsoft/agents-bot-hosting": "0.1.20",
"express": "^5.0.1",
"express-rate-limit": "^7.5.0"
},
"devDependencies": {
"@microsoft/teams-app-test-tool": "^0.2.6",
"@types/node": "^22.13.4",
"npm-run-all": "^4.1.5",
"typescript": "^5.7.2"
},
"keywords": []
}
205 changes: 205 additions & 0 deletions samples/basic/cards/nodejs/resources/adaptiveCard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"$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
},
{
"type": "TextBlock",
"text": "Jeremy Goldberg",
"spacing": "none"
},
{
"type": "TextBlock",
"text": "Evan Litvak",
"spacing": "none"
},
{
"type": "TextBlock",
"text": "2 Stops",
"weight": "bolder",
"spacing": "medium"
},
{
"type": "TextBlock",
"text": "Fri, October 10 8:30 AM",
"weight": "bolder",
"spacing": "none"
},
{
"type": "ColumnSet",
"separator": true,
"columns": [
{
"type": "Column",
"width": 1,
"items": [
{
"type": "TextBlock",
"text": "San Francisco",
"isSubtle": true
},
{
"type": "TextBlock",
"size": "extraLarge",
"color": "accent",
"text": "SFO",
"spacing": "none"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": " "
},
{
"type": "Image",
"url": "http://adaptivecards.io/content/airplane.png",
"size": "small",
"spacing": "none"
}
]
},
{
"type": "Column",
"width": 1,
"items": [
{
"type": "TextBlock",
"horizontalAlignment": "right",
"text": "Amsterdam",
"isSubtle": true
},
{
"type": "TextBlock",
"horizontalAlignment": "right",
"size": "extraLarge",
"color": "accent",
"text": "AMS",
"spacing": "none"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Non-Stop",
"weight": "bolder",
"spacing": "medium"
},
{
"type": "TextBlock",
"text": "Fri, October 18 9:50 PM",
"weight": "bolder",
"spacing": "none"
},
{
"type": "ColumnSet",
"separator": true,
"columns": [
{
"type": "Column",
"width": 1,
"items": [
{
"type": "TextBlock",
"text": "Amsterdam",
"isSubtle": true
},
{
"type": "TextBlock",
"size": "extraLarge",
"color": "accent",
"text": "AMS",
"spacing": "none"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": " "
},
{
"type": "Image",
"url": "http://adaptivecards.io/content/airplane.png",
"size": "small",
"spacing": "none"
}
]
},
{
"type": "Column",
"width": 1,
"items": [
{
"type": "TextBlock",
"horizontalAlignment": "right",
"text": "San Francisco",
"isSubtle": true
},
{
"type": "TextBlock",
"horizontalAlignment": "right",
"size": "extraLarge",
"color": "accent",
"text": "SFO",
"spacing": "none"
}
]
}
]
},
{
"type": "ColumnSet",
"spacing": "medium",
"columns": [
{
"type": "Column",
"width": "1",
"items": [
{
"type": "TextBlock",
"text": "Total",
"size": "medium",
"isSubtle": true
}
]
},
{
"type": "Column",
"width": 1,
"items": [
{
"type": "TextBlock",
"horizontalAlignment": "right",
"text": "$4,032.54",
"size": "medium",
"weight": "bolder"
}
]
}
]
}
]
}

Loading