From 347ba5696472c19f22445c3a19f6f0b77f545def Mon Sep 17 00:00:00 2001 From: Rido Date: Sun, 27 Jul 2025 23:00:46 +0000 Subject: [PATCH 1/6] migrate console to agents sdk --- .../01.console-echo/consoleAdapter.js | 30 +++++++++---------- .../01.console-echo/package.json | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/samples/javascript_nodejs/01.console-echo/consoleAdapter.js b/samples/javascript_nodejs/01.console-echo/consoleAdapter.js index e68f03d02b..4c24bb57b0 100644 --- a/samples/javascript_nodejs/01.console-echo/consoleAdapter.js +++ b/samples/javascript_nodejs/01.console-echo/consoleAdapter.js @@ -5,10 +5,12 @@ // @ts-check -const botbuilderCore = require('botbuilder-core'); -const { BotAdapter, TurnContext, ActivityTypes } = botbuilderCore; +// const botbuilderCore = require('botbuilder-core'); +const { CloudAdapter, TurnContext } = require('@microsoft/agents-hosting'); +const { ActivityTypes, Activity } = require('@microsoft/agents-activity') const readline = require('readline'); - +const { text } = require('stream/consumers'); +const BotAdapter = CloudAdapter; /** * Lets a user communicate with a bot from a console window. * @@ -36,7 +38,7 @@ class ConsoleAdapter extends BotAdapter { this.reference = { channelId: 'console', user: { id: 'user', name: 'User1' }, - bot: { id: 'bot', name: 'Bot' }, + agent: { id: 'bot', name: 'Bot' }, conversation: { id: 'convo1', name: '', isGroup: false }, serviceUrl: '', ...reference @@ -77,21 +79,17 @@ class ConsoleAdapter extends BotAdapter { output: process.stdout, terminal: false }); - rl.on('line', line => { + rl.on('line', async line => { // Initialize activity - const activity = TurnContext.applyConversationReference( - { - type: ActivityTypes.Message, - id: (this.nextId++).toString(), - timestamp: new Date(), - text: line - }, - this.reference, + const activity = Activity.fromObject({type: ActivityTypes.Message, text: line}); + + activity.applyConversationReference( + this.reference, true ); // Create context and run middleware pipe const context = new TurnContext(this, activity); - this.runMiddleware(context, logic).catch(err => { + await this.runMiddleware(context, logic).catch(err => { this.printError(err.toString()); }); }); @@ -125,8 +123,8 @@ class ConsoleAdapter extends BotAdapter { */ continueConversation(reference, logic) { // Create context and run middleware pipe - const activity = TurnContext.applyConversationReference( - {}, + const activity = new Activity(ActivityTypes.Message); + activity.applyConversationReference( reference, true ); diff --git a/samples/javascript_nodejs/01.console-echo/package.json b/samples/javascript_nodejs/01.console-echo/package.json index e46935ae54..438bfa8fe6 100644 --- a/samples/javascript_nodejs/01.console-echo/package.json +++ b/samples/javascript_nodejs/01.console-echo/package.json @@ -16,7 +16,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder-core": "~4.23.0", + "@microsoft/agents-hosting": "~1.0.0", "dotenv": "^8.2.0", "path": "^0.12.7", "readline": "^1.3.0" From 683b292d71e0ff56a93c61359f08b1b93738e408 Mon Sep 17 00:00:00 2001 From: Rido Date: Sun, 27 Jul 2025 23:10:12 +0000 Subject: [PATCH 2/6] migrate echo --- samples/javascript_nodejs/02.echo-bot/bot.js | 4 ++-- .../javascript_nodejs/02.echo-bot/index.js | 24 +++++++++---------- .../02.echo-bot/package.json | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/samples/javascript_nodejs/02.echo-bot/bot.js b/samples/javascript_nodejs/02.echo-bot/bot.js index c36b9b317d..016b6eef6f 100644 --- a/samples/javascript_nodejs/02.echo-bot/bot.js +++ b/samples/javascript_nodejs/02.echo-bot/bot.js @@ -3,7 +3,7 @@ // @ts-check -const { ActivityHandler, MessageFactory } = require('botbuilder'); +const { ActivityHandler, MessageFactory } = require('@microsoft/agents-hosting'); class EchoBot extends ActivityHandler { constructor() { @@ -20,7 +20,7 @@ class EchoBot extends ActivityHandler { const membersAdded = context.activity.membersAdded ?? []; const welcomeText = 'Hello and welcome!'; for (let cnt = 0; cnt < membersAdded.length; ++cnt) { - if (membersAdded[cnt].id !== context.activity.recipient.id) { + if (membersAdded[cnt].id !== context.activity.recipient?.id) { await context.sendActivity(MessageFactory.text(welcomeText, welcomeText)); } } diff --git a/samples/javascript_nodejs/02.echo-bot/index.js b/samples/javascript_nodejs/02.echo-bot/index.js index 49558ea08f..e132a29eab 100644 --- a/samples/javascript_nodejs/02.echo-bot/index.js +++ b/samples/javascript_nodejs/02.echo-bot/index.js @@ -14,10 +14,7 @@ const restify = require('restify'); // Import required bot services. // See https://aka.ms/bot-services to learn more about the different parts of a bot. -const { - CloudAdapter, - ConfigurationBotFrameworkAuthentication -} = require('botbuilder'); +const { CloudAdapter, loadAuthConfigFromEnv } = require('@microsoft/agents-hosting'); // This bot's main dialog. const { EchoBot } = require('./bot'); @@ -32,7 +29,7 @@ server.listen(process.env.port || process.env.PORT || 3978, () => { console.log('\nTo talk to your bot, open the emulator select "Open Bot"'); }); -const botFrameworkAuthentication = new ConfigurationBotFrameworkAuthentication(process.env); +const botFrameworkAuthentication = loadAuthConfigFromEnv() // Create adapter. // See https://aka.ms/about-bot-adapter to learn more about how bots work. @@ -68,15 +65,16 @@ const myBot = new EchoBot(); // Listen for incoming requests. server.post('/api/messages', async (req, res) => { // Route received a request to adapter for processing + // @ts-ignore await adapter.process(req, res, (context) => myBot.run(context)); }); -// Listen for Upgrade requests for Streaming. -server.on('upgrade', async (req, socket, head) => { - // Create an adapter scoped to this WebSocket connection to allow storing session data. - const streamingAdapter = new CloudAdapter(botFrameworkAuthentication); - // Set onTurnError for the CloudAdapter created for each connection. - streamingAdapter.onTurnError = onTurnErrorHandler; +// // Listen for Upgrade requests for Streaming. +// server.on('upgrade', async (req, socket, head) => { +// // Create an adapter scoped to this WebSocket connection to allow storing session data. +// const streamingAdapter = new CloudAdapter(botFrameworkAuthentication); +// // Set onTurnError for the CloudAdapter created for each connection. +// streamingAdapter.onTurnError = onTurnErrorHandler; - await streamingAdapter.process(req, socket, head, (context) => myBot.run(context)); -}); +// await streamingAdapter.process(req, socket, head, (context) => myBot.run(context)); +// }); diff --git a/samples/javascript_nodejs/02.echo-bot/package.json b/samples/javascript_nodejs/02.echo-bot/package.json index 62a1a4f778..85ee4f57fc 100644 --- a/samples/javascript_nodejs/02.echo-bot/package.json +++ b/samples/javascript_nodejs/02.echo-bot/package.json @@ -16,7 +16,7 @@ "url": "https://github.com" }, "dependencies": { - "botbuilder": "~4.23.0", + "@microsoft/agents-hosting": "~1.0.0", "dotenv": "^8.2.0", "restify": "~10.0.0" }, From 0b99aa229fd9423392fb647818c510f9de94c5ea Mon Sep 17 00:00:00 2001 From: Rido Date: Sun, 27 Jul 2025 23:38:33 +0000 Subject: [PATCH 3/6] migrating --- .../07.using-adaptive-cards/bots/adaptiveCardsBot.js | 11 ++++++----- .../07.using-adaptive-cards/index.js | 8 ++++---- .../07.using-adaptive-cards/package.json | 2 +- .../44.prompt-for-user-input/bots/customPromptBot.js | 2 +- .../44.prompt-for-user-input/index.js | 7 ++++--- .../44.prompt-for-user-input/package.json | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js b/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js index 12b7ba5345..f155d20d31 100644 --- a/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js +++ b/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js @@ -3,8 +3,8 @@ // @ts-check -const { ActivityHandler, CardFactory } = require('botbuilder'); - +const { ActivityHandler, CardFactory } = require('@microsoft/agents-hosting'); +const { Activity } = require('@microsoft/agents-activity') // Import AdaptiveCard content. const FlightItineraryCard = require('../resources/FlightItineraryCard.json'); const ImageGalleryCard = require('../resources/ImageGalleryCard.json'); @@ -29,7 +29,7 @@ class AdaptiveCardsBot extends ActivityHandler { this.onMembersAdded(async (context, next) => { const membersAdded = context.activity.membersAdded ?? []; for (let cnt = 0; cnt < membersAdded.length; cnt++) { - if (membersAdded[cnt].id !== context.activity.recipient.id) { + if (membersAdded[cnt].id !== context.activity.recipient?.id) { await context.sendActivity(`Welcome to Adaptive Cards Bot ${ membersAdded[cnt].name }. ${ WELCOME_TEXT }`); } } @@ -40,10 +40,11 @@ class AdaptiveCardsBot extends ActivityHandler { this.onMessage(async (context, next) => { const randomlySelectedCard = CARDS[Math.floor((Math.random() * CARDS.length - 1) + 1)]; - await context.sendActivity({ + await context.sendActivity(Activity.fromObject({ + type: 'message', text: 'Here is an Adaptive Card:', attachments: [CardFactory.adaptiveCard(randomlySelectedCard)] - }); + })); // By calling next() you ensure that the next BotHandler is run. await next(); diff --git a/samples/javascript_nodejs/07.using-adaptive-cards/index.js b/samples/javascript_nodejs/07.using-adaptive-cards/index.js index 8c858cdc49..21a7d69000 100644 --- a/samples/javascript_nodejs/07.using-adaptive-cards/index.js +++ b/samples/javascript_nodejs/07.using-adaptive-cards/index.js @@ -14,13 +14,12 @@ const restify = require('restify'); // Import required bot services. // See https://aka.ms/bot-services to learn more about the different parts of a bot. const { - CloudAdapter, - ConfigurationBotFrameworkAuthentication -} = require('botbuilder'); + CloudAdapter, loadAuthConfigFromEnv +} = require('@microsoft/agents-hosting'); const { AdaptiveCardsBot } = require('./bots/adaptiveCardsBot'); -const botFrameworkAuthentication = new ConfigurationBotFrameworkAuthentication(process.env); +const botFrameworkAuthentication = loadAuthConfigFromEnv(); // Create adapter. See https://aka.ms/about-bot-adapter to learn more about adapters. const adapter = new CloudAdapter(botFrameworkAuthentication); @@ -62,5 +61,6 @@ server.listen(process.env.port || process.env.PORT || 3978, function() { // Listen for incoming requests. server.post('/api/messages', async (req, res) => { // Route received a request to adapter for processing + // @ts-ignore await adapter.process(req, res, (context) => bot.run(context)); }); diff --git a/samples/javascript_nodejs/07.using-adaptive-cards/package.json b/samples/javascript_nodejs/07.using-adaptive-cards/package.json index dfe19e6745..0f92bde17a 100644 --- a/samples/javascript_nodejs/07.using-adaptive-cards/package.json +++ b/samples/javascript_nodejs/07.using-adaptive-cards/package.json @@ -16,7 +16,7 @@ "url": "https://github.com/Microsoft/BotBuilder-Samples.git" }, "dependencies": { - "botbuilder": "~4.23.0", + "@microsoft/agents-hosting": "~1.0.0", "dotenv": "^8.2.0", "restify": "~10.0.0" }, diff --git a/samples/javascript_nodejs/44.prompt-for-user-input/bots/customPromptBot.js b/samples/javascript_nodejs/44.prompt-for-user-input/bots/customPromptBot.js index d40fb700c8..7722b81ce3 100644 --- a/samples/javascript_nodejs/44.prompt-for-user-input/bots/customPromptBot.js +++ b/samples/javascript_nodejs/44.prompt-for-user-input/bots/customPromptBot.js @@ -4,7 +4,7 @@ // @ts-check const Recognizers = require('@microsoft/recognizers-text-suite'); -const { ActivityHandler } = require('botbuilder'); +const { ActivityHandler } = require('@microsoft/agents-hosting'); // The accessor names for the conversation flow and user profile state property accessors. const CONVERSATION_FLOW_PROPERTY = 'CONVERSATION_FLOW_PROPERTY'; diff --git a/samples/javascript_nodejs/44.prompt-for-user-input/index.js b/samples/javascript_nodejs/44.prompt-for-user-input/index.js index a605b1e12a..7a8f657bdf 100644 --- a/samples/javascript_nodejs/44.prompt-for-user-input/index.js +++ b/samples/javascript_nodejs/44.prompt-for-user-input/index.js @@ -18,8 +18,8 @@ const { ConversationState, MemoryStorage, UserState, - ConfigurationBotFrameworkAuthentication -} = require('botbuilder'); + loadAuthConfigFromEnv +} = require('@microsoft/agents-hosting'); // This bot's main dialog. const { CustomPromptBot } = require('./bots/customPromptBot'); @@ -34,7 +34,7 @@ server.listen(process.env.port || process.env.PORT || 3978, function() { console.log('\nTo talk to your bot, open the emulator select "Open Bot"'); }); -const botFrameworkAuthentication = new ConfigurationBotFrameworkAuthentication(process.env); +const botFrameworkAuthentication = loadAuthConfigFromEnv() // Create adapter. // See https://aka.ms/about-bot-adapter to learn more about how bots work. @@ -74,5 +74,6 @@ adapter.onTurnError = async (context, error) => { // Listen for incoming requests. server.post('/api/messages', async (req, res) => { // Route received a request to adapter for processing + // @ts-ignore await adapter.process(req, res, (context) => bot.run(context)); }); diff --git a/samples/javascript_nodejs/44.prompt-for-user-input/package.json b/samples/javascript_nodejs/44.prompt-for-user-input/package.json index 46e4f6aee4..6554aeb30b 100644 --- a/samples/javascript_nodejs/44.prompt-for-user-input/package.json +++ b/samples/javascript_nodejs/44.prompt-for-user-input/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@microsoft/recognizers-text-suite": "1.1.4", - "botbuilder": "~4.23.0", + "@microsoft/agents-hosting": "~1.0.0", "dotenv": "^8.2.0", "restify": "~10.0.0" }, From a654b50ce5b61767ec31de4fcb9a064874f18210 Mon Sep 17 00:00:00 2001 From: Rido Date: Tue, 29 Jul 2025 23:28:00 +0000 Subject: [PATCH 4/6] update node version to 22.x in CI workflow --- .github/workflows/ci-javascript-samples.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-javascript-samples.yml b/.github/workflows/ci-javascript-samples.yml index 5ff6e50cd2..9865f0fb80 100644 --- a/.github/workflows/ci-javascript-samples.yml +++ b/.github/workflows/ci-javascript-samples.yml @@ -78,10 +78,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: use node 18.x + - name: use node 22.x uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 22.x - name: yarn install run: yarn install From 06354caa16118a929b2ada376f2db0b9df97cf31 Mon Sep 17 00:00:00 2001 From: Rido Date: Tue, 29 Jul 2025 23:31:08 +0000 Subject: [PATCH 5/6] fix: correct formatting and remove unused import in ConsoleAdapter --- .../javascript_nodejs/01.console-echo/consoleAdapter.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/samples/javascript_nodejs/01.console-echo/consoleAdapter.js b/samples/javascript_nodejs/01.console-echo/consoleAdapter.js index 4c24bb57b0..045bdc2cd3 100644 --- a/samples/javascript_nodejs/01.console-echo/consoleAdapter.js +++ b/samples/javascript_nodejs/01.console-echo/consoleAdapter.js @@ -7,9 +7,8 @@ // const botbuilderCore = require('botbuilder-core'); const { CloudAdapter, TurnContext } = require('@microsoft/agents-hosting'); -const { ActivityTypes, Activity } = require('@microsoft/agents-activity') +const { ActivityTypes, Activity } = require('@microsoft/agents-activity'); const readline = require('readline'); -const { text } = require('stream/consumers'); const BotAdapter = CloudAdapter; /** * Lets a user communicate with a bot from a console window. @@ -81,10 +80,10 @@ class ConsoleAdapter extends BotAdapter { }); rl.on('line', async line => { // Initialize activity - const activity = Activity.fromObject({type: ActivityTypes.Message, text: line}); - + const activity = Activity.fromObject({ type: ActivityTypes.Message, text: line }); + activity.applyConversationReference( - this.reference, + this.reference, true ); // Create context and run middleware pipe From 57b3c0ca610a12957b17853a2980c8df0b5f98c4 Mon Sep 17 00:00:00 2001 From: Rido Date: Wed, 30 Jul 2025 00:01:02 +0000 Subject: [PATCH 6/6] fix lint issues --- samples/javascript_nodejs/02.echo-bot/index.js | 12 +----------- .../07.using-adaptive-cards/bots/adaptiveCardsBot.js | 2 +- .../44.prompt-for-user-input/index.js | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/samples/javascript_nodejs/02.echo-bot/index.js b/samples/javascript_nodejs/02.echo-bot/index.js index e132a29eab..a5abbaa89b 100644 --- a/samples/javascript_nodejs/02.echo-bot/index.js +++ b/samples/javascript_nodejs/02.echo-bot/index.js @@ -29,7 +29,7 @@ server.listen(process.env.port || process.env.PORT || 3978, () => { console.log('\nTo talk to your bot, open the emulator select "Open Bot"'); }); -const botFrameworkAuthentication = loadAuthConfigFromEnv() +const botFrameworkAuthentication = loadAuthConfigFromEnv(); // Create adapter. // See https://aka.ms/about-bot-adapter to learn more about how bots work. @@ -68,13 +68,3 @@ server.post('/api/messages', async (req, res) => { // @ts-ignore await adapter.process(req, res, (context) => myBot.run(context)); }); - -// // Listen for Upgrade requests for Streaming. -// server.on('upgrade', async (req, socket, head) => { -// // Create an adapter scoped to this WebSocket connection to allow storing session data. -// const streamingAdapter = new CloudAdapter(botFrameworkAuthentication); -// // Set onTurnError for the CloudAdapter created for each connection. -// streamingAdapter.onTurnError = onTurnErrorHandler; - -// await streamingAdapter.process(req, socket, head, (context) => myBot.run(context)); -// }); diff --git a/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js b/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js index f155d20d31..4d0b161c9b 100644 --- a/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js +++ b/samples/javascript_nodejs/07.using-adaptive-cards/bots/adaptiveCardsBot.js @@ -4,7 +4,7 @@ // @ts-check const { ActivityHandler, CardFactory } = require('@microsoft/agents-hosting'); -const { Activity } = require('@microsoft/agents-activity') +const { Activity } = require('@microsoft/agents-activity'); // Import AdaptiveCard content. const FlightItineraryCard = require('../resources/FlightItineraryCard.json'); const ImageGalleryCard = require('../resources/ImageGalleryCard.json'); diff --git a/samples/javascript_nodejs/44.prompt-for-user-input/index.js b/samples/javascript_nodejs/44.prompt-for-user-input/index.js index 7a8f657bdf..020ed847a2 100644 --- a/samples/javascript_nodejs/44.prompt-for-user-input/index.js +++ b/samples/javascript_nodejs/44.prompt-for-user-input/index.js @@ -34,7 +34,7 @@ server.listen(process.env.port || process.env.PORT || 3978, function() { console.log('\nTo talk to your bot, open the emulator select "Open Bot"'); }); -const botFrameworkAuthentication = loadAuthConfigFromEnv() +const botFrameworkAuthentication = loadAuthConfigFromEnv(); // Create adapter. // See https://aka.ms/about-bot-adapter to learn more about how bots work.