Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/ci-javascript-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 12 additions & 15 deletions samples/javascript_nodejs/01.console-echo/consoleAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

// @ts-check

const botbuilderCore = require('botbuilder-core');
const { BotAdapter, TurnContext, ActivityTypes } = botbuilderCore;
// const botbuilderCore = require('botbuilder-core');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A commented line seems to have been overlooked here.
Also, the remarks section in line 16 mentions botbuilder.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README files are also mentioning BotFramework.

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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
});
});
Expand Down Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion samples/javascript_nodejs/01.console-echo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions samples/javascript_nodejs/02.echo-bot/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// @ts-check

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

class EchoBot extends ActivityHandler {
constructor() {
Expand All @@ -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));
}
}
Expand Down
18 changes: 3 additions & 15 deletions samples/javascript_nodejs/02.echo-bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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.
Expand Down Expand Up @@ -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));
});
2 changes: 1 addition & 1 deletion samples/javascript_nodejs/02.echo-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 }`);
}
}
Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions samples/javascript_nodejs/07.using-adaptive-cards/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
});
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 4 additions & 3 deletions samples/javascript_nodejs/44.prompt-for-user-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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.
Expand Down Expand Up @@ -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));
});
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Loading