Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions examples/quoted-replies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
teams*.yml
env/
infra/
node_modules/
.vscode/
dist/
.env
30 changes: 30 additions & 0 deletions examples/quoted-replies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Example: Quoted Replies

A bot that demonstrates quoted reply features in Microsoft Teams — referencing previous messages when sending responses.

## Commands

| Command | Behavior |
|---------|----------|
| `test reply` | `reply()` — auto-quotes the inbound message |
| `test quote` | `quote()` — sends a message, then quotes it by ID |
| `test add` | `addQuote()` — sends a message, then quotes it with builder + response |
| `test multi` | Sends two messages, then quotes both with interleaved responses |
| `test manual` | `addQuote()` + `addText()` — manual control |
| `help` | Shows available commands |
| *(quote a message)* | Bot reads and displays the quoted reply metadata |

## Run

```bash
npm run dev
```

## Environment Variables

Create a `.env` file:

```
CLIENT_ID=<your-azure-bot-app-id>
CLIENT_SECRET=<your-azure-bot-app-secret>
```
Binary file added examples/quoted-replies/appPackage/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions examples/quoted-replies/appPackage/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/teams/v1.20/MicrosoftTeams.schema.json",
"version": "1.0.0",
"manifestVersion": "1.20",
"id": "${{TEAMS_APP_ID}}",
"name": {
"short": "quoted-replies",
"full": "Quoted Replies Example"
},
"developer": {
"name": "Microsoft",
"mpnId": "",
"websiteUrl": "https://microsoft.com",
"privacyUrl": "https://privacy.microsoft.com/privacystatement",
"termsOfUseUrl": "https://www.microsoft.com/legal/terms-of-use"
},
"description": {
"short": "Bot demonstrating quoted replies",
"full": "A sample bot that demonstrates how to send and receive quoted replies in Microsoft Teams."
},
"icons": {
"outline": "outline.png",
"color": "color.png"
},
"accentColor": "#FFFFFF",
"staticTabs": [
{
"entityId": "conversations",
"scopes": ["personal"]
},
{
"entityId": "about",
"scopes": ["personal"]
}
],
"bots": [
{
"botId": "${{BOT_ID}}",
"scopes": ["personal", "team", "groupChat"],
"isNotificationOnly": false,
"supportsCalling": false,
"supportsVideo": false,
"supportsFiles": false
}
],
"validDomains": ["${{BOT_DOMAIN}}", "*.botframework.com"],
"webApplicationInfo": {
"id": "${{BOT_ID}}",
"resource": "api://botid-${{BOT_ID}}"
}
}
Binary file added examples/quoted-replies/appPackage/outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/quoted-replies/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@microsoft/teams.config/eslint.config').default;
35 changes: 35 additions & 0 deletions examples/quoted-replies/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@examples/quoted-replies",
"version": "0.0.0",
"private": true,
"license": "MIT",
"main": "dist/index",
"types": "dist/index",
"files": [
"dist",
"README.md"
],
"scripts": {
"clean": "npx rimraf ./dist",
"lint": "npx eslint",
"lint:fix": "npx eslint --fix",
"build": "npx tsc",
"start": "node .",
"dev": "tsx watch -r dotenv/config src/index.ts"
},
"dependencies": {
"@microsoft/teams.api": "*",
"@microsoft/teams.apps": "*",
"@microsoft/teams.cards": "*",
"@microsoft/teams.common": "*",
"@microsoft/teams.dev": "*"
},
"devDependencies": {
"@microsoft/teams.config": "*",
"@types/node": "^22.5.4",
"dotenv": "^16.4.5",
"rimraf": "^6.0.1",
"tsx": "^4.20.6",
"typescript": "^5.4.5"
}
}
115 changes: 115 additions & 0 deletions examples/quoted-replies/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { MessageActivity } from '@microsoft/teams.api';
import { App } from '@microsoft/teams.apps';
import { ConsoleLogger } from '@microsoft/teams.common/logging';
import { DevtoolsPlugin } from '@microsoft/teams.dev';

const app = new App({
logger: new ConsoleLogger('@examples/quoted-replies', { level: 'debug' }),
plugins: [new DevtoolsPlugin()],
});

app.on('message', async ({ send, reply, quote, activity }) => {
await reply({ type: 'typing' });

const text = activity.text?.toLowerCase() || '';

// ============================================
// Read inbound quoted replies
// ============================================
const quotes = activity.getQuotedMessages();
if (quotes.length > 0) {
const quote = quotes[0].quotedReply;
const info = [
`Quoted message ID: ${quote.messageId}`,
quote.senderName ? `From: ${quote.senderName}` : null,
quote.preview ? `Preview: "${quote.preview}"` : null,
quote.isReplyDeleted ? '(deleted)' : null,
quote.validatedMessageReference ? '(validated)' : null,
].filter(Boolean).join('\n');

await send(`You sent a message with a quoted reply:\n\n${info}`);
}

// ============================================
// reply() — auto-quotes the inbound message
// ============================================
if (text.includes('test reply')) {
await reply('Thanks for your message! This reply auto-quotes it using reply().');
return;
}

// ============================================
// quote() — quote a previously sent message by ID
// ============================================
if (text.includes('test quote')) {
const sent = await send('The meeting has been moved to 3 PM tomorrow.');
await quote(sent.id, 'Just to confirm — does the new time work for everyone?');
return;
}

// ============================================
// addQuote() — builder with response
// ============================================
if (text.includes('test add')) {
const sent = await send('Please review the latest PR before end of day.');
const msg = new MessageActivity()
.addQuote(sent.id, 'Done! Left my comments on the PR.');
await send(msg);
return;
}

// ============================================
// Multi-quote with mixed responses
// ============================================
if (text.includes('test multi')) {
const sentA = await send('We need to update the API docs before launch.');
const sentB = await send('The design mockups are ready for review.');
const sentC = await send('CI pipeline is green on main.');
const msg = new MessageActivity()
.addQuote(sentA.id, 'I can take the docs — will have a draft by Thursday.')
.addQuote(sentB.id, 'Looks great, approved!')
.addQuote(sentC.id);
await send(msg);
return;
}

// ============================================
// addQuote() + addText() — manual control
// ============================================
if (text.includes('test manual')) {
const sent = await send('Deployment to staging is complete.');
const msg = new MessageActivity()
.addQuote(sent.id)
.addText(' Verified — all smoke tests passing.');
await send(msg);
return;
}

// ============================================
// Help / Default
// ============================================
if (text.includes('help')) {
await reply(
'**Quoted Replies Test Bot**\n\n' +
'**Commands:**\n' +
'- `test reply` - reply() auto-quotes your message\n' +
'- `test quote` - quote() quotes a previously sent message\n' +
'- `test add` - addQuote() builder with response\n' +
'- `test multi` - Multi-quote with mixed responses (one bare quote with no response)\n' +
'- `test manual` - addQuote() + addText() manual control\n\n' +
'Quote any message to me to see the parsed metadata!'
);
return;
}

await reply('Say "help" for available commands.');
});

app.on('install.add', async ({ send }) => {
await send(
'Hi! I demonstrate quoted replies.\n\n' +
'Say **help** to see available commands.'
);
});

app.start().catch(console.error);
8 changes: 8 additions & 0 deletions examples/quoted-replies/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@microsoft/teams.config/tsconfig.node.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*.ts"]
}
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions packages/api/src/activities/activity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('Activity', () => {
conversation: chat,
})
.withRecipient(bot)
.withReplyToId('3')
.withServiceUrl('http://localhost')
.withTimestamp(new Date())
.withLocalTimestamp(new Date());
Expand All @@ -51,7 +50,6 @@ describe('Activity', () => {
});

expect(activity.recipient).toEqual(bot);
expect(activity.replyToId).toEqual('3');
expect(activity.serviceUrl).toEqual('http://localhost');
expect(activity.timestamp).toBeDefined();
expect(activity.localTimestamp).toBeDefined();
Expand Down
5 changes: 0 additions & 5 deletions packages/api/src/activities/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,6 @@ export class Activity<T extends string = string> implements IActivity<T> {
return this;
}

withReplyToId(value: string) {
this.replyToId = value;
return this;
}

withChannelId(value: ChannelID) {
this.channelId = value;
return this;
Expand Down
Loading
Loading