Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 683b292

Browse files
committed
migrate echo
1 parent 55d1f53 commit 683b292

3 files changed

Lines changed: 14 additions & 16 deletions

File tree

samples/javascript_nodejs/02.echo-bot/bot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// @ts-check
55

6-
const { ActivityHandler, MessageFactory } = require('botbuilder');
6+
const { ActivityHandler, MessageFactory } = require('@microsoft/agents-hosting');
77

88
class EchoBot extends ActivityHandler {
99
constructor() {
@@ -20,7 +20,7 @@ class EchoBot extends ActivityHandler {
2020
const membersAdded = context.activity.membersAdded ?? [];
2121
const welcomeText = 'Hello and welcome!';
2222
for (let cnt = 0; cnt < membersAdded.length; ++cnt) {
23-
if (membersAdded[cnt].id !== context.activity.recipient.id) {
23+
if (membersAdded[cnt].id !== context.activity.recipient?.id) {
2424
await context.sendActivity(MessageFactory.text(welcomeText, welcomeText));
2525
}
2626
}

samples/javascript_nodejs/02.echo-bot/index.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ const restify = require('restify');
1414

1515
// Import required bot services.
1616
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
17-
const {
18-
CloudAdapter,
19-
ConfigurationBotFrameworkAuthentication
20-
} = require('botbuilder');
17+
const { CloudAdapter, loadAuthConfigFromEnv } = require('@microsoft/agents-hosting');
2118

2219
// This bot's main dialog.
2320
const { EchoBot } = require('./bot');
@@ -32,7 +29,7 @@ server.listen(process.env.port || process.env.PORT || 3978, () => {
3229
console.log('\nTo talk to your bot, open the emulator select "Open Bot"');
3330
});
3431

35-
const botFrameworkAuthentication = new ConfigurationBotFrameworkAuthentication(process.env);
32+
const botFrameworkAuthentication = loadAuthConfigFromEnv()
3633

3734
// Create adapter.
3835
// See https://aka.ms/about-bot-adapter to learn more about how bots work.
@@ -68,15 +65,16 @@ const myBot = new EchoBot();
6865
// Listen for incoming requests.
6966
server.post('/api/messages', async (req, res) => {
7067
// Route received a request to adapter for processing
68+
// @ts-ignore
7169
await adapter.process(req, res, (context) => myBot.run(context));
7270
});
7371

74-
// Listen for Upgrade requests for Streaming.
75-
server.on('upgrade', async (req, socket, head) => {
76-
// Create an adapter scoped to this WebSocket connection to allow storing session data.
77-
const streamingAdapter = new CloudAdapter(botFrameworkAuthentication);
78-
// Set onTurnError for the CloudAdapter created for each connection.
79-
streamingAdapter.onTurnError = onTurnErrorHandler;
72+
// // Listen for Upgrade requests for Streaming.
73+
// server.on('upgrade', async (req, socket, head) => {
74+
// // Create an adapter scoped to this WebSocket connection to allow storing session data.
75+
// const streamingAdapter = new CloudAdapter(botFrameworkAuthentication);
76+
// // Set onTurnError for the CloudAdapter created for each connection.
77+
// streamingAdapter.onTurnError = onTurnErrorHandler;
8078

81-
await streamingAdapter.process(req, socket, head, (context) => myBot.run(context));
82-
});
79+
// await streamingAdapter.process(req, socket, head, (context) => myBot.run(context));
80+
// });

samples/javascript_nodejs/02.echo-bot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"url": "https://github.com"
1717
},
1818
"dependencies": {
19-
"botbuilder": "~4.23.0",
19+
"@microsoft/agents-hosting": "~1.0.0",
2020
"dotenv": "^8.2.0",
2121
"restify": "~10.0.0"
2222
},

0 commit comments

Comments
 (0)