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 diff --git a/samples/javascript_nodejs/01.console-echo/consoleAdapter.js b/samples/javascript_nodejs/01.console-echo/consoleAdapter.js index e68f03d02b..045bdc2cd3 100644 --- a/samples/javascript_nodejs/01.console-echo/consoleAdapter.js +++ b/samples/javascript_nodejs/01.console-echo/consoleAdapter.js @@ -5,10 +5,11 @@ // @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 BotAdapter = CloudAdapter; /** * Lets a user communicate with a bot from a console window. * @@ -36,7 +37,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 +78,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 - }, + 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 +122,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" 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..a5abbaa89b 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,6 @@ 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; - - 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" }, 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..4d0b161c9b 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..020ed847a2 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" },